Build a Team-Based Fort Island with Verse
Build a Team-Based Fort Island with Verse
Welcome, young game makers! Have you ever played a game where you pick a team color? Maybe Blue Team or Red Team? In Fortnite Creative, we can make islands where teams matter. We can make rules so only Blue Team players can use certain doors. We can make health packs that only heal Red Team players. This is called Player Options.
In this tutorial, we will build a simple "Team Challenge" island. We will use Verse to check which team a player is on. Then, we will give them a special gift if they are on the right team. You will learn how to talk to the game engine about players. Let's get started!
What You'll Learn
- What a Player is in the code world.
- How to check a player's Team.
- How to give a player an Item using Verse.
- How to use If/Else logic for team choices.
How It Works
Imagine you are at a party. You have two groups of friends. One group wears blue shirts. The other group wears red shirts. You have a box of cookies. You want to give cookies only to the blue-shirt friends.
In Fortnite, a Player is the person controlling their character. Every player has a Team. The team is like a label. It says "You are on Team 1" or "You are on Team 2."
We can use Verse to ask the game: "Who is this player?" Then we ask: "What is their team?" If the answer is "Blue," we give them a gift. If the answer is "Red," we do nothing. This is called Conditional Logic. It means the game makes a choice based on a rule.
We will also use a Device. A device is a tool in Fortnite. We will use a Trigger Volume. This is like an invisible mat on the floor. When a player steps on it, the Verse code wakes up. It checks the team. Then it acts.
Let's Build It
We will build a "Team Door." If you are on Team 1, you get a shield potion. If you are not on Team 1, nothing happens.
First, open UEFN. Create a new island. Place a Trigger Volume in the middle of the map. Make it big enough to stand on.
Next, we need to write the Verse code. Click on the Trigger Volume. Go to the Verse tab. Click Create New Verse Script.
Here is the code. Read it carefully.
# This is our Team Door script
# It runs when a player steps on the trigger
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# We attach this class to a trigger_device placed in the editor
team_door_device := class(creative_device):
# Reference to the trigger device placed in the editor
@editable
Trigger : trigger_device = trigger_device{}
# Reference to an item_granter_device placed in the editor.
# Set its item to Shield Potion Small in the UEFN editor properties.
# note: Verse has no direct GrantItem() API; item_granter_device is the real mechanism.
@editable
ItemGranter : item_granter_device = item_granter_device{}
# OnBegin runs once when the island starts
OnBegin<override>()<suspends> : void =
# Subscribe to the trigger's TriggeredEvent
Trigger.TriggeredEvent.Subscribe(OnTriggerEnter)
# This function runs when a player steps on the trigger
OnTriggerEnter(Agent : ?agent) : void =
# Check if the agent is actually a player
if (ActualAgent := Agent?):
if (Player := player[ActualAgent]):
# Ask the game for this player's team collection
# GetTeamCollection() is a method on fort_playspace
Playspace := GetPlayspace()
TeamCollection := Playspace.GetTeamCollection()
# GetTeam() returns an option; the 'if' unwraps it
if (Team := TeamCollection.GetTeam[Player]):
# GetTeams() returns all teams; find the index by locating our team in the array
# note: fort_team_collection has no GetTeamIndex(); we compare teams manually.
Teams := TeamCollection.GetTeams()
var TeamIndex : int = 0
var Idx : int = 0
for (T : Teams):
set Idx = Idx + 1
if (T = Team):
set TeamIndex = Idx
# Let's check if they are on Team 1 (index 1)
if (TeamIndex = 1):
# They are on Team 1! Give them a gift via the item granter.
ItemGranter.GrantItem(ActualAgent)
# Print a message to the chat for fun
# note: Print() writes to the UEFN output log; no in-game chat API exists in Verse.
Print("You are on Team 1! Here is a potion!")
else:
# They are NOT on Team 1.
# Do nothing, or say hello.
Print("You are not on Team 1. Try again!")```
### Code Walkthrough
1. **`OnBegin`**: This is the **startup function**. It runs once when the island loads. It connects the trigger's event to our `OnTriggerEnter` function using `Subscribe`.
2. **`OnTriggerEnter`**: This is an **Event Handler**. An event is something that happens in the game. Like a bell ringing. When someone steps on the trigger, this code starts.
3. **`Agent : agent`**: This is the **Parameter**. It is the person who stepped on the mat. The game calls them "Agent."
4. **`if (Player := player[Agent])`**: This checks if the agent is a player. Not every agent is a player. This line makes sure it is a human player.
5. **`GetTeamCollection()`**: This is a **Function**. It asks the game for the object that knows about all teams on the island.
6. **`TeamCollection.GetTeamIndex(Team)`**: This gives us back the team's number. Team 1 returns `1`, Team 2 returns `2`, and so on.
7. **`if (TeamIndex = 1)`**: This is a **Comparison**. We are asking if the team number is one. In Verse, `=` inside an `if` is a failable equality check.
8. **`ItemGranter.GrantItem(Agent)`**: This tells the `item_granter_device` to give the player its configured item. We set the item to Shield Potion Small in the UEFN editor. This is the **Reward**.
## Try It Yourself
Now it is your turn to be creative!
**Challenge:** Change the code so that Team 2 players get the potion instead of Team 1.
**Hint:** Look at the line `if (TeamIndex = 1)`. Change the `1` to the number for Team 2. Remember, Team 1 is 1. So Team 2 is probably 2.
**Bonus Challenge:** Add an `else if` block. If the player is on Team 2, print "Hello Team 2!" to the chat.
## Recap
You just built a smart door! You learned that players have teams. You used Verse to check that team. You gave a reward based on that team. This is the power of **Player Options**. You can make games that feel different for every team. Keep coding and have fun!
## References
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/random-sentry-fight-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-player-spawn-pad-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-class-designer-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-class-designer-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-fuel-pump-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Player Options 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.