Verse Library verse

02 Standalone

Initializes NPC behavior by retrieving the agent and subscribing to damage events for AI logic.

verse-library/get-the-agent-the-npc/02-standalone.verse

using { /Fortnite.com/AI }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }

# This is our main script structure.
# Think of this as the "Brain" of the NPC.
MyBehavior := class(npc_behavior):

    # This function runs automatically when the NPC starts.
    # It's like the "Start of Match" screen.
    OnBegin<override>()<suspends>:void=
        # STEP 1: GET THE AGENT
        # We ask the NPC: "Who are you?"
        # This grabs the unique ID for this specific NPC instance.
        # GetAgent[] can fail, so it must be called inside a failure context (if).
        if (BossAgent := GetAgent[]):

            # Let's verify we got it by printing to the debug console.
            # GetAgent[] returns an agent interface value; Print accepts any.
            Print("Boss NPC behavior has started and Agent is live.")

            # STEP 2: MONITOR DAMAGE IN A LOOP
            # Cast the Agent to fort_character so we can access health events.
            # fort_character is the real interface for Fortnite character stats.
            if (BossCharacter := BossAgent.GetFortCharacter[]):
                # Subscribe to the damage taken event on the fort_character.
                BossCharacter.DamagedEvent().Subscribe(OnTakeDamage)
                # Keep this behavior alive so the subscription stays active.
                loop:

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