This section shows how to find the devices at runtime that you set up earlier.
-
Open Verse Explorer and double-click team_elimination_game.verse to open the script in Visual Studio Code.
-
At the top of the file:
-
Add
using { /Fortnite.com/Game }
to reference theelimination_result
struct. -
Add
using { /Fortnite.com/Characters }
to use theGetFortCharacter[]
API.
using { /Fortnite.com/Characters } using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Fortnite.com/Teams } using { /Verse.org/Simulation }
-
-
In the
team_elimination_game
class definition, add the following fields:-
An editable
item_granter_device
array variable namedWeaponGranters
to store all the item granters needed to grant weapons to players.@editable var WeaponGranters : []item_granter_device = array{}
-
An integer variable named
EliminationsToEndGame
to represent the number of eliminations needed for one player to win for their team. A team wins once one of their players advances past the final weapon in the sequence.var EliminationsToEndGame : int = 0
-
An editable
end_game_device
namedEndGameDevice
to end the game once a team reachesEliminationsToEndGame
.@editable EndGameDevice : end_game_device = end_game_device{}
-
An editable
sentry_device
array variable namedSentries
to store the sentries for testing eliminations.@editable var Sentries : []sentry_device = array{}
-
An editable
player_spawner_device
array variable namedPlayerSpawners
to store the player spawn pads for both teams.@editable var PlayerSpawners : []player_spawner_device = array{}
-
A team array variable named
Teams
to store a reference to each team in the game.var Teams : []team = array{}
-
Your
team_elimination_game
class definition should now look like the code below:team_elimination_game := class(creative_device): @editable EndGameDevice : end_game_device = end_game_device{} @editable var WeaponGranters : []item_granter_device = array{} @editable var PlayerSpawners : []player_spawner_device = array{} @editable var Sentries : []sentry_device = array{} var EliminationsToEndGame : int = 0 var Teams : []team = array{}
-
-
In
OnBegin()
, update theTeams
array with each team that you set up earlier in Island Settings. You can use theGetTeams()
function from thefort_team_collection
API to get an array of all teams in the playspace.OnBegin<override>()<suspends> : void = # Get all the players set Teams = GetPlayspace().GetTeamCollection().GetTeams()
-
Set the
EliminationsToEndGame
to the length ofWeaponGranters
. This ensures that the game only ends once a player progresses past the final weapon. YourOnBegin()
code should now look like the code below:OnBegin<override>()<suspends> : void = # Get all the players set Teams = GetPlayspace().GetTeamCollection().GetTeams() set EliminationsToEndGame = WeaponGranters.Length Print("Number of eliminations to end game is {EliminationsToEndGame}")
-
Save the script in Visual Studio Code, and in the UEFN toolbar, click Verse, then Build Verse Code to update your Verse-authored device in the level.
-
Select the team_elimination_game device. In the Details panel, add each Item Granter to the WeaponGranters array, each Player Spawn Pad to the PlayerSpawners array, each Sentry to Sentries, and the End Game Device to EndGameDevice.
The order in which you add the item granters is important! Make sure the order in the Details panel matches the order you want your players to progress through weapons in game.
-
Click Launch Session in the UEFN toolbar to playtest the level. When you playtest your level,
EliminationsToEndGame
should be equal to the length of yourWeaponGranters
array. Verify this behavior with the log.
Next Step
In the next step of this tutorial, you’ll learn how to assign players a weapon at the start of the game and subscribe to their spawn events.