Jump to content

Team Functions


Recommended Posts

what if teams keep changeing ?

function balanceTeams ( thePlayer ) 
    local Team1 = getTeamFromName () 
    local Team2 = getTeamFromName () 
    local Count1 = countPlayersInTeam () 
    local Count2 = countPlayersInTeam () 
    if Count1 == Count2 then 
        setPlayerTeam ( thePlayer , Team1 ) 
    elseif Count1 > Count2 then 
        setPlayerTeam ( thePlayer , Team2 ) 
    elseif Count1 < Count2 then 
        setPlayerTeam ( thePlayer , Team2 ) 
    end 
  

Link to comment

Well, I guess you have defined the team when you create them, like this:

team1 = createTeam("Test 1", 255, 255, 255) 
team2 = createTeam("Test 2", 255, 255, 255) 
  
function balanceTeams ( thePlayer ) 
    local Count1 = countPlayersInTeam (team1) 
    local Count2 = countPlayersInTeam (team2) 
    if (Count1 == Count2) then 
        setPlayerTeam ( thePlayer, team1 ) 
    elseif (Count1 > Count2) then 
        setPlayerTeam ( thePlayer, team2 ) 
    elseif (Count1 < Count2) then 
        setPlayerTeam ( thePlayer, team2 ) 
    end 
end 

Link to comment

Like This ?

local teams = getElementsByType("team") 
for i,team in ipairs(teams) do 
   local teamName = getTeamName(teams) 
   function balanceTeams ( thePlayer ) 
    local Count1 = countPlayersInTeam (teamName) 
    local Count2 = countPlayersInTeam (teamName) 
    if (Count1 == Count2) then 
        setPlayerTeam ( thePlayer, teamName ) 
    elseif (Count1 > Count2) then 
        setPlayerTeam ( thePlayer, teamName ) 
    elseif (Count1 < Count2) then 
        setPlayerTeam ( thePlayer, teamName ) 
    end 
end 
end 

Link to comment

Wrong.

Comments here:

  
local teams = getElementsByType("team") 
for i,team in ipairs(teams) do -- Ok you loop all teams 
   local teamName = getTeamName(teams) -- why? Variable teams is table  
   function balanceTeams ( thePlayer ) -- You create function in loop? Why?  
    local Count1 = countPlayersInTeam (teamName) -- false, because getTeamName return false 
    local Count2 = countPlayersInTeam (teamName) -- false, because getTeamName return false 
    if (Count1 == Count2) then -- All wrong next. 
        setPlayerTeam ( thePlayer, teamName ) 
    elseif (Count1 > Count2) then 
        setPlayerTeam ( thePlayer, teamName ) 
    elseif (Count1 < Count2) then 
        setPlayerTeam ( thePlayer, teamName ) 
    end 
end 
end 
  
--[[  
    You need tabulate your code. 
]] 
  

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...