Pick random player of Team1 after a player of Team2 is eliminated by creature...

Wow dude, so first of all, too many indents, meaning that there’s a problem with your code.

Secondly, I’m not sure where the OnPlayerEliminated2() function is called from, but it returns an agent which doesn’t mean it’s a creature, because players are agents too.

From what I understood, I think this should do it :

    OnPlayerEliminated2(Agent: agent) : void =
        TeamCollection := GetPlayspace().GetTeamCollection()

        if(
            EliminatedPlayer := player[Agent],
            Team1 := GetPlayspace().GetTeamCollection().GetTeams()[0],
            TeamCollection.IsOnTeam[EliminatedPlayer, Team1],
            Team2 := GetPlayspace().GetTeamCollection().GetTeams()[1],
            Team2Agents := TeamCollection.GetAgents[Team2],
            ShuffledAgents := Shuffle(Team2Agents)
        ):

            # Will store the first alive player into SelectedPlayerMaybe
            var SelectedPlayerMaybe : ?player = false
            for(Team2Agent : ShuffledAgents, not SelectedPlayerMaybe?, Player := player[Team2Agent], Player.GetFortCharacter[].IsActive[]):
                set SelectedPlayerMaybe = option{Player}

            if(SelectedPlayer := SelectedPlayerMaybe?):
                # Do your thing

So I added an alive check at the end, but if you don’t need it, you can just use ShuffledAgents[0].

Also, the TeamCollection.GetAgents[] method seem to return a list of agent, this could also contain guards/wildlife. I’m not sure but maybe double check if you have some in your map!

Tell me if it works :slight_smile:

1 Like