Getting the team of a Player

I am trying to get the team of a player as an int value using verse code. I am not sure but I think I have to use GetPlaySpace for this. But I can only seem to get something of type team. I do not know what this type team is and I do not think there is any documentation on this.

1 Like

The team should have a stable index in the GetPlayspace().GetTeamCollection().GetTeams() array if you want a representative team number.

    TeamCollection := GetPlayspace().GetTeamCollection()

    if (AgentsTeam := TeamCollection.GetTeam[Agent]):

        TeamArray := TeamCollection.GetTeams()

        for (TeamNumber->Team : TeamArray):
            
            if (AgentsTeam = Team):
                # If you get here the team's number will be TeamNumber
4 Likes

Thanks, but it is not what I am looking for. This works fine if you have players in team 1, 2, 3 etc. But if you have just 1 player in the map that is on team 2, after if (AgentsTeam = Team): TeamNumber will be 0, because TeamArray only contains a single team, team 2. What I expect is TeamNumber to be 1 for team 2 but this code does not work like that.

If you have the number of teams set in your IslandSettings the TeamArray should be the same length as that. That being said we did encounter an issue internally where creative team indices were not matching the team indices in verse which should be fixed in an upcoming release.

Actually, the array does not contain just 1 team like I said before, but it indeed it is equal to the number of teams in the island settings like you said. But yeah, for whatever reason I am always the 1st team (index 0) in the array, no matter what my team is

1 Like

Hello, I have a same type of problem. I want that, if the Playercounter1 is true, then all Players that are not in Team1, to automatically switch to Team 2. And if he Playercounter2 is true, then all Players that are not in Team2, to automatically switch to Team 1. For a Box fights. May you guys help me with the code in Verse. Would help me a lot. Thanks <3