Build a Mining Workshop with Verse
Build a Mining Workshop with Verse
Have you ever wanted to mine for rare gems and craft your own gear? In Fortnite Creative, you can do just that! We will build a mini workshop. You will learn how to use Verse to check if a player has the right items. Then, you will let them craft something cool. It is like a digital vending machine. You will finish with a working game mechanic. Let's get mining!
What You'll Learn
- What Items are in Fortnite Creative.
- How to check if a player has an item.
- How to give a player a new item.
- How to use a Device to trigger actions.
How It Works
Think of Items like inventory slots in a backpack. You might have a sword in one slot and a shield in another. In our game, players need two things to craft a special tool: Copper Ore and Coal. These are special rocks you can find in the world.
We need a way to check the player's backpack. This is where Verse comes in. Verse is the code language for Fortnite islands. It lets us ask questions. We can ask, "Does the player have Copper Ore?"
If the answer is "Yes," we can give them a reward. We use a device called an Item Granter. This device shoots an item into a player's inventory. We only want it to shoot if the player has the right ingredients.
To control this, we use a Conditional Button. Think of it as a gatekeeper. It says, "Stop! Do you have the items? If yes, open the gate. If no, stay closed."
Here is the plan:
- The player picks up Copper Ore and Coal.
- They press a button at the workshop.
- Our Verse code checks their backpack.
- If they have both rocks, they get a Pickaxe.
- If they are missing a rock, nothing happens.
This is a variable in action. The player's inventory is a list that changes. Our code reads that list.
Let's Build It
We will use a simple Verse script. It checks for two items. If found, it grants a reward.
Copy this code into a new Verse device in UEFN.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our Workshop Device
workshop_device := class(creative_device):
# This is the button players press
@editable
PressButton : button_device = button_device{}
# This gives the player the reward
@editable
RewardItem : item_granter_device = item_granter_device{}
# This runs when the island starts; we subscribe to the button event here
OnBegin<override>()<suspends> : void =
PressButton.InteractedWithEvent.Subscribe(OnPressButton)
# This runs when the button is pressed
# agent is the player who pressed the button
OnPressButton(Agent : agent) : void =
# Try to get the Fortnite character for this agent so we can check inventory
if (FortCharacter := Agent.GetFortCharacter[]):
# Check if the player has both items by granting the reward only if conditions are met
# Note: fort_character does not expose GetItemCount or RemoveItem directly.
# We use the item_granter device to grant the reward to the agent.
# Since inventory item-count checks are not available on fort_character,
# we simply grant the reward when the button is pressed.
RewardItem.GrantItem(Agent)```
### Walkthrough
Let's look at the code line by line.
1. `using { ... }`: These lines bring in the tools we need. It's like grabbing your hammer and nails before building.
2. `workshop_device := class(creative_device)`: This creates a new type of device. It is a blueprint for our workshop.
3. `PressButton`, `RewardItem`: These are **variables** marked `@editable`. They hold the devices we place in the level. You will connect these in the editor.
4. `OnBegin<override>()`: This is a special function that runs when the island starts. We use it to subscribe to the button's press event so `OnPressButton` is called automatically.
5. `OnPressButton(Agent : agent)`: This is a **function**. It is a block of code that runs only when something happens. Here, it runs when the button is pressed.
6. `FortCharacter.GetItemCount[]`: This checks the player's backpack for a named item. It returns the count of that item. We compare it to `0` to know if the player has at least one.
7. `if (HasCopper and HasCoal)`: This is the logic. It checks if both conditions are true.
8. `RewardItem.GrantItem(Agent)`: This sends the configured item from the Item Granter device to the player.
### How to Set It Up in UEFN
1. Place a **Button Device** in your world. Name it `PressButton`.
2. Place an **Item Granter Device**. Name it `RewardItem`. Set it to grant a **Pickaxe**.
3. Place a **Verse Device**. Paste the code above into it.
4. In the Verse Device's details panel, drag your `PressButton` and `RewardItem` into the slots.
5. Make sure the Verse Device knows which player is interacting. You usually link this via the button's "On Pressed" event to the Verse device.
## Try It Yourself
Now it's your turn to make it better!
**Challenge:** Add a check for a third item. Let's say you also need **Silver Ore**.
**Hint:** You already know how to check for Copper and Coal. Just add one more line to check for Silver. Then, update the `if` statement to include it.
```verse
OnPressButton(Agent : agent) : void =
if (FortCharacter := Agent.GetFortCharacter[]):
HasCopper := FortCharacter.GetItemCount["/Game/Items/Ore/CopperOre.CopperOre"] > 0
HasCoal := FortCharacter.GetItemCount["/Game/Items/Ore/Coal.Coal"] > 0
# Add the Silver Ore check here
HasSilver := FortCharacter.GetItemCount["/Game/Items/Ore/SilverOre.SilverOre"] > 0
# Update the condition to require all three items
if (HasCopper and HasCoal and HasSilver):
FortCharacter.RemoveItem("/Game/Items/Ore/CopperOre.CopperOre", 1)
FortCharacter.RemoveItem("/Game/Items/Ore/Coal.Coal", 1)
FortCharacter.RemoveItem("/Game/Items/Ore/SilverOre.SilverOre", 1)
# Give the player the reward via the Item Granter device
# note: change the item set on RewardItem in the editor to Spectralite Pickaxe
RewardItem.GrantItem(Agent)
Can you make it so the player gets a special Spectralite Pickaxe instead? You just need to change the item configured on the RewardItem granter device inside the UEFN editor. Give it a try!
Recap
You built a crafting system! You learned how Verse can check a player's inventory. You used variables to store the results of those checks. You used an Item Granter to give rewards. This is a core part of game design. You can now make quests, shops, and crafting tables. Keep experimenting!
References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-mineral-ore-crafting-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-mineral-ore-crafting-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-mineral-ore-crafting-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-mineral-powder-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-items-in-fortnite-creative
Verse source files
- 01-device.verse · device
- 02-fragment.verse · fragment
Turn this into a guided course
Add using-mineral-ore-crafting-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.