I want to make it so every time a new player spawns, it uses the global stack. If the stack is not globally defined, the OnPlayerSpawned Event will make the stack each time and there might be multiple people in a team. I want to only allow one person per team
using { /Fortnite.com/Devices }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath}
using { /Fortnite.com/FortPlayerUtilities }
using { /Verse.org/Simulation/Tags }
Tags on spawner devices in map
spawner := class(tag){}
A Verse-authored creative device that can be placed in a level
game_manager := class(creative_device):
# The amount of team settings devices in the map
AmountOfTeamSettings : int = 3
OnBegin<override>()<suspends>:void=
Spawners := GetCreativeObjectsWithTag(spawner{})
for (Obj : Spawners):
if (Spawner := player_spawner_device[Obj]):
Spawner.SpawnedEvent.Subscribe(OnPlayerSpawned)
OnPlayerSpawned(Agent : agent):void=
var TeamStack:stack(team) = stack(team){}
TeamCollection:= GetPlayspace().GetTeamCollection()
AllTeams := TeamCollection.GetTeams()
# Randomize Teams
RandomTeams := Shuffle(AllTeams)
for (Index := 0..AmountOfTeamSettings-1):
if(TeamStack.Push(RandomTeams[Index])):
if(var RandomTeamTuple : tuple(stack(team), team) = TeamStack.Pop[]):
set TeamStack = RandomTeamTuple(0)
var RandomTeam : team = RandomTeamTuple(1)
if(TeamCollection.AddToTeam[Agent, RandomTeam]):
Print("Player Spawned")
stack(t:type) := class:
Items:t = array{}
Push<public>(Item:t)<computes>:stack(t)=
stack(t){ Items := Items + array{Item} }
Pop<public>()<decides><computes>:tuple(stack(t), t)=
Ret:t = Items[Items.Length - 1]
(stack(t){ Items := Items.RemoveElement[Items.Length - 1] }, Ret)