Verse Library verse

01 Standalone

Implements NPC behavior that scans for injured players and targets them for healing during gameplay.

verse-library/create-your-own-npc-medic/01-standalone.verse

# This is our main script file.
# It tells the NPC how to behave.

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

# We create a new type of NPC behavior.
# This is like a blueprint for our medic.
medic_behavior := class(npc_behavior):

    # This function runs when the game starts.
    OnBegin<override>()<suspends>: void =
        # We start a loop that never ends.
        # The NPC will keep thinking forever.
        loop:
            # Step 1: Find all players in the game.
            # GetPlayspace gives us the current match session.
            # GetPlayers() returns every player currently in the game.
            AllPlayers := GetPlayspace().GetPlayers()

            # Step 2: Filter only the hurt players.
            # We check their health. If it is low, we keep them.
            var HurtCharacters : []fort_character = array{}
            for (Player : AllPlayers):
                # Cast the player to a fort_character so we can read health.
                if (Character := Player.GetFortCharacter[]):
                    # IsPlayerHurt checks whether this character needs healing.

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