Balancing Players in Triad Infiltration
When a new player joins the game, they need to be balanced asymmetrically onto the right team. If that team happens to be the Infiltrators, they also need to have an instance of OnInfiltratorDamaged() associated with them.
Follow the steps below to learn how to balance players to the correct team when they join the game in progress.
Setting Up Player Join Functions
- Add a new function,
OnInfiltratorJoined(), to theinvisibility_managerclass definition. This function takes an agent and spawns an instance ofOnInfiltratorDamaged()with the given agent. Add the<public>specifier to this function, since you'll be calling it fromtriad_infiltration_game.# Spawns an OnInfiltratorDamaged function when a new infiltrator joins the game OnInfiltratorJoined<public>(InAgent:agent):void= spawn{OnInfiltratorDamaged(InAgent)} - Add a new function
OnPlayerAdded()to thetriad_infiltration_gameclass definition. This function takes a player, balances them to the correct team, and callsOnInfiltratorJoined()if the new player is an Infiltrator.# Handles a new player joining the game. OnPlayerAdded(InPlayer:player):void= - Get the
fort_team_collectionfor the current playspace and save it in a variableFortTeamCollection.# Handles a new player joining the game. OnPlayerAdded(InPlayer:player):void= Logger.Print("A new Player joined, assigning them to a team") FortTeamCollection := GetPlayspace().GetTeamCollection()Refactoring Team Balancing - You need to balance the new player onto the correct team, but if you call
BalanceTeams()you'll end up rearranging every player onto a new team. Instead of rewriting the code for finding the smallest team for the new player and balancing them onto it, this is a good opportunity for refactoring.
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.