The Magic Pizza Box: Healing on Your Island
Tutorial beginner compiles

The Magic Pizza Box: Healing on Your Island

Updated beginner Code verified

The Magic Pizza Box: Healing on Your Island

Do you ever get hit in a game and feel your health go down? It's not fun! But what if you could fix it with a slice of pizza? Today, we will build a healing station. You will learn how to give players health and shields. It is like giving players a magic power-up.

What You'll Learn

  • What Health and Shield are.
  • How to use the Item Spawner device.
  • How to make a Restorative Item appear.
  • How to test your healing station.

How It Works

Imagine you are playing a video game. You have two bars on your screen. One is green. That is your Health. It shows how much life you have. The other is blue. That is your Shield. It acts like a protective bubble.

Sometimes, you lose Health or Shield. You might get hit by an enemy. Or you might fall off a cliff. You need to feel better fast!

In Fortnite Creative, we have special items. We call them Restorative Items. These items give Health or Shield back to the player. Think of them like a video game potion.

We can make these items appear using a device. This device is called an Item Spawner. An Item Spawner is like a magic box. You tell it what item to give. Then, you press a button. The item appears!

We will build a simple room. It will have a button. When you press the button, you get a Pizza Slice. The Pizza Slice will heal you. It is simple, but it is very powerful.

Let's Build It

First, let's look at the code. Don't worry. It is very short. We will explain it line by line.

# This is our healing station script
# It runs when the game starts

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

healing_station := class(creative_device):

    # We connect the Item Spawner device in the editor
    # Drag your Item Spawner into this property slot
    @editable
    HealingBox : item_spawner_device = item_spawner_device{}

    # We connect the Trigger device in the editor
    # Drag your Trigger into this property slot
    @editable
    HealingButton : trigger_device = trigger_device{}

    # OnBegin runs automatically when the game starts
    OnBegin<override>()<suspends> : void =
        # We tell the trigger what to do when a player enters
        # A trigger is like a sensor that watches for players
        HealingButton.TriggeredEvent.Subscribe(OnPlayerHeals)

    # This function runs when someone hits the button
    # We tell the Item Spawner to spawn the item
    OnPlayerHeals(Agent : ?agent) : void =
        # We call SpawnItem on the Item Spawner device
        # The spawner already knows which item to give
        # because you set it in the editor properties
        HealingBox.SpawnItem()
        # note: item type (Pizza Slice, Shield Mushroom, etc.)
        # is configured on the item_spawner_device in the UEFN
        # editor panel, not passed as a code argument

Let's break this down.

1. The Setup We start by getting the Item Spawner. This is the device in your level. You connect it in the editor by dragging it into the HealingBox property slot. This is like giving your toy a name tag.

2. The Variable We create a property called HealingBox. A property is a container. It holds a value. Here, it holds the Item Spawner device. We can swap it out in the editor if we want.

3. The Trigger We find a Trigger. A trigger is a sensor. It watches for players. We connect it in the editor by dragging it into the HealingButton property slot. When a player walks into it, something happens.

4. The Action We tell the trigger what to do. We use TriggeredEvent.Subscribe. This means "when a player enters this zone." We connect it to a function called OnPlayerHeals.

5. The Healing The OnPlayerHeals function tells the Item Spawner to spawn the item. The player picks it up. They eat it. Their Health goes up!

How to Place It in UEFN

  1. Open your island in the Creative tool.
  2. Place an Item Spawner device. In its editor panel, set the item to Pizza Slice.
  3. Place a Trigger device.
  4. Place the Verse script in the same folder and compile it.
  5. Select your healing_station device in the level. Drag the Item Spawner into the HealingBox slot. Drag the Trigger into the HealingButton slot.
  6. Save and Play.

Try It Yourself

You did it! You made a healing station. Now, try this challenge.

Challenge: Change the Pizza Slice to a Shield Mushroom.

Hint: Look at your Item Spawner device in the UEFN editor panel. Find the item property. It says Pizza Slice. Can you change that value? Try selecting Shield Mushroom instead. Save and play again. What happens when you press the button?

Recap

You built a healing station! You learned about Health and Shield. You used an Item Spawner. You used a Trigger to detect players. You gave players a magic item. Great job!

References

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

Verse source files

Turn this into a guided course

Add using-restorative-consumables-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