The Slap-Stacker: Building Infinite Energy Traps in Verse
The Slap-Stacker: Building Infinite Energy Traps in Verse
Remember that feeling when you're sprinting across the map, energy bar hits zero, and suddenly you're walking like a zombie while your opponent flanks you? It's the worst. Let's fix that.
In this tutorial, we're going to build a Slap-Stacker. This is a simple Verse script that detects when a player picks up a Slap Berry or Slap Juice and, instead of just eating it, duplicates it. You'll create a loot goblin that keeps giving you infinite slaps as long as you keep picking them up. No storm circles, no logic gates, just pure, unadulterated energy spam.
What You'll Learn
- Variables: Think of these as your inventory slots. They hold data that changes (like how many slaps you have).
- Events: These are triggers. Like a tripwire or a zone trigger, they tell your code to wake up when something happens.
- The Scene Graph: Understanding where your items live in the game world so you can grab them and move them around.
How It Works
In Fortnite Creative, you're used to dragging a Item Granter onto the floor, dropping a Slap Berry in it, and setting it to "Grant on Touch." That works for one-time loot. But if you want dynamic behavior—like "if they pick this up, give them another one"—you need Verse.
Here's the game mechanic analogy:
- The Item Granter is just a box. It doesn't know what's inside until you tell it.
- The Event is the "On Player Touch" signal. It's like the bus horn honking; it tells everyone "Hey, someone is here!"
- The Variable is your mental counter. "I have 1 slap. I ate it. Now I have 0. Wait, I got another one!"
We're going to write a script that listens for the "Touch" signal, checks if it's a Slap item, and then spawns a new one right where the old one was. It's a perpetual motion machine for healing.
Let's Build It
We need to create a Verse file that attaches to an Item Granter. When a player touches the granter, the script triggers.
The Code
Create a new Verse file in your project (right-click in the Content Browser > New > Verse File). Name it SlapSpawnerVerse. Paste this in:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
using { /UnrealEngine.com/Temporary/Diagnostics }
slap_spawner := class(creative_device):
@editable
MyGranter : item_granter_device = item_granter_device{}
@editable
MyRespawnGranter : item_granter_device = item_granter_device{}
OnBegin<override>()<suspends> : void =
MyGranter.ItemGrantedEvent.Subscribe(HandleSlapGranted)
HandleSlapGranted(GrantingPlayer : agent) : void =
MyRespawnGranter.GrantItem(GrantingPlayer)
Print("Slap granted! Energy: MAX")```
### Walkthrough
1. **`slap_spawner := class(creative_device)`**: This defines our script as a "Creative Device." It's the container that holds all our logic.
2. **`@editable MyGranter : item_granter_device`**: This is our **Variable**. It's a slot that holds a reference to the actual Item Granter device in your island. The `@editable` attribute exposes it in the UEFN editor's Details panel so you can wire it up by clicking and selecting the device. You'll do that after saving and compiling.
3. **`OnBegin<override>()<suspends> : void`**: This is the standard Verse entry point for a `creative_device`. It runs once when the game session starts. We use it to **subscribe** to the granter's built-in event so our function is called automatically.
4. **`MyGranter.ItemGrantedEvent.Subscribe(HandleSlapGranted)`**: This is the **Event** subscription — the tripwire. `ItemGrantedEvent` is the real event fired by `item_granter_device` every time it grants an item. We tell it to call `HandleSlapGranted` each time it fires.
5. **`HandleSlapGranted(GrantingPlayer : player) : void`**: This function is our responder. When the event fires it hands us the `player` who received the item, so we know exactly who to re-grant to.
6. **`MyRespawnGranter.GrantItem(GrantingPlayer)`**: This calls the real `GrantItem` method on `item_granter_device`, which grants whichever item that device is configured with in the editor to the specified player. Set its item to a Slap Berry and enable "Reset on Grant" in its properties so it is always ready to fire again. This is what creates the "infinite loop" of slaps. *Warning: This might be chaotic.*
## Try It Yourself
**Challenge:** The current code only grants Slap Berries. Modify the script to also grant **Slap Juice** if the player picks up a Slap Berry.
**Hint:** Add a second `@editable item_granter_device` configured with Slap Juice. Then inside `HandleSlapGranted`, pick randomly between the two granters using `GetRandomInt`. Use an `if/else` statement to decide which granter fires!
*Example logic:*
```verse
# note: GetRandomInt(low, high) returns an int in [low, high] inclusive.
RandomChoice : int = GetRandomInt(0, 1)
if (RandomChoice = 0):
MyRespawnGranter.GrantItem(GrantingPlayer)
else:
MyJuiceGranter.GrantItem(GrantingPlayer)
Recap
You've just built your first dynamic item system in Verse. You learned how to:
- Use a Variable to hold a reference to a device.
- Trigger code with an Event (
ItemGrantedEvent+Subscribe). - Manipulate the Scene Graph by re-granting items through a second configured device.
Now go forth and slap your friends into next week. Or just heal yourself indefinitely. Your call.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-slap-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-slap-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-grenade-consumables-in-fortnite-creative
Verse source files
- 01-device.verse · device
- 02-fragment.verse · fragment
Turn this into a guided course
Add using-slap-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.