Jump to content

Team Functions


Recommended Posts

Posted

Hi all i want to Make script Team ballance if team 1 = 10 players i write /b the teams well be team 1 = 5

team 2 = 5

i want the script automauicy get teams Name what ever they are !

can some one give me the functions and events i need to make this script ?

:D

Posted

You want to make a script which will check the players in each team and output the names with players to chat?

If so:

addCommandHandler 
getTeamFromName 
countPlayersInTeam 

Posted

i want script check the teams if team 1 = team 2 count then play the map else

make teams the same team 1 = 5 players team 2 = 5 players and play the Map !

Posted

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 
  

Posted

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 

Posted

You can use this:

for index, team in ipairs(getElementsByType"team") do -- Loop through all server teams. 
     -- Do something. 
end 

Posted

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 

Posted

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

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