For context, I’m making a game of Tag that eliminates the “IT” team when they run out of time, and then selects a handful of players to be IT for the next round.
Is there any way to make the game randomly select a player to be moved to Team 1 when a 3 second timer runs out? (the IT team)
Oh, and I want the amount of players IT to be less players as the game goes on, eventually being 1-2 people IT. (32 players max are allowed in game)
Thanks! (and if theres any reference tools for this, do let me know where to find them)
A good way to do this using verse is to use GetPlayspace().GetTeamCollection().AddToTeam[:agent, :team] and GetRandomInt(:int, :int). Here is an example on how to use it:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# A Verse-authored creative device that can be placed in a level
Team_manager := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
AllPlayers:= GetPlayspace().GetPlayers() # Collect players available in the map
TeamCollection:= GetPlayspace().GetTeamCollection() # Collect the team collection
ActiveTeams:= TeamCollection.GetTeams() # Collect active teams in the map
if (
Index:= GetRandomInt(0, AllPlayers.Length-1) # Select random number in range of total players
RandomPlayer:= AllPlayers[Index] # The randomly selected player
TeamCollection.AddToTeam[RandomPlayer, ActiveTeams[1]] # Add the randomly selected player to the desired team (team 2 in this case)
):
Print("Player added successfully!")
It is worth mentioning that you should modify the max teams in your map to be able to add the player to the team you want. Otherwise if you added the player to a team out of the maximum teams it will fail
Now, is there any way to make the players switch to Team 1 (the IT team) if they are tagged, and the player that tagged them switch to Team 2 (runners).
Using damage_result and .DamagedEvent() might help doing this. check this quick code I wrote on how to use them
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
# A Verse-authored creative device that can be placed in a level
Manager := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
AllPlayers:= GetPlayspace().GetPlayers()
TeamCollection:= GetPlayspace().GetTeamCollection()
ActiveTeams:= TeamCollection.GetTeams()
for (Player: AllPlayers, FortChar:= Player.GetFortCharacter[]):
FortChar.DamagedEvent().Subscribe(TagPlayer) # Assign event to all players
TagPlayer(result: damage_result): void=
AllPlayers:= GetPlayspace().GetPlayers()
TeamCollection:= GetPlayspace().GetTeamCollection()
ActiveTeams:= TeamCollection.GetTeams()
if (
Tagger:= fort_character[result.Source?].GetAgent[] # Get the tagger (The one who caused damage)
Tagged:= fort_character[result.Target].GetAgent[] # Get the tagged player (The one who got damaged)
TeamCollection.AddToTeam[Tagged, ActiveTeams[0]] # Add tagged player to the desired team
TeamCollection.AddToTeam[Tagger, ActiveTeams[1]] # Add tagger player to the desired team
):
Print("Player was added to the team successfully!")
Here, ActiveTeams[0] is team 1 and ActiveTeam[1] is team 2. From there you could change the index to what you are looking for and TeamCollection.AddToTeam[] is what will change the player’s team. If comparing teams is needed by somehow, use TeamCollection.GetTeam[:agent] to get the team of the agent. That will return value of data type team that can be used to compare with any team in ActiveTeams array