Team autobalance

how would one go about making a simple auto balance system, this is as far as I got , trying to get back into LUA and could use some assistance, thanks for the help!

function teamBalance()
if ply:Team(1) > ply:Team(2) then



Use a parameter for that function in which you pass on “ply”, otherwise it has no reference to the player.

Then use team.NumPlayers( TeamIndex ) and compare number of players between teams to determine where to place the player.

Obviously this is extremely simplified, but for your purposes, possibly assign the player to the team on spawn.

alright thank you, I’ll get right on it!

If you are wondering about the logic behind balancing teams, you need to come up with some sort of per player scoring system, frags alone may not be enough.

But what you’d do is combine frags/score of one team and combine frags/score of the other one ( sum of all frags/scores ). This will tell you which team is “more powerful”.

Once the “overpowered” team is identified what you’d do is take 1 player from the winning team and add their score to the score of the losing team and subtract it from the score of the winning team.

Do that for every player and select the player who would make the two sums as close as possible.