Hello ! I would like to pick a random player in a specific team (for ex Team1) only after player of Team 2 has been eliminated by a creature/non-agent. 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]} #Check if Team1
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) # Shuffle agents
if (FirstAgent : agent = ShuffledPlayers[0]): # Select first shuffled plyer
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
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!
Thank you for your help !
Unfortunately your code doesn’t return an agent that has been eliminated by a creature, or i don’t understand it du to my low experience…
I think I need to explain more concretely what I want to do:
Players from Team 1 are in a special arena where they will face zombies, while players from Team 2 (who will be outside the arena) will have to eliminate the players from Team 1.
I already have a function that does what I want when a player from Team 1 is eliminated by a player from Team 2.
However, I can’t seem to write a function that does “my thing” when a player from Team 1 is eliminated by a zombie…
I’m not even sure if it’s possible to do that…
I hope this makes things a bit clearer to understand. I realize that my request might seem a bit far-fetched at first glance lol.
Thanks for explaining again, actually I noticed, this is why I told you that your function did not filter out creatures, can you tell me, where do you Subscribe the OnPlayerEliminated2 function ?
Ok so, can you set your elimination device “Target Type” to Players Only and the Selected Team Index to 1 as you said the team 1 players will face zombies. Then try with this code :
EliminationManager1.EliminationEvent.Subscribe(OnPlayerElimination) # replace the old line
OnPlayerElimination(Eliminator: ?agent) : void =
TeamCollection := GetPlayspace().GetTeamCollection()
if(
not player[Eliminator?],
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
I also tried this function on a damage volume device by removing boolean condition (“eliminator?”) and activated “Self elimination” on the elimination manager.
OnPlayerFall(Player_ : agent) : void =
TeamCollection := GetPlayspace().GetTeamCollection()
if(
Team2 := GetPlayspace().GetTeamCollection().GetTeams()[0],
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?):
TeleportDropR3_1.Teleport(SelectedPlayer)
Still not working
Maybe i did something wrong… your code seems to be absolutely clear and relevant to face my problem… but nothing is happening when i’m trying to trigger the current event.
I did what you said with your function on the elimination device but nothing is printing, the function seems to be not called…
However, i used the modified function for damage volume and it works for print but not for teleporting each print is shown 4 times in a row as i can see on the log.
So the function is called.
(Sorry for using french on my prints lol)
EDIT : It works fine with the function on damage volume ! I had to change team AND class because the teleporter is allowing only specific team and class. So my problem is resolved.