How To Get fort_character from a Specific Team

Hello! I’m trying to figure out how to get the fort_character from the Team 4

    var Teams: []team = array{}
    

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
       
        #Get All Teams in the game
        set Teams = Self.GetPlayspace().GetTeamCollection().GetTeams()
        
        #Get All Fortnite Characters Crouch Events and send signal     
        AllFortniteCharacters:[]fort_character = GetAllFortniteCharacters()
        for (FortniteCharacter: AllFortniteCharacters): 
                FortniteCharacter.CrouchedEvent().Subscribe(PlayerCrouched)
      

    # Get an array of all the fort_character objects on an island
    GetAllFortniteCharacters():[]fort_character=
        AllPlayers:[]player = GetPlayspace().GetPlayers()
        for (Player : AllPlayers, Character := Player.GetFortCharacter[]):
            Character

Right now I’m getting ALL players from all teams and an array of all teams but I don’t know how to link them and get only the players from Team 4 and send the CrouchedEvent

Use GetAgents function. GetAgents function

How do I specify I want the agents from Team 4? ?

var Team4 : team = GetPlayspace().GetTeamCollection().GetTeams()[3]

And then iterate all players and test:

GetPlayspace().GetTeamCollection().IsOnTeam[Agent, Team4]

Something like:

var MaybeTeam4 : ?team = option{GetPlayspace().GetTeamCollection().GetTeams()[3]}

    if (ValidTeam4 := MaybeTeam4?):
    for (Player : GetPlayspace().GetPlayers()):
        MaybeFortCharacter : ?fort_character = option{Player.GetFortCharacter[]}
            if (ValidFortCharacter := MaybeFortCharacter?):
                MaybeAgent : ?agent = option{ValidFortCharacter.GetAgent[]}
                if (ValidAgent := MaybeAgent?):
                   if (GetPlayspace().GetTeamCollection().IsOnTeam[ValidAgent , ValidTeam4]): 
                       # Player is on Team4
1 Like

I saw an example in the Team Elimination Game tutorial where you create a hashmap and loop through each team and store the players for each particular team to its own hashmap. I think in this case, you could create an array of players for each team and then set that array on a hashmap with “1” as the key for team one, etc.

     Print("Beginning to populate players")
     for (Team : Teams, TeamPlayers := GetPlayspace().GetTeamCollection().GetAgents[Team]):
         var PlayerMap : player_map = map {}
         for (Agent : TeamPlayers, TeamPlayer := player[Agent], FortCharacter := Agent.GetFortCharacter[]): 
             if(set PlayerMap[TeamPlayer] = 0, WeaponTier := PlayerMap[TeamPlayer]): 
                 Print("Assigned Player to PlayerMap with Tier {WeaponTier}")
             FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) 
2 Likes

Thank you for your help ! I would like to pick a random player in a specific team (for ex Team1) only after player of Team 2 has been eliminated. So i’m trying to mix shuffle function with that but i have an error about type…

Let’s see my code function :

                OnPlayerEliminated2(Player : agent) : void =
                     set Teams = GetPlayspace().GetTeamCollection().GetTeams()
                    var MaybeTeam1 : ?team = option{GetPlayspace().GetTeamCollection().GetTeams()[0]}

                    if (ValidTeam1 := MaybeTeam1?):
                        for (Player_ : GetPlayspace().GetPlayers()):
                            MaybeFortCharacter : ?fort_character = option{Player_.GetFortCharacter[]}
                            if (ValidFortCharacter := MaybeFortCharacter?):
                                MaybeAgent : ?agent = option{ValidFortCharacter.GetAgent[]}
                                if (ValidAgent := MaybeAgent?):
                                   if (GetPlayspace().GetTeamCollection().IsOnTeam[ValidAgent , ValidTeam1]):
                                    ShuffledPlayers := Shuffle(ValidTeam1)  # Mélanger les agents
                                    if (FirstAgent : agent = ShuffledPlayers[0]):  # Sélectionner le premier agent mélangé
                                        if (FortniteCharacter : fort_character = FirstAgent.GetFortCharacter[]):  # Procéder avec le caractère Fortnite
                                            TeleportDropR3_1.Teleport(Player)
                                            TeamChanger4.ChangeTeam(Player)

And here is the error : This function parameter expects a value of type []any, but this argument is an incompatible value of type team. on the line

ShuffledPlayers := Shuffle(ValidTeam1)

I’m so confused about that…