The Ultimate Grenade Launcher: Build Your Own Grenade Game
Tutorial beginner compiles

The Ultimate Grenade Launcher: Build Your Own Grenade Game

Updated beginner Code verified

The Ultimate Grenade Launcher: Build Your Own Grenade Game

Welcome, future game designer! Do you want to add some boom to your Fortnite island? Grenades are the most fun way to make things explode, freeze, or fly away. In this tutorial, we will build a simple game. You will create a "Grenade Drop Zone." Players will catch grenades and throw them at targets. It is easy to make and super fun to play. Let's start coding!

What You'll Learn

  • How to use variables to track player actions.
  • How to use events to react to player choices.
  • How to give players items using code.
  • How to make a simple game loop with loops.

How It Works

Imagine you are at a birthday party. You have a piñata. When you hit it, candy falls out. In Fortnite, we can make a code version of this. We need three things. First, a variable. A variable is like a digital notebook. It stores a number that changes. We will use it to count how many grenades a player has. Second, an event. An event is like a trigger. It happens when something occurs. We will use it when a player picks up an item. Third, a function. A function is like a recipe. It is a set of steps the computer follows. We will write a recipe to give the player a grenade.

We will also talk about the scene graph. Think of the scene graph as a family tree for your game objects. Every prop and device is a "child" of the main game world. We can talk to them directly using their names. This helps us tell a specific grenade to move or change.

Let's Build It

We will make a device that gives players a grenade when they press a button. This is safer than letting them pick up dangerous items randomly. We will use a Switch device. When you flip the switch, the code runs. The code gives you a grenade. Then, you can throw it!

Here is the code for your island. Copy this into a Verse script device.

# This is a Verse script for a grenade dispenser.
# It gives a player a grenade when they use a device.

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

# This is our main script block.
# It holds all the code for our dispenser.
grenade_dispenser := class(creative_device):

    # 'ItemGranter' is a item_granter_device placed in your scene.
    # Connect it in the UEFN editor's details panel.
    # note: Verse has no direct GiveItem() API on player; item_granter_device is the correct way to grant items.
    @editable
    ItemGranter : item_granter_device = item_granter_device{}

    # OnBegin runs when the island starts.
    # We subscribe to the item granter's activation here.
    OnBegin<override>()<suspends> : void =
        # We print a message to the console.
        # This helps us know the device started correctly.
        Print("Grenade dispenser is ready!")

    # This function is called by a button_device or switch
    # wired to this device via the UEFN event binding panel.
    # 'Agent' is the person who flipped the switch.
    OnPlayerUsed(Agent : agent) : void =
        # We tell the item granter to give its configured item to the agent.
        # Set the item granter's item to "Grenade" in the UEFN editor.
        ItemGranter.GrantItem(Agent)

        # We print a message to the console.
        # This helps us know it worked.
        Print("A grenade was granted!")

Walkthrough of the Code

Let's look at each part. The first lines say using. This tells Verse we want to use tools from Fortnite. We need devices and characters. Next, we have grenade_dispenser := class(creative_device). This names our script. Think of it like naming a folder. Inside the folder, we put our rules. The @editable line above ItemGranter lets you connect a real Item Granter device from the UEFN editor. The OnBegin part runs when the island starts. The OnPlayerUsed part is the event handler. It waits for a player to interact with the device. The ItemGranter.GrantItem(Agent) line is the function call. It tells the item granter device to put its configured item into the player's inventory. The word Print shows a message in the debug screen. This is helpful for testing.

Building the Island

Now, let's build the island in UEFN. First, place a Button device. This is your button. Next, place an Item Granter device nearby. Open the Item Granter device settings. Set its item to Grenade. Next, place a Verse Script device nearby. This is your brain. Open the Verse Script device. Paste the code above into it. Make sure the script's ItemGranter property is connected to your Item Granter device in the details panel. Wire the Button device's OnButtonActivated event to call your script's OnPlayerUsed function. Now, test your island. Press Play. Walk up to the button. Press it. Look at your inventory. You should see a grenade! Pick it up. Throw it at a wall. Watch it explode. You did it!

Try It Yourself

You made a basic grenade dispenser. Now, let's make it cooler. Can you make a dispenser that gives a Chiller Grenade instead? A Chiller Grenade freezes players in ice. It is great for puzzles. Try changing the item set in the Item Granter device from Grenade to Chiller Grenade. Save your script. Test it again. Did you get a freezing grenade? If you get stuck, think about the other grenade types. There are many to try!

Recap

You learned how to use Verse to give players items. You used a variable concept by storing the item name. You used an event to trigger the action. You used a function to give the item. You also learned about the scene graph by talking to the player device. You built a working game feature. Great job! Keep experimenting with different grenades.

References

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

Verse source files

Turn this into a guided course

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