Hello, i tried really hard and watched tutorial for hours but am still a beginner and I don’t find a way to get the team of the eliminating player.
Can you please help me?
This is my code so far:
AllPlayers := GetPlayspace().GetPlayers()
for (EliminationGamePlayer : AllPlayers):
if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
# Subscribe to character eliminated event.
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)
OnPlayerEliminated(Result:elimination_result):void=
Print("One player has been killed")
EliminatingCharacter := Result.EliminatingCharacter
if:
FortCharacter := EliminatingCharacter?
EliminatingAgent := FortCharacter.GetAgent[]
then:
Print("We have the agent")
>>>> Get the team index of the Eliminating Player.
Bonus: I am also looking to know the size of each team. (in my game there will only be only two teams) Thank youuu !
For the teams i’d like to get a function that i call anytime and gives me the number of players in team 1 & 2.
Something like:
FORTNITE_GAME := class(creative_device):
var NumberPlayersTeam1 : int = 0
var NumberPlayersTeam2 : int = 0
OnBegin<override>()<suspends>:void=
StartMap()
UpdateNumberOfPlayersInTeam1and2() #it's a game with only 2 teams
UpdateNumberOfPlayersInTeam1and2() : void =
#Something here that update the two vars with the number of players in each teams.
set NumberPlayersTeam1 := something
set NumberPlayersTeam2 := something
I tried the following but it doesn’t work:
UpdateNumberOfPlayersInTeam1and2()<decides>: void =
var TheMaybeTeam1 : ?team = option{GetPlayspace().GetTeamCollection().GetTeams()[0]}
var TheMaybeTeam2 : ?team = option{GetPlayspace().GetTeamCollection().GetTeams()[1]}
# Getting the value out
if(Team1 := TheMaybeTeam1?):
set NumberPlayerTeam1 = GetPlayspace().GetTeamCollection().GetAgents[Team1].Length
Print("The number of players in Team 1 is: {NumberPlayerTeam1}")
if(Team2 := TheMaybeTeam2?):
set NumberPlayerTeam2 = GetPlayspace().GetTeamCollection().GetAgents[Team2].Length
Print("The number of players in Team 2 is: {NumberPlayerTeam2}")
var NumberPlayersTeam1 : int = 0
var NumberPlayersTeam2 : int = 0
OnBegin<override>()<suspends>:void=
UpdateNumberOfPlayers()
UpdateNumberOfPlayers(): void=
TeamCollection := GetPlayspace().GetTeamCollection()
if (
Team1 := TeamCollection.GetTeams()[0]
set NumberPlayersTeam1 = TeamCollection.GetAgents[Team1].Length
Team2 := TeamCollection.GetTeams()[1]
set NumberPlayersTeam2 = TeamCollection.GetAgents[Team1].Length
):
return
This will work only if you do not use specifiers that have rollback. Team 2 will only be updated occasionally because only one team can be on the map at a time. Just change the logic to what you want.
Great question and responses here! I’d also recommend checking out the Team Elimination Game tutorial which shows how to use the team APIs and handle player elimination and spawning as well.