Teleport all players when one team is eliminated - Verse

Hello everyone,

I have a problem with my code and hope someone can help me.

My goal is to use the team size of each team as the maximum eliminations - what I think is already working. When all players of a team are eliminated, all players should be teleported to pre-defined team teleporters.

Unfortunately, my code is not working as intended. Currently, only the eliminated player is teleported, not the entire team of both teams when all team members are eliminated.

Here is a my code:

`TeleportToGame := class(creative_device):

respawnposition: vector3=vector3{X:= 1800.00, Y:= -3700.00, Z:= 161.9}

@editable
TeleporterTeam1 : teleporter_device = teleporter_device{}
@editable
TeleporterTeam2 : teleporter_device = teleporter_device{}

@editable
ElimManagerT10 : elimination_manager_device  = elimination_manager_device{}
@editable
ElimManagerT20 : elimination_manager_device  = elimination_manager_device{}


var DeathsT10 : int = 0
var DeathsT20 : int = 0


NowRespawn(Agent : agent)<suspends> : void =
    Sleep(3.0)
    Agent.Respawn(respawnposition, rotation{})
    TeleporterTeam1.Teleport(Agent)
    TeleporterTeam2.Teleport(Agent)


SelfEliminated(Agent : agent) : void =
    AllPlayers := GetPlayspace().GetPlayers()
    for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
        var TeamSize : int = 0

        if(NewTeamSize := GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length , set TeamSize = NewTeamSize):
            Print("Teleport ready")

        if (DeathsT10 = TeamSize):
            spawn{NowRespawn(Agent)}

        if (DeathsT20 = TeamSize):
            spawn{NowRespawn(Agent)}


Team1(Agent:agent) : void =
    set DeathsT10 += 1
    AllPlayers := GetPlayspace().GetPlayers()
    for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
        var TeamSize : int = 0

        if(NewTeamSize := GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length , set TeamSize = NewTeamSize):
            Print("Teamgröße: {TeamSize}")

        if (DeathsT10 < TeamSize):
            set DeathsT10 += 1
            Print("Deaths T10: {DeathsT10}")
        else:
            SelfEliminated(Agent)
            set DeathsT10 = 0
            set DeathsT20 = 0
    

Team2(Agent:agent) : void =
    set DeathsT20 += 1
    AllPlayers := GetPlayspace().GetPlayers()
    for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
        var TeamSize : int = 0

        if(NewTeamSize := GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length , set TeamSize = NewTeamSize):
            Print("Teamgröße: {TeamSize}")
        if (DeathsT20 < TeamSize):
            set DeathsT20 += 1
            Print("Deaths T20: {DeathsT20}")
        else:
            SelfEliminated(Agent)
            set DeathsT10 = 0
            set DeathsT20 = 0



OnBegin<override>()<suspends> : void =
    ElimManagerT10.EliminatedEvent.Subscribe(Team1)
    ElimManagerT20.EliminatedEvent.Subscribe(Team2)`
1 Like

When you call SelfEliminated, you only pass a single agent in. You’re essentially respawning the same agent one time for every player on the team.

In your Team1() and Team2() functions, instead of calling SelfEliminated(Agent) perhaps try calling SelfEliminated(TeamPlayer) ?

Edit: oops, I thought TeamPlayer was cycling through the eliminated agent’s team’s players, but it is actually cycling through all players. You’ll need to adjust things a bit. You actually are respawning the eliminated agent once for every player in the whole game.

I apologize but don’t have enough time to type up a solution right now but can come back to help in a bit if you still need assistance :slight_smile:

2 Likes