# 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(): 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. if (IsPlayerHurt[Character]): set HurtCharacters += array{Character} # Step 3: Find the closest hurt player. # We pick the first one we find for now. if (HurtCharacters.Length > 0): if (Target := HurtCharacters[0]): # Step 4: Heal the target! # We use our helper function to add health. # This makes them feel better. HealCharacter(Target, 50.0) # Step 5: Wait a little bit. # We don't want to heal too fast. # It would be annoying! Sleep(2.0) # This helper function checks if a player is hurt. # fort_character exposes GetHealth() directly. IsPlayerHurt(Character : fort_character): void = # GetHealth() returns the current health as a float. # If health is less than 100, they are hurt. Character.GetHealth() < 100.0 # This helper function heals a character. HealCharacter(Target : fort_character, Amount : float): void = # GetHealth() reads current health. # SetHealth() writes the new value. # Old health + Amount = New health. NewHealth : float = Target.GetHealth() + Amount Target.SetHealth(NewHealth)