using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # GUARD PATROL & HIRE — drive the Guard Spawner device from Verse. # # Guards are the one NPC type with combat AI built in: they idle, patrol, grow # suspicious, go alert, and attack — all on their own. The guard_spawner_device # lets Verse tune that built-in brain and react to it. Here one button posts the # guards and tightens their senses; a second button hires the whole squad to the # presser's team; and we log every alert so you can see the FSM tick over. guard_post_device := class(creative_device): @editable GuardSpawner : guard_spawner_device = guard_spawner_device{} # Posts the guards and sets them patrolling. @editable DeployButton : button_device = button_device{} # Hires every living guard to the presser's team. @editable HireButton : button_device = button_device{} OnBegin() : void = DeployButton.InteractedWithEvent.Subscribe(OnDeploy) HireButton.InteractedWithEvent.Subscribe(OnHire) # Listen in on the guard AI's state machine. GuardSpawner.AlertedEvent.Subscribe(OnAlerted) GuardSpawner.SuspiciousEvent.Subscribe(OnSuspicious) GuardSpawner.EliminatedEvent.Subscribe(OnGuardDown) OnDeploy(Presser : agent) : void = # Tune the built-in guard brain via the device's editable vars. set GuardSpawner.PatrolRange = 1500.0 # roam radius in cm set GuardSpawner.VisibilityRange = 8000.0 # how far they can spot set GuardSpawner.CanBeHired = true # Let them be recruited later. GuardSpawner.SetGuardsHireable() GuardSpawner.Enable() GuardSpawner.Spawn() Print("Guards deployed and patrolling.") OnHire(Presser : agent) : void = # Recruit the squad to whoever pressed the button. GuardSpawner.Hire(Presser) Print("Guards hired to the presser's team.") # `AlertedEvent` fires when a guard locks onto a target. Source is the guard, # Target is who alerted them. OnAlerted(Result : device_ai_interaction_result) : void = if (Guard := Result.Source?): # Bypass perception and commit the guard straight to its target. if (Target := Result.Target?): GuardSpawner.ForceAttackTarget(Target, ?ForgetTime := 20.0) Print("Guard ALERT — committing to attack.") OnSuspicious(Guard : agent) : void = Print("A guard is getting suspicious...") OnGuardDown(Result : device_ai_interaction_result) : void = Print("A guard was eliminated.")