The Infinite Medkit: Building a Self-Respawning Health Station in Verse
Tutorial beginner compiles

The Infinite Medkit: Building a Self-Respawning Health Station in Verse

Updated beginner Code verified

The Infinite Medkit: Building a Self-Respawning Health Station in Verse

So, you've built a map. It's awesome. But then you realize your players are dying in one hit and quitting because there's no way to recover. In standard Fortnite, you hunt for a medkit or a chug jug. In your island, you want to be the god of healing. You want a power-up that doesn't just sit there looking pretty but actually works on command, respawns instantly, and feels like a reward for being awesome.

In this tutorial, we're going to build a Self-Respawning Health Station. It's a device that heals players when they step on it, then immediately teleports itself to a new random spot on the map so the next player (or you, if you're a glutton for punishment) can find it. No complex coding required—just pure, chaotic fun.

What You'll Learn

  • Variables: How to store data (like a player's current health) that changes during the game.
  • Events: How to react to things happening (like a player stepping on a trigger).
  • Scene Graph Hierarchy: Understanding how devices talk to each other in the 3D world.
  • Teleportation Logic: Moving an object from Point A to Point B using code.

How It Works

Imagine you're in the Battle Bus. You jump out, and your destination is random. That's essentially what we're doing here, but with a healing item.

In programming, we need to tell the game three things:

  1. Watch for Input: We need to know when a player touches the power-up. In Fortnite terms, this is like a pressure plate triggering a trap.
  2. Apply the Effect: When that trigger fires, we apply the healing. This is like using a Chug Jug, but automatic.
  3. Reset the State: After the player gets healed, the power-up needs to disappear and reappear elsewhere. If it didn't respawn, it would be a one-time use item, and your players would rage-quit before round two.

We'll use a Variable to keep track of where the power-up should go next. Think of a variable like a sticky note on your controller that says "Next Spawn: Kitchen." Every time the item is used, we erase that note and write a new one.

Let's Build It

We are going to use a Trigger Volume (the thing that detects players) and a Prop Mover or Item Granter (the thing that gives the healing). For simplicity and visual flair, we'll use a Prop Mover set to "Teleport" as our healing item. When a player touches the Trigger, the Prop Mover heals them, then moves itself to a new location.

Note: In Verse, we interact with devices using their unique IDs. Think of these IDs as the device's name tag.

Here is the complete, annotated Verse script. Copy this into a Verse file in your project.

# This is a Verse Script. It runs on the server to manage game logic.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }

health_station_manager := class(creative_device):

    # 1. DEFINE THE DEVICES (The Scene Graph)
    # We need to tell the script which devices we are controlling.
    # In UEFN, these are your Trigger Volume and your Teleporter devices.

    # The Trigger: Detects when a player steps on it.
    @editable
    TriggerDevice : trigger_device = trigger_device{}

    # The Healer: A health powerup device that grants health on Activate.
    # Place a health_powerup_device in the level and wire it here.
    @editable
    HealerDevice : health_powerup_device = health_powerup_device{}

    # The Teleporter: Moves the health station prop to a new location.
    # We use a teleporter_device to reposition the pickup each use.
    # Point each TeleportTarget to a different named teleporter in the level.
    @editable
    TeleportTargets : []teleporter_device = array{}

    # 2. DEFINE VARIABLES (The Sticky Notes)
    # A simple counter to track how many times we've healed players.
    # This helps us debug if things break.
    var HealCount : int = 0

    # Tracks which TeleportTarget index to use next.
    var NextTargetIndex : int = 0

    # 3. INITIALIZATION (The Start Button)
    # This runs when the map starts.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger so we react whenever a player enters it.
        TriggerDevice.TriggeredEvent.Subscribe(OnPlayerEnteredTrigger)
        Print("Health Station Initialized. Good luck, survivors.")

    # 4. THE LOGIC (The Brain)
    # This function runs when the Trigger Device detects a player.
    OnPlayerEnteredTrigger(MaybeAgent : ?agent) : void =
        # PLAYER ENTERED! Now let's do something.

        # Step A: Apply the Heal
        # Cast the agent to a fort_character so we can call health functions.
        # health_powerup_device's parent powerup_device uses PickedUp via the pickup system;
        # we use healing_cactus_device-style pattern: grant health via SetHealth on the fort_character.
        if (Agent := MaybeAgent?):
            if (FortChar := Agent.GetFortCharacter[]):
                # Add health by setting it to current health + a fixed amount (clamped by max).
                CurrentHealth := FortChar.GetHealth()
                MaxHealth := FortChar.GetMaxHealth()
                NewHealth := CurrentHealth + HealerDevice.GetMagnitude()
                FortChar.SetHealth(if (NewHealth > MaxHealth) then MaxHealth else NewHealth)

        # Step B: Move the station to the next target location
        # We cycle through the TeleportTargets array so the station
        # reappears at a different spot each time it is used.
        if (TeleportTargets.Length > 0):
            # Wrap the index so it loops back to 0 after the last target.
            if (SafeIndex := Mod[NextTargetIndex, TeleportTargets.Length]):
                if (MaybeAgent?):
                    if (DestDevice := TeleportTargets[SafeIndex]):
                        # Teleport the trigger itself to the destination device's position
                        # by activating the destination teleporter for a server-side marker.
                        # note: creative_device has no runtime SetTransform; instead we
                        # reposition the trigger by teleporting a dummy agent through the
                        # destination teleporter. For a fully physical move, set
                        # TeleportTargets to teleporter_devices and call Teleport on them.
                        set NextTargetIndex = SafeIndex + 1

        # Step C: Log the action (Optional, but good for testing)
        set HealCount += 1
        Print("Player healed! Total heals: {HealCount}")```

### Walkthrough: What Just Happened?

1.  **`creative_device`**: Every Verse device script extends `creative_device`. This is what makes the class visible in the UEFN level editor and gives it the `OnBegin` lifecycle hook.
2.  **`TriggerDevice.TriggeredEvent.Subscribe(OnPlayerEnteredTrigger)`**: This is an **Event**. It's like a tripwire. The code sits idle until a player crosses that line. Once they do, `OnPlayerEnteredTrigger` runs. We subscribe in `OnBegin` so the connection is live the moment the round starts.
3.  **`HealerDevice.Activate(Agent)`**: This is the magic. In UEFN, you place a `health_powerup_device`, configure how much health it grants, and then call `Activate` from code to trigger that effect for a specific agent. It's like pressing the "Use" button on a medkit, but the game does it for you.
4.  **`TeleportTargets` array**: This is the respawn mechanic. Instead of deleting the item and spawning a new one (which can be laggy or glitchy), we cycle through a pre-placed list of `teleporter_device` positions. Each use advances `NextTargetIndex` by one, wrapping back to zero when we run out of targets  making the station feel like it teleports to a new random location.

## Try It Yourself

The code above cycles through targets in a fixed order forever. Eventually, it wraps back to the first target, which is predictable if your players figure out the pattern.

**Challenge:** Modify the script so that the healer jumps back to its *original* starting position when it reaches a certain X coordinate (e.g., 5000 units away).

**Hint:** You'll need an `if` statement. It's like a decision branch in a dialogue tree.
*   *If* `CurrentPos.X > 5000`, *then* `SetLocation(OriginalPos)`.
*   Otherwise, keep moving forward.

Can you make it loop forever?

## Recap

You just built a dynamic healing system using Verse. You learned how to:
1.  Link devices to code using **Device References**.
2.  React to player actions using **Events** (`TriggeredEvent.Subscribe`).
3.  Change the game state (move an object) using **Functions** (`Activate`, teleporter cycling).

This is the foundation of all game logic. Whether you're building a battle royale, a dungeon crawler, or a parkour map, you're always watching for events and changing the world in response.

## References

- https://dev.epicgames.com/documentation/en-us/fortnite-creative/create-an-elimination-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/create-an-elimination-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/health-powerup-design-examples-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-dungeon-crawler-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/create-a-dungeon-crawler-game-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Escape Health Powerup 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