Improved code:
teamRed = createTeam ( "Red", 255, 0, 0 )
teamBlue = createTeam ( "Blue", 0, 0, 255 )
function balanceTeams ( )
local RedCount = countPlayersInTeam ( teamBlue )
local BlueCount = countPlayersInTeam ( teamRed )
if RedCount ~= BlueCount then
if RedCount > BlueCount then
setPlayerTeam ( source , teamBlue )
elseif RedCount < BlueCount then
setPlayerTeam ( source , teamRed )
end
outputChatBox ( "You've been moved to the "..getTeamName ( getPlayerTeam ( source ) ):lower ( ).." team!", source )
end
end
addEventHandler ( "onPlayerJoin", getRootElement ( ), balanceTeams )