# How To Get fort\_character from a Specific Team

**URL:** <https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 28, 2023, 6:47pm UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633 "2023-03-28T18:47:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YouTube\_Giova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@YouTube\_Giova](https://forums.unrealengine.com/u/YouTube_Giova)\
**Post date:** [March 28, 2023, 6:47pm UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/1 "2023-03-28T18:47:38Z")

</div>

Hello! I’m trying to figure out how to get the fort\_character from the Team 4

```auto
    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

---

<div class="post-metadata">

**Author:** ![TritonSailor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TritonSailor](https://forums.unrealengine.com/u/TritonSailor)\
**Post date:** [March 28, 2023, 7:14pm UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/2 "2023-03-28T19:14:41Z")

</div>

Use GetAgents function. [GetAgents function](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/teams/fort_team_collection/getagents)

---

<div class="post-metadata">

**Author:** ![YouTube\_Giova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@YouTube\_Giova](https://forums.unrealengine.com/u/YouTube_Giova)\
**Post date:** [March 28, 2023, 7:19pm UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/4 "2023-03-28T19:19:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Patothief](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Patothief](https://forums.unrealengine.com/u/Patothief)\
**Post date:** [March 29, 2023, 8:30am UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/5 "2023-03-29T08:30:08Z")

</div>

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

And then iterate all players and test:

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

Something like:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![KingJArthur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kingjarthur/32/639252_2.png) [@KingJArthur](https://forums.unrealengine.com/u/KingJArthur)\
**Post date:** [March 29, 2023, 11:41am UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/6 "2023-03-29T11:41:19Z")

</div>

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.

```auto
     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) 

```

---

<div class="post-metadata">

**Author:** ![UNREG](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/unreg/32/740541_2.png) [@UNREG](https://forums.unrealengine.com/u/UNREG)\
**Post date:** [September 3, 2023, 9:56pm UTC](https://forums.unrealengine.com/t/how-to-get-fort-character-from-a-specific-team/830633/7 "2023-09-03T21:56:30Z")

</div>

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 :

```auto
                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

```auto
ShuffledPlayers := Shuffle(ValidTeam1)

```

I’m so confused about that…
