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_resultstruct.Add
using { /Fortnite.com/Characters }to use theGetFortCharacter[]API.Verseusing { /Fortnite.com/Characters } using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Fortnite.com/Teams } using { /Verse.org/Simulation }
In the
team_elimination_gameclass definition, add the following fields:An editable
item_granter_devicearray variable namedWeaponGrantersto store all the item granters needed to grant weapons to players.Verse@editable var WeaponGranters : []item_granter_device = array{}An integer variable named
EliminationsToEndGameto 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.Versevar EliminationsToEndGame : int = 0An editable
end_game_devicenamedEndGameDeviceto end the game once a team reachesEliminationsToEndGame.Verse@editable EndGameDevice : end_game_device = end_game_device{}An editable
sentry_devicearray variable namedSentriesto store the sentries for testing eliminations.Verse@editable var Sentries : []sentry_device = array{}An editable
player_spawner_devicearray variable namedPlayerSpawnersto store the player spawn pads for both teams.Verse@editable var PlayerSpawners : []player_spawner_device = array{}A team array variable named
Teamsto store a reference to each team in the game.Versevar Teams : []team = array{}Your
team_elimination_gameclass definition should now look like the code below:Verseteam_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
In
OnBegin(), update theTeamsarray with each team that you set up earlier in Island Settings. You can use theGetTeams()function from thefort_team_collectionAPI to get an array of all teams in the playspace.VerseOnBegin<override>()<suspends> : void = # Get all the players set Teams = GetPlayspace().GetTeamCollection().GetTeams()Set the
EliminationsToEndGameto 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:VerseOnBegin<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,
EliminationsToEndGameshould be equal to the length of yourWeaponGrantersarray. 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.