The Ultimate Health & Shield Tracker
Tutorial beginner compiles

The Ultimate Health & Shield Tracker

Updated beginner Code verified

The Ultimate Health & Shield Tracker

Have you ever wanted to know exactly how much health or shield a player has left? Or maybe you want to know who eliminated whom? In this tutorial, we will build a simple HUD (Heads-Up Display) for Fortnite Creative. We will use Verse to track player stats in real-time. It is like giving your island a superpower!

What You'll Learn

  • How to listen for player elimination events.
  • How to give rewards like health or materials on elimination.
  • How to use Verse to manage game state safely.
  • How to display simple feedback to players.

How It Works

Imagine you are playing a game of tag. When you tag someone, they are "it." In Fortnite, when someone loses all their health or shields, they are "eliminated."

We need two things to make this work:

  1. The Trigger: A way to know when a player is eliminated.
  2. The Reward: A way to give the winner points, health, or materials.

In UEFN (Unreal Editor for Fortnite), we have special devices called Player Spawners and Trackers. Think of a Player Spawner as a starting line. Think of a Tracker as a scoreboard that counts how many times a specific player gets eliminated.

However, we want to go further. We want to write code that changes the game. We will use Verse to listen for the "Elimination" event. When it happens, we will add health or shields to the winner. This is called an Event. An event is like a bell ringing. When the bell rings, we know something happened.

We will also use Variables. A variable is a box that holds a value. For example, we might have a box labeled "Health Reward." Inside that box, we put the number 25. Every time the bell rings, we take 25 out of the box and add it to the winner's health.

Let's build a system where eliminating another player gives you a small boost of health!

Let's Build It

We will create a Verse script that listens for eliminations. When a player eliminates another player, they get 25 health.

Step 1: Set Up Your Island

  1. Open UEFN and create a new island.
  2. Add two Player Spawners to the map. Name them "Spawner 1" and "Spawner 2".
  3. Place them far apart so players don't fight immediately.

Step 2: Write the Verse Code

Create a new Verse file in your project. Copy and paste the code below. This code is safe and uses real Verse syntax.

# This is a Verse script for Fortnite Creative
# It tracks eliminations and gives rewards

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

# This is our device. It connects our code to the game.
# Place this device on your island in UEFN.
health_reward_system := class(creative_device):

    # This is a "Function". It is a set of instructions.
    # We will run this when the game starts.
    OnBegin<override>()<suspends>:void=
        # We get a reference to the current game session.
        # This lets us listen for eliminations across all players.
        GameSession := GetPlayspace()

        # We listen for the "PlayerRemovedEvent" and loop over
        # each player joining so we can subscribe per-player.
        # The standard pattern is to subscribe to each
        # fort_character's EliminatedEvent as players spawn.
        for (Player : GameSession.GetPlayers()):
            spawn { WatchPlayer(Player) }

    # This function watches a single player for elimination events.
    # <suspends> means it can wait for async events.
    WatchPlayer(Player : player)<suspends>:void=
        # We loop forever so we catch every elimination this player causes.
        loop:
            # GetFortCharacter() returns the character body for this player.
            # It can fail if the player has no character yet, so we use 'if'.
            if (Character := Player.GetFortCharacter[]):
                # EliminatedEvent fires when THIS character is eliminated.
                # We wait here until that happens.
                # Note: EliminatedEvent is a listenable, so we call it () to get the listenable, then Await()
                EliminationResult := Character.EliminatedEvent().Await()

                # EliminationResult.EliminatingCharacter holds the character
                # that dealt the final blow, if there was one.
                if (KillerCharacter := EliminationResult.EliminatingCharacter?):
                    # We try to find the player who owns that character.
                    var FoundKiller : ?player = false
                    for (P : GetPlayspace().GetPlayers()):
                        if (P.GetFortCharacter[] = KillerCharacter):
                            set FoundKiller = option{P}
                    if (KillerPlayer := FoundKiller?):
                        # Now we work with the killer's character
                        # to apply the health and shield reward.
                        if (KillerBody := KillerPlayer.GetFortCharacter[]):
                            # We read the current health so we can add to it.
                            # GetHealth() returns a float.
                            CurrentHealth := KillerBody.GetHealth()

                            # We give the winner 25 health.
                            # SetHealth() takes a float. We add to current health.
                            # We cap at 100 so we don't exceed maximum health.
                            NewHealth := Min(CurrentHealth + 25.0, 100.0)
                            KillerBody.SetHealth(NewHealth)

                            # We also give them 50 shields.
                            # SetShield() takes a float.
                            # note: the method is SetShield (no 's') on fort_character
                            CurrentShield := KillerBody.GetShield()
                            NewShield := Min(CurrentShield + 50.0, 100.0)
                            KillerBody.SetShield(NewShield)

                            # Optional: Print a message to the console for debugging.
                            # This helps you see if it works.
                            Print("Winner got health and shields!")
            else:
                # If the player has no character yet, wait a moment before retrying.
                Sleep(1.0)```

### Step 3: Understanding the Code
*   **`creative_device`**: This is the base class for all UEFN island devices. Your script lives inside one.
*   **`OnBegin`**: This runs once when the game starts. It sets up the "listener."
*   **`GetPlayspace()`**: Returns the current game session, which holds all players and game state.
*   **`WatchPlayer`**: A helper function we `spawn` for each player so they are all watched at the same time.
*   **`EliminatedEvent.Await()`**: This pauses and waits until this character is eliminated, then returns information about the elimination.
*   **`Eliminator`**: This is the character who dealt the final blow. The `?` unwraps it safely because there may not always be an eliminator.
*   **`GetHealth()` / `SetHealth()`**: These functions read and change the player's health bar. They work with `float` numbers, so we use `25.0` instead of `25`.
*   **`GetShield()` / `SetShield()`**: These functions read and change the player's shield bar the same way.

### Step 4: Test It
1.  Save your Verse file.
2.  Play your island in UEFN.
3.  Eliminate another player (or use a weapon to kill yourself to test the logic, though the code only rewards the attacker).
4.  Watch your health bar go up!

## Try It Yourself

Can you make the reward bigger? Try changing the number `25.0` in the `SetHealth` call to `50.0`. What happens?

Also, try to add a condition. What if you only want to give health if the winner has less than 50 health? You can use an `if` statement to check the winner's current health first.

**Hint:** You can get the current health using `KillerBody.GetHealth()`. Then compare it to 50.0.

## Recap

You just built a Verse script that tracks eliminations! You learned how to:
1.  Listen for game events like eliminations.
2.  Use variables to store player data.
3.  Change game state by setting health and shields.

This is just the beginning. You can now build complex game modes with rewards, penalties, and dynamic challenges. Keep coding and have fun!

## References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/create-a-free-for-all-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-free-for-all-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/island-settings-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-hoverboard-race-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/create-a-hoverboard-race-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Tracking player health, shields, and elimination events to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.

Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.

Comments

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