Jump to content

Making the teams even?


Xeno

Recommended Posts

So say I had two teams, how would I even out the number of players on each one onPlayerJoin?

team1 = createTeam("Team1", 255,255,255) 
team2 = createTeam("Team 2",0,255,255) 
  
function onPlayerJoin() 
  
end 
addEventHandler("onPlayerJoin", ect ect... 

I would appreciate it if you could help me.

Link to comment
team1 = createTeam("Team1", 255,255,255) 
team2 = createTeam("Team 2",0,255,255) 
  
function onPlayerJoin() 
     outputChatBox("Team 1 has: ".. tostring(countPlayersInTeam(team1)) .." players.", source) 
     outputChatBox("Team 2 has: ".. tostring(countPlayersInTeam(team2)) .." players.", source, 0,255,255) 
end 
addEventHandler("onPlayerJoin", root, onPlayerJoin) 

Link to comment
team1 = createTeam("Team1", 255,255,255) 
team2 = createTeam("Team 2",0,255,255) 
  
function onPlayerJoin() 
     outputChatBox("Team 1 has: ".. tostring(countPlayersInTeam(team1)) .." players.", source) 
     outputChatBox("Team 2 has: ".. tostring(countPlayersInTeam(team2)) .." players.", source, 0,255,255) 
end 
addEventHandler("onPlayerJoin", root, onPlayerJoin) 

No no, not like that. I mean, say if I had 4 players on one team, and 5 on another, a new player would be put in the team with 4 players in, and not 5, to even out the number of players on each team.

Link to comment
Use a comparison between the players in team A and the players of team B.
countPlayersInTeam 

So something like on the wiki page?

function balanceTeams ( thePlayer ) 
    --get the team pointers from their names 
    local groveTeam = getTeamFromName ( "grove" ) 
    local ballasTeam = getTeamFromName ( "ballas" ) 
    --count the number of players in each team, and store them 
    local groveCount = countPlayersInTeam ( groveTeam ) 
    local ballasCount = countPlayersInTeam ( ballasTeam ) 
    if groveCount == ballasCount then --if the teams are equal 
        setPlayerTeam ( thePlayer , groveTeam ) --place the player in grove 
    elseif groveCount > ballasCount then --if there are more in grove 
        setPlayerTeam ( thePlayer , ballasTeam ) --place him in ballas 
    elseif groveCount < ballasCount then --if there are more in ballas 
        setPlayerTeam ( thePlayer , groveTeam ) --place him in grove. 
    end 
end 

??

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...