The Magic Healing Potion: Making Your Island Heal Players
Tutorial beginner compiles

The Magic Healing Potion: Making Your Island Heal Players

Updated beginner Code verified

The Magic Healing Potion: Making Your Island Heal Players

Do you want to give your players a superpower? You can make items that fix their health! This is like a magic potion in a video game. We will use Verse to make a pizza slice heal a player when they touch it. It is fun to see numbers go up. Let's build a healing zone together.

What You'll Learn

  • What a Restorative Item is.
  • How to use a Prop Mover to make items appear.
  • How to use Verse to check if a player is touching something.
  • How to give health back to a player.

How It Works

Imagine you are playing a game. You get hurt by a trap. Ouch! You need to feel better. In Fortnite, we use Restorative Items. These are items that fix your health or shield. Health is your green bar. Shield is your blue bar.

We will build a "Pizza Party" zone. When a player walks into the zone, they get a pizza slice. When they eat it, they get health back.

Here is the plan:

  1. We place a Prop Mover device. This device holds a pizza slice.
  2. We write a small Verse script. This script is like a rulebook.
  3. The rule says: "If a player touches this pizza, give them health."

In programming, we call this an Event. An event is something that happens in the game. Like a door opening or a button being pressed. We want to watch for the event of a player touching the pizza.

Let's Build It

First, open UEFN. Go to your Creative Island.

  1. Place a Prop Mover device.
  2. Open the device settings. Choose a Pizza Slice from the item list.
  3. Make sure the item is set to Grant to players. This means it gives it to them.
  4. Now, we need Verse code to make it heal them.

Here is the code. Copy this into a new Verse script file. Attach this script to your Prop Mover.

# This is our healing pizza script!
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# We tell Verse which device we are using.
# This is like giving the script a name tag.
healing_pizza_manager := class(creative_device):

    # We connect to a Trigger device placed in the world.
    # The Trigger fires when a player walks into its zone.
    @editable
    HealTrigger : trigger_device = trigger_device{}

    # This is the main function.
    # It runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # We subscribe to the TriggeredEvent so we know
        # when a player walks into the trigger zone.
        HealTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)

    # This function runs every time a player enters the trigger.
    OnPlayerEntered(Agent : ?agent) : void =
        # We need to turn the agent into a fort_character
        # so we can change their health.
        # note: GetFortCharacter() returns an option type; we use 'if' to unwrap it safely.
        if (ActualAgent := Agent?, Character := ActualAgent.GetFortCharacter[]):
            # Then we heal them!
            # We add 25 health to their green bar.
            # note: SetHealth sets the absolute value; we read current health first and add 25.
            CurrentHealth := Character.GetHealth()
            NewHealth := CurrentHealth + 25.0
            Character.SetHealth(NewHealth)```

Let's look at the important parts.

`healing_pizza_manager := class(creative_device):`
This line defines our script as a device class. Every Verse script that runs on your island must extend `creative_device`. It is the foundation every script is built on.

`@editable`
`HealTrigger : trigger_device = trigger_device{}`
This connects a **Trigger** device to our script. You place a Trigger in the world around your pizza prop. When a player steps inside it, the Trigger fires. The `@editable` tag lets you pick the exact Trigger from your island inside UEFN.

`HealTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)`
This is **subscribing to an event**. We are telling the game: "Every time the Trigger fires, call my `OnPlayerEntered` function." This is how Verse listens for things that happen.

`if (Character := Agent.GetFortCharacter[]):`
This safely unwraps the player's character. We need a `fort_character` to change health values. The `if` check makes sure the player is valid before we do anything.

`Character.SetHealth(NewHealth)`
This is the magic line! It sets the player's health to their old value plus 25. If they were hurt, they feel better now.

## Try It Yourself

Great job! You made a healing pizza. Now, try to change the code.

**Challenge:**
Change the amount of health given. Right now, it gives `25.0`. Try changing it to `50.0`. What happens when you play?

**Hint:**
Look for the number `25.0` near the `SetHealth` line. Change it to `50.0`. Save your code and test it in the game. See if the green bar fills up faster!

## Recap

You learned how to make a healing item. You used a Prop Mover to hold the pizza. You used Verse to give the player health. You used a Trigger device to detect when players step into the zone. Your island is now a safer place for friends to play. Keep coding!

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite/using-restorative-items-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-restorative-consumables-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-items-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/using-items-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-healing-items-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-restorative-items-in-fortnite-creative 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