using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation }
A Verse-authored creative device that can be placed in a level
enemy_detector_device := class(creative_device):
@editable
Button : button_device = button_device{}
@editable
EnemyImage : texture_2d = DefaultTexture2D # Replace DefaultTexture2D with your actual enemy image asset
var PlayerUI : player_ui = player_ui{} # The UI for the player
OnBegin<override>()<suspends>:void=
Button.InteractedWithEvent.Subscribe(OnButtonClicked)
OnButtonClicked(InPlayer:agent):void=
NearestEnemy := FindNearestEnemy(InPlayer)
if (NearestEnemy):
ShowEnemyImage(InPlayer)
FindNearestEnemy(Player:agent) : ?agent =
NearestEnemy : ?agent = false
MinDistance := 999999.0
for (OtherPlayer : GetPlayspace().GetPlayers()):
if (OtherPlayer.GetTeam() <> Player.GetTeam()):
Distance := Vector3Distance(Player.GetTransform().Translation, OtherPlayer.GetTransform().Translation)
if (Distance < MinDistance):
set MinDistance = Distance
set NearestEnemy = option{OtherPlayer}
NearestEnemy
ShowEnemyImage(Player:agent) : void =
if (PlayerUI := GetPlayerUI[player[Player]]):
EnemyImageWidget := image{Texture := EnemyImage}
PlayerUI.ShowWidget(EnemyImageWidget)