This script can be used to set players to teams, useful for game types like one against many (for example.) This loops around in order, but should cope with players joining or leaving, although there are some events that you can call here to add your own logic.
Installing
- Go to the community tab and search “Team balancing with bias"
- Install the package
- Drag the script onto any object in your level e.g. a locator
Details
I have included a function called ForcedRefresh() which you could hook in to the playerQuitEvent this will force the teams to be recalculated but won’t change the order of whoever is going to be replaced on the next round. You may also want to do other things with this event, like showing a message that you’re rebalancing teams. I’ve also made it so it passes the user who left, so you could send a message with the player who quits name.
I have included events onTeamOne and onTeamTwo, this can be used to call another function or script. This would be useful if you had a new script with a function that assigned a specific player template to a team. These pass the player and the team they are on as variables, this could be useful for another function.
Properties
There are the following properties for the teamBalance script:
teamBias = By default this is set to 1 which is perfect for standard PVP teams. If you adjust this to 3 then this will create a 3 Vs 1 match. You could them limit your games max players to 4 to make 1 Vs 4 match.
playerQuitEvent = Can be used to trigger something if a player leaves, passes the player who left.
roundDismissed = Can be used to trigger something if not enough players are in the game
onTeamOne = Event will pass the player and the team they are on.