Jump to content

some Help in Teams :(


^Dev-PoinT^

Recommended Posts

no thing and debguscript nothing To how about use getElementByType (team)?

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 ) 
         ouputChatBox ( "teamBlue: ".. tostring ( teamBlue ).. "; teamRed: ".. tostring ( teamRed) ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement ( ), balanceTeams ) 

Link to comment
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 ) 
         outputChatBox ( "teamBlue: ".. tostring ( teamBlue ).. "; teamRed: ".. tostring ( teamRed) ) -- You had ouputChatBox 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement ( ), balanceTeams ) 

Link to comment
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 
    else 
            setPlayerTeam ( source , teamRed ) 
    end 
outputChatBox ( "You've been moved to the "..getTeamName (getPlayerTeam(source)):lower ().." team!", source ) 
end 
addEventHandler ("onPlayerJoin", root, balanceTeams) 

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

Link to comment

Your script may have some bugs if you restart it with players playing at the time. To prevent it, use this code, please.

teamRed = createTeam ( "Red", 255, 0, 0 ) 
teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
  
function balanceTeams ( player ) 
    if source then player = source end 
    local RedCount = countPlayersInTeam(teamRed) 
    local BlueCount = countPlayersInTeam(teamBlue) 
    if RedCount ~= BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( player, teamBlue ) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( player, teamRed ) 
         end 
    else 
            setPlayerTeam ( player, teamRed ) 
    end 
outputChatBox ( "You've been moved to the "..getTeamName (getPlayerTeam(player)):lower ().." team!", player ) 
end 
addEventHandler ("onPlayerJoin", root, balanceTeams) 
  
for i, v in ipairs ( getElementsByType ( "player" ) ) do balanceTeams ( v ) 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...