Guards Following Player Using Leash
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/AI }
using { /Fortnite.com/Characters }
# A Verse-authored creative device that can be placed in a level
follower_example_device := class(creative_device):
@editable
FollowerSpawner:guard_spawner_device = guard_spawner_device{}
var MaybePlayer:?player = false
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# Get first player in game to have the guards follow
set MaybePlayer = option{GetPlayspace().GetPlayers()[0]}
# Connect behavior to leash guards to player when they spawn
FollowerSpawner.SpawnedEvent.Subscribe(OnFollowerSpawned)
# Spawn 20 guards that will follow first player
for (X := 1..20):
FollowerSpawner.Spawn()
# Have guards leashed to player when they're spawned
OnFollowerSpawned(Follower:agent):void=
if:
FollowerLeash := Follower.GetFortCharacter[].GetFortLeashable[]
Player := MaybePlayer?
then:
# Player is center of the leash
# InnerRadius and OuterRadius define the range for the guards to try to stay in
FollowerLeash.SetLeashAgent(Player, InnerRadius := 384.0, OuterRadius := 1000.0)