# GuardLeash.verse # This device defines a leash volume for guards. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } using { /Verse.org/SpatialMath } # We create a new class called 'LeashDevice'. # Think of this as a new type of device you can place in the editor. LeashDevice := class(creative_device): # @editable means this variable shows up in the editor sidebar. # You can change it without touching code. # 1. The Inner Radius (Home Base) # Guards should stay inside this distance from the spawn center. @editable InnerRadius:float = 500.0 # 2. The Outer Radius (The Leash Limit) # Guards cannot go further than this distance. @editable OuterRadius:float = 1000.0 # 3. The List of Spawners # This is an 'Array'. It's a list where you drag in your Guard Spawner devices. # We leave it empty for now; you'll fill it in the editor. @editable ConnectedSpawners:[]npc_spawner_device = array{} # This function runs when the game starts (or when the island loads). OnBegin():void= # We loop through every device in our ConnectedSpawners list. for (Spawner : ConnectedSpawners): # We subscribe to its 'SpawnedEvent'. # This means: "Hey Spawner, tell me every time you spawn a guard." Spawner.SpawnedEvent.Subscribe(OnGuardSpawned) # This function runs whenever a guard is spawned. OnGuardSpawned(SpawnedGuard:agent):void= # Get the position of the guard. # We cast agent to fort_character to access position info. if (GuardChar := fort_character[SpawnedGuard]): GuardPosition := GuardChar.GetTransform().Translation # Get the position of the leash device itself (our anchor point). LeashPosition := GetTransform().Translation # Calculate the distance between the guard and the leash device. Diff := GuardPosition - LeashPosition GuardDist := Diff.Length() # If the guard is outside the Outer Radius, we snap them back. # This simulates the "leash" pulling them in. if (GuardDist > OuterRadius): # Calculate a direction vector from the guard to the leash center. Direction := Normal(LeashPosition - GuardPosition) # Move the guard to the edge of the Outer Radius. NewPosition := LeashPosition + (Direction * OuterRadius) GuardChar.TeleportTo[NewPosition, GuardChar.GetTransform().Rotation] # Optional: Print a message to the chat so you know it worked. Print("Guard snapped back to leash!")