Build Your Own Trap Factory with Verse
Build Your Own Trap Factory with Verse
Welcome, future game designer! Have you ever wanted to create a room in Fortnite where players can grab a Launch Pad or a Cozy Campfire and use it right away? That is what we call a "Trap Consumable." Today, we are going to build a simple machine. It will give players these cool items when they walk near it. You will learn how to make your island feel like a real shop or a supply drop. Let's get building!
What You'll Learn
- What a consumable is in Fortnite.
- How to use a variable to count how many items are left.
- How to use a function to give an item to a player.
- How to make a device disappear after it is used.
How It Works
Think of a consumable like a snack. You eat it once, and it is gone. In Fortnite, trap consumables are items like Bouncers, Chiller traps, or Launch Pads. Players can pick them up and place them in the world.
We want to build a "Dispenser." Imagine a vending machine. When you walk up to it, it gives you a snack. But here is the twist: the vending machine only has one snack inside. Once you take it, the machine is empty.
To do this, we need a variable. A variable is like a digital notebook. It holds a number that can change. We will use a variable to store the number of items left. Let's call it items_left.
We also need a function. A function is like a recipe. It is a set of instructions that the computer follows. We will write a recipe called GiveItem. When we call this recipe, it will find the player and give them the trap item.
Finally, we need to know when a player touches the machine. We will use an event. An event is like a doorbell. When someone rings the bell (or touches our machine), our code wakes up and runs the recipe.
Let's Build It
We will create a simple script. This script will live on a device in your island. When a player touches the device, it gives them a Launch Pad. Then, the device turns off so no one else can use it.
Here is the code. Copy it into a Verse script in UEFN.
# This is our main script. It lives on a device.
# We call this "MyTrapDispenser".
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation }
MyTrapDispenser := class(creative_device):
# This is our variable. It is like a counter.
# We start with 1 item inside the machine.
# var lets us change it later.
var items_left : int = 1
# This trigger device detects when a player
# walks close enough to the dispenser.
# Place a trigger_device in your island and
# connect it to this property in UEFN.
TriggerDevice : trigger_device = trigger_device{}
# OnBegin runs automatically when the island starts.
OnBegin<override>()<suspends> : void =
# Subscribe to the trigger so we hear the "doorbell".
TriggerDevice.TriggeredEvent.Subscribe(OnPlayerTouch)
# This is our recipe.
# It takes an agent (which includes players) as an input.
GiveItem(Agent : agent) : void =
# Try to get a fort_character from the agent so
# we can work with the player in the world.
if (FortChar := Agent.GetFortCharacter[]):
# Check if we have items left.
if (items_left > 0):
# Grant the player a Launch Pad consumable.
# item_spawner_device is the closest real device
# for spawning pickups; direct inventory grants
# for trap consumables require an item_granter_device
# wired in UEFN — see note below.
# note: Verse has no built-in runtime API to grant
# a named trap consumable directly. Use an
# item_granter_device placed in your island and
# wired to this class (see TrapGranter property).
TrapGranter.GrantItem(Agent)
# Take one away from our counter.
set items_left = items_left - 1
# Tell the player "Here you go!"
Print("You got a Launch Pad!")
else:
# No items left. Tell the player.
Print("Machine is empty!")
# This is the event handler (the doorbell).
# It runs when a player touches the trigger device.
OnPlayerTouch(Agent : ?agent) : void =
# Unwrap the optional agent safely.
if (RealAgent := Agent?):
# Run our recipe to give the item.
GiveItem(RealAgent)
# After giving the item, turn off the device.
# This makes it stop working for everyone else.
TriggerDevice.Disable()
# Wire an item_granter_device in UEFN to this property.
# Set that device to grant a Launch Pad with quantity 1.
# note: item_granter_device is the real Verse API for
# granting specific inventory items (including trap
# consumables) to a player at runtime.
TrapGranter : item_granter_device = item_granter_device{}```
### Walkthrough
1. **`var items_left : int = 1`**: We set up our notebook. We write the number `1` in it. This means the machine has one item.
2. **`GiveItem`**: This is our recipe. It says: "If there is more than zero items, give the player a Launch Pad. Then, subtract 1 from the count."
3. **`OnPlayerTouch`**: This is the doorbell. When a player touches the device, the game runs the `GiveItem` recipe.
4. **`TriggerDevice.Disable()`**: This is the final step. It turns the device off. It is like unplugging the vending machine.
## Try It Yourself
Now it is your turn to customize the machine!
**Challenge:** Change the code so that the machine gives a **Cozy Campfire** instead of a Launch Pad. Also, change the message that the player sees to say "Stay warm!"
**Hint:** Look at the `TrapGranter` device in your UEFN island — swap the item it is set to grant for a Cozy Campfire. Then find the `Print` line that says `"You got a Launch Pad!"` and change the text to `"Stay warm!"`.
## Recap
You just built a working dispenser! You learned that a **variable** holds a changing number. You used a **function** to group your instructions. And you used an **event** to react to a player touching your device. Great job! You are one step closer to making your own Fortnite island.
## References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-trap-consumables-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-nature-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-crafting-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/fortnite-glossary
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-trap-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.
References
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.