Verse Library verse

03 Device

Posts guard squads, hires them to players, and monitors their AI alert states.

verse-library/verse-npc-guard-patrol/03-device.verse

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<override>()<suspends> : 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)

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in