Boom Goes the Dynamite: Making Explosive Traps with Verse
Tutorial beginner compiles

Boom Goes the Dynamite: Making Explosive Traps with Verse

Updated beginner Code verified

Boom Goes the Dynamite: Making Explosive Traps with Verse

Do you like big explosions? πŸ’₯

We are going to build a trap. It looks like a simple crate. But when someone touches it... BOOM!

You will learn how to make things explode using Verse. Verse is the code language for Fortnite Creative. It helps you make your island unique.

You will give players a crate. When they touch it, it explodes. You can use this for a puzzle or a fun trap. Let's make some noise!

What You'll Learn

  • How to use a Trigger Volume. This is an invisible box that senses when a player enters.
  • How to use Event Handling. This is a rule that says "do this when that happens."
  • How to spawn an Explosive Consumable. This is an item like Dynamite that blows up.
  • How to make the game feel exciting with code.

How It Works

Imagine you are building a Lego tower. You put a special block at the bottom. If someone bumps the tower, the special block triggers a mechanism.

In Fortnite, we use a Trigger Volume. Think of it like an invisible pressure plate. It has no shape you can see. But it knows when a player walks into it.

When a player enters the box, we want something to happen. We want to give them an explosive item. In Fortnite, items like Dynamite or Bottle Rockets are called Consumables. They are items you use and then they are gone.

We will write code that says: "If a player enters this box, give them Dynamite."

This is called an Event. An event is a moment in time. The event here is "Player Entered." The action is "Give Item."

We will also use a Device. A Device is a tool in Fortnite Creative. We will use a Trigger Volume device. It is easy to place in the world.

Let's write the code to make this magic happen.

Let's Build It

First, place a Trigger Volume in your island. Make it big enough for a player to walk into.

Now, open the Verse editor. We will write a script. This script connects to your Trigger Volume.

Here is the code. Read it carefully.

# This is a comment. It explains the code.
# We are making a script that works with a Trigger Volume.

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

# This is our main script.
# It "owns" the Trigger Volume device.
explosive_trap_device := class(creative_device):

    # This is the Trigger Volume device placed on your island.
    # Link this slot to your Trigger Volume in the editor.
    @editable
    MyTrigger : trigger_device = trigger_device{}

    # OnBegin runs automatically when the game starts.
    # We use it to connect our function to the trigger's event.
    OnBegin<override>()<suspends> : void =
        # Subscribe tells the trigger: "Call OnPlayerEntered
        # every time a player walks into the volume."
        MyTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)

    # This function runs when a player enters the trigger.
    # 'Agent' is the person who walked in.
    OnPlayerEntered(Agent : ?agent) : void =
        # Cast the agent to a fort_character so we can
        # interact with them as a Fortnite player character.
        if (ActualAgent := Agent?, Character := ActualAgent.GetFortCharacter[]):
            # Consumable granting is handled through the
            # item_granter_device in UEFN. Here we just
            # print a message to confirm the trigger fired.
            # Wire an item_granter_device to do the actual
            # item grant (see placement steps below).
            # note: There is no direct GiveConsumable() API
            # on fort_character; use item_granter_device instead.
            Print("Trap triggered! Granting explosive item.")```

Wait, that code is a bit tricky. Let's look at a simpler version that works with the Trigger Volume device directly.

Here is a better way. We will use the `TriggeredEvent` from the `trigger_device` and an **Item Granter Device** to actually hand out Dynamite.

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

# This script attaches to a creative_device you place on your island.
# It connects a trigger_device to an item_granter_device.
explosive_trap_device := class(creative_device):

    # Place a Trigger Volume on your island and link it here.
    @editable
    MyTrigger : trigger_device = trigger_device{}

    # Place an Item Granter device on your island.
    # Set its item to Dynamite in the device properties.
    # Then link it to this slot.
    # note: item_granter_device is the real API for giving
    # consumable items to players in UEFN Verse.
    @editable
    MyItemGranter : item_granter_device = item_granter_device{}

    # OnBegin runs automatically when the game starts.
    # We connect our function to the trigger here.
    OnBegin<override>()<suspends> : void =
        MyTrigger.TriggeredEvent.Subscribe(OnTriggerEntered)

    # This function runs when a player enters the trigger volume.
    # 'Agent' is the person who walked in.
    OnTriggerEntered(Agent : agent) : void =
        # Tell the Item Granter to give its item to this agent.
        # The item (Dynamite) is configured in the device properties.
        MyItemGranter.GrantItem(Agent)
        Print("Dynamite granted! Watch out!")

Walkthrough

Let's break down what each part does.

  1. using { /Fortnite.com/Devices }: This tells Verse we want to use Fortnite devices. It is like opening a toolbox.
  2. explosive_trap_device := class(creative_device):: This creates our script as a device class. Every Verse script you place on an island extends creative_device.
  3. @editable MyTrigger : trigger_device: This creates a slot for our Trigger Volume device. You will link this to the Trigger Volume in the editor.
  4. @editable MyItemGranter : item_granter_device: This creates a slot for our Item Granter device. You will set its item to Dynamite in the editor.
  5. OnBegin<override>()<suspends> : void =: This function runs automatically when the game starts. We use it to wire up our event subscription.
  6. MyTrigger.TriggeredEvent.Subscribe(OnTriggerEntered): This connects the function to the device. Now, when someone walks in, the code runs.
  7. MyItemGranter.GrantItem(Agent): This is the magic line. It tells the Item Granter device to give its configured item to the player. You set the item to Dynamite in the device's properties panel.

How to Place It

  1. Place a Trigger Volume in your game.
  2. Make it large. Use the editor to stretch it.
  3. Place a crate or a box nearby. This is the "trap."
  4. Place an Item Granter device anywhere on your island. In its properties, set the item to Dynamite.
  5. Place a Verse Device on your island and assign the explosive_trap_device class to it.
  6. Open the Verse editor.
  7. Paste the code above.
  8. In the Verse device properties, link the MyTrigger slot to your Trigger Volume and the MyItemGranter slot to your Item Granter.
  9. Play the game! Walk into the invisible box. You should get Dynamite in your hand.

Try throwing it! πŸ’£

Try It Yourself

You gave players Dynamite. That is cool. But what if you want to give them something different?

Challenge: Change the code to give players Bottle Rockets instead of Dynamite.

Hint: Bottle Rockets are also a consumable. They shoot fire in the air. Look at the MyItemGranter device in the editor. What item do you need to set it to?

Hint 2: You can find the name of the item in the Fortnite Creative inventory. It is usually the same as the item name.

If you get stuck, think about what the item is called. Is it "BottleRocket" or "Bottle_Rocket"? Try both!

Recap

You built a working trap! πŸŽ‰

You learned how to use a Trigger Volume. This is an invisible box that senses players. You learned how to write an Event. This is code that runs when something happens. You learned how to Give Consumables. This gives players items like Dynamite.

Verse is powerful. You can make many more traps. You can make puzzles. You can make games that no one has seen before. Keep coding!

References

  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-explosive-consumables-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/using-explosive-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-power-crafting-consumables-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-grenade-consumables-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-explosive-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