Jump to content

setNametagcolor


DarkLink

Recommended Posts

Okay this is a function to put a color on a name of a player right?

I added this to my script just for test:

  
function nametagColorChange ( thePlayer, commandName, r, g, b ) 
    -- Apply the new color mix of RGB to the command handler activator 
    setPlayerNametagColor ( thePlayer, r, g, b ) 
end 
-- This is a command handler that activates on text "nametagcolor" in the console. It also asks  
-- the player to provide values for the extra parameters r, g, b after the command name. These will  
-- be the new color mix of RGB to apply to the player's name tag. 
addCommandHandler ( "nametagcolor", nametagColorChange ) 
  

and then I get error on server console saying that its a bad argument, and I dont see my color get changed.. keeps white.

thanks guys :)

Link to comment
function nametagColorChange ( thePlayer, commandName, r, g, b ) 
    -- Apply the new color mix of RGB to the command handler activator 
    setPlayerNametagColor ( thePlayer, tonumber(r), tonumber(g), tonumber(b) ) 
end 
-- This is a command handler that activates on text "nametagcolor" in the console. It also asks 
-- the player to provide values for the extra parameters r, g, b after the command name. These will 
-- be the new color mix of RGB to apply to the player's name tag. 
addCommandHandler ( "nametagcolor", nametagColorChange ) 

Try that.

Edited by Guest
Link to comment

thanks both. I already tryed that quaispj , didnt work too :S

Maybe your game mode is messing with this?

Well I have using the function setTeamColor, it sets for all the team members, but I am using setNametagcolor before the setTeamColor, so no problem I guess..

Thanks guys!

Instead of using the tostring.. use tonumber

Tryed your solution now again, and now I have bad argument on fuction setPlayerNametagColor.

Bahh, thePlayer is fine I guess..

Thanks guys.

Edited by Guest
Link to comment
Use nametag color after the team color.

offtopic-And people would normally say quaisjp, but quaispj? LMFAO, just call be quisBJ lmao.

Bahh stil not working, tonumber fives me bad argument, changed to tostring, no error, but no color changed :S

I keep talking on char and my name didnt change color :S

What the hell..?

offtopic- ROFL! Aahah I am sorry bro xD my mistake quisBJ, was late xD

Link to comment
function nametagColorChange ( thePlayer, commandName, r, g, b ) 
    -- Apply the new color mix of RGB to the command handler activator 
    setPlayerNametagColor ( thePlayer, tonumber(r), tonumber(g), tonumber(b) ) 
end 
-- This is a command handler that activates on text "nametagcolor" in the console. It also asks 
-- the player to provide values for the extra parameters r, g, b after the command name. These will 
-- be the new color mix of RGB to apply to the player's name tag. 
addCommandHandler ( "nametagcolor", nametagColorChange ) 

Try that.

Can't help more than Solidsnake did.

This should work and if it doesn't then something is wrong elsewhere in your script.

Link to comment
function nametagColorChange ( thePlayer, commandName, r, g, b ) 
    -- Apply the new color mix of RGB to the command handler activator 
    setPlayerNametagColor ( thePlayer, tonumber(r), tonumber(g), tonumber(b) ) 
end 
-- This is a command handler that activates on text "nametagcolor" in the console. It also asks 
-- the player to provide values for the extra parameters r, g, b after the command name. These will 
-- be the new color mix of RGB to apply to the player's name tag. 
addCommandHandler ( "nametagcolor", nametagColorChange ) 

Try that.

Can't help more than Solidsnake did.

This should work and if it doesn't then something is wrong elsewhere in your script.

Hm thanks bro.

When a color is setted to a team using setTeamColor, this function doesnt work?

Link to comment
Try to remove team color code and test without it.

didnt work bro, I tested on another resource and the function is working perfect..

I dont know where is the problem when I add it to my script :S

What might block this function? do you know? thanks.

Link to comment
Well, in that case, i'm positive that the problem is in the resource not the function.

Post all the script then.

Really? But all the files that I use for the resource? They are already many :S

If you have any guess of which problems can make this function not to work, I can search on the script.

Thanks jacob :)

Link to comment
Just the script file, that contains the command.

lol its so much jacob xD

400 lines lol

the command handler is the function called by onplayerjoin event

  
local skinsForEMI = {183,158,159,160,162,132,136}
 
 
addEvent("buttonClicked",true)
gamemodeStarted = false
playersForIMI = {}
playersForPOL = {}
 
 
function setcolor(playerSource)
    outputChatBox("cona")
 
 
  setPlayerNametagColor(playerSource, 255, 10, 40)
end
 
 
 
function joinHandler(equipa)
    if (gamemodeStarted == false) then
   
   
       
        if(equipa == 'imigrante') then
            table.insert(playersForIMI, source)
            --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63))
        elseif(equipa == 'police') then
            table.insert(playersForPOL, source)
            --setPlayerNametagColor(source, 30, 144, 255)
        else
       
            local numberOfTeam = math.random(2)
           
            if numberOfTeam == 1 then
                table.insert(playersForIMI, source)
            else
                table.insert(playersForPOL, source)
            end
       
       
        end
    end
end
addEventHandler("buttonClicked", root, joinHandler)
 
 
function playerJoin ()
 
   
    local name = getPlayerName(source)
 
    for i, v in ipairs(getElementsByType("player")) do
        if (v ~= source) then
            outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64)
            addCommandHandler("nametagcolor", setcolor)
        end
    end
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin )
 
 
 
function destroyBlipsWhenPlayerLeavesServer ( quitType)
 
    local name = getPlayerName(source)
   
   
    outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64)
   
   
   
   
    if source then
        local attacheds = getAttachedElements ( source )
        if ( attacheds ) then
            for k,element in ipairs(attacheds) do
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer )
 
 
 
function colocarDeNoite ()
    setTime ( 1, 0)
    --setWeather ( 22 )
   
   
end
addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite)
 
 
 
 
 
 
 
 
    segundos = 30
    timerEnabled = false
    gamemodeStarted = false
    local mostrou = false
     
     addEvent("checkTwoPlayersOnMode", true)
     function checkTwoAndNotStartedRunIT ()
     
        if gamemodeStarted == false then
            if timerEnabled == false then
                if(getPlayerCount() >= 1) then
                    setTimer(escreve, 200, 1)
                    triggerClientEvent("canShowGUISPAWN",getRootElement())
                   
                    mostrou = true
                else
                    outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source)
                end
            else
                setElementData(source,"secondsRemaining",tostring(segundos))
                triggerClientEvent ( source, "showDX", source )
                triggerClientEvent(source,"canShowGUISPAWN",source)
            end
       
        else
            outputChatBox("You will need to wait the gamemode to finish, sorry", source)
        end
     
     
     end
     addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT)
     
     
     
     
     
 
     
    function escreve ()
        timerEnabled = true
        for i,v in pairs(getElementsByType("player")) do
            setElementData(v,"secondsRemaining",tostring(segundos))
            triggerClientEvent ( v, "showDX", v )
            if(mostrou ~= true) then
                triggerClientEvent(v,"canShowGUISPAWN",v)
            end
        end
        setTimer(countDown,1000,30)
    end
   
     
    function countDown()
        segundos = segundos -1
            for i,v in pairs(getElementsByType("player")) do
                setElementData(v,"secondsRemaining",tostring(segundos))
            end
           
            if segundos == 3 then
                triggerClientEvent("hadChosenTeam", getRootElement())
            end
           
            if segundos == 0 then
               
                triggerClientEvent ( "hideDX", getRootElement() )
                triggerClientEvent("hideSpawnGUI", getRootElement())
               
                timerEnabled = false
                gamemodeStarted = true
               
                if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then
                    spawn()
                else
                    outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64)
                    autobalance()
                   
                end
            end
    end
     
    function onStart ()
            timerEnabled = false
            if(getPlayerCount() >= 2) then
                removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT )
                setTimer(escreve, 1500, 1)
            end
    end
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart )
   
   
    function autobalance()
        if(#playersForIMI - #playersForPOL >= 2) then
            local sync = false
            local dif = #playersForIMI - #playersForPOL
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL + 1) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
            end
           
        elseif(#playersForPOL - #playersForIMI >= 2) then
            local sync = false
            local dif = #playersForPOL - #playersForIMI
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                        setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI + 1) then
                       
Link to comment

Why you are doing addCommandHandler inside onPlayerJoin.

here try this: (not sure it will make a diffrence at all)

local skinsForEMI = {183,158,159,160,162,132,136} 
 
addEvent("buttonClicked",true)
gamemodeStarted = false
playersForIMI = {}
playersForPOL = {}
 
 
function setcolor(playerSource)
    outputChatBox("cona")
 
 
  setPlayerNametagColor(playerSource, 255, 10, 40)
end
  addCommandHandler("nametagcolor", setcolor)
 
 
function joinHandler(equipa)
    if (gamemodeStarted == false) then
   
   
       
        if(equipa == 'imigrante') then
            table.insert(playersForIMI, source)
            --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63))
        elseif(equipa == 'police') then
            table.insert(playersForPOL, source)
            --setPlayerNametagColor(source, 30, 144, 255)
        else
       
            local numberOfTeam = math.random(2)
           
            if numberOfTeam == 1 then
                table.insert(playersForIMI, source)
            else
                table.insert(playersForPOL, source)
            end
       
       
        end
    end
end
addEventHandler("buttonClicked", root, joinHandler)
 
 
function playerJoin ()
 
   
    local name = getPlayerName(source)
 
    for i, v in ipairs(getElementsByType("player")) do
        if (v ~= source) then
            outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64)
        end
    end
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin )
 
 
 
function destroyBlipsWhenPlayerLeavesServer ( quitType)
 
    local name = getPlayerName(source)
   
   
    outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64)
   
   
   
   
    if source then
        local attacheds = getAttachedElements ( source )
        if ( attacheds ) then
            for k,element in ipairs(attacheds) do
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer )
 
 
 
function colocarDeNoite ()
    setTime ( 1, 0)
    --setWeather ( 22 )
   
   
end
addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite)
 
 
 
 
 
 
 
 
    segundos = 30
    timerEnabled = false
    gamemodeStarted = false
    local mostrou = false
     
     addEvent("checkTwoPlayersOnMode", true)
     function checkTwoAndNotStartedRunIT ()
     
        if gamemodeStarted == false then
            if timerEnabled == false then
                if(getPlayerCount() >= 1) then
                    setTimer(escreve, 200, 1)
                    triggerClientEvent("canShowGUISPAWN",getRootElement())
                   
                    mostrou = true
                else
                    outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source)
                end
            else
                setElementData(source,"secondsRemaining",tostring(segundos))
                triggerClientEvent ( source, "showDX", source )
                triggerClientEvent(source,"canShowGUISPAWN",source)
            end
       
        else
            outputChatBox("You will need to wait the gamemode to finish, sorry", source)
        end
     
     
     end
     addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT)
     
     
     
     
     
 
     
    function escreve ()
        timerEnabled = true
        for i,v in pairs(getElementsByType("player")) do
            setElementData(v,"secondsRemaining",tostring(segundos))
            triggerClientEvent ( v, "showDX", v )
            if(mostrou ~= true) then
                triggerClientEvent(v,"canShowGUISPAWN",v)
            end
        end
        setTimer(countDown,1000,30)
    end
   
     
    function countDown()
        segundos = segundos -1
            for i,v in pairs(getElementsByType("player")) do
                setElementData(v,"secondsRemaining",tostring(segundos))
            end
           
            if segundos == 3 then
                triggerClientEvent("hadChosenTeam", getRootElement())
            end
           
            if segundos == 0 then
               
                triggerClientEvent ( "hideDX", getRootElement() )
                triggerClientEvent("hideSpawnGUI", getRootElement())
               
                timerEnabled = false
                gamemodeStarted = true
               
                if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then
                    spawn()
                else
                    outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64)
                    autobalance()
                   
                end
            end
    end
     
    function onStart ()
            timerEnabled = false
            if(getPlayerCount() >= 2) then
                removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT )
                setTimer(escreve, 1500, 1)
            end
    end
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart )
   
   
    function autobalance()
        if(#playersForIMI - #playersForPOL >= 2) then
            local sync = false
            local dif = #playersForIMI - #playersForPOL
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL + 1) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
            end
           
        elseif(#playersForPOL - #playersForIMI >= 2) then
            local sync = false
            local dif = #playersForPOL - #playersForIMI
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                        setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI + 1) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                       
Link to comment
Why you are doing addCommandHandler inside onPlayerJoin.

here try this: (not sure it will make a diffrence at all)

local skinsForEMI = {183,158,159,160,162,132,136} 
 
addEvent("buttonClicked",true)
gamemodeStarted = false
playersForIMI = {}
playersForPOL = {}
 
 
function setcolor(playerSource)
    outputChatBox("cona")
 
 
  setPlayerNametagColor(playerSource, 255, 10, 40)
end
  addCommandHandler("nametagcolor", setcolor)
 
 
function joinHandler(equipa)
    if (gamemodeStarted == false) then
   
   
       
        if(equipa == 'imigrante') then
            table.insert(playersForIMI, source)
            --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63))
        elseif(equipa == 'police') then
            table.insert(playersForPOL, source)
            --setPlayerNametagColor(source, 30, 144, 255)
        else
       
            local numberOfTeam = math.random(2)
           
            if numberOfTeam == 1 then
                table.insert(playersForIMI, source)
            else
                table.insert(playersForPOL, source)
            end
       
       
        end
    end
end
addEventHandler("buttonClicked", root, joinHandler)
 
 
function playerJoin ()
 
   
    local name = getPlayerName(source)
 
    for i, v in ipairs(getElementsByType("player")) do
        if (v ~= source) then
            outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64)
        end
    end
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin )
 
 
 
function destroyBlipsWhenPlayerLeavesServer ( quitType)
 
    local name = getPlayerName(source)
   
   
    outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64)
   
   
   
   
    if source then
        local attacheds = getAttachedElements ( source )
        if ( attacheds ) then
            for k,element in ipairs(attacheds) do
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer )
 
 
 
function colocarDeNoite ()
    setTime ( 1, 0)
    --setWeather ( 22 )
   
   
end
addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite)
 
 
 
 
 
 
 
 
    segundos = 30
    timerEnabled = false
    gamemodeStarted = false
    local mostrou = false
     
     addEvent("checkTwoPlayersOnMode", true)
     function checkTwoAndNotStartedRunIT ()
     
        if gamemodeStarted == false then
            if timerEnabled == false then
                if(getPlayerCount() >= 1) then
                    setTimer(escreve, 200, 1)
                    triggerClientEvent("canShowGUISPAWN",getRootElement())
                   
                    mostrou = true
                else
                    outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source)
                end
            else
                setElementData(source,"secondsRemaining",tostring(segundos))
                triggerClientEvent ( source, "showDX", source )
                triggerClientEvent(source,"canShowGUISPAWN",source)
            end
       
        else
            outputChatBox("You will need to wait the gamemode to finish, sorry", source)
        end
     
     
     end
     addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT)
     
     
     
     
     
 
     
    function escreve ()
        timerEnabled = true
        for i,v in pairs(getElementsByType("player")) do
            setElementData(v,"secondsRemaining",tostring(segundos))
            triggerClientEvent ( v, "showDX", v )
            if(mostrou ~= true) then
                triggerClientEvent(v,"canShowGUISPAWN",v)
            end
        end
        setTimer(countDown,1000,30)
    end
   
     
    function countDown()
        segundos = segundos -1
            for i,v in pairs(getElementsByType("player")) do
                setElementData(v,"secondsRemaining",tostring(segundos))
            end
           
            if segundos == 3 then
                triggerClientEvent("hadChosenTeam", getRootElement())
            end
           
            if segundos == 0 then
               
                triggerClientEvent ( "hideDX", getRootElement() )
                triggerClientEvent("hideSpawnGUI", getRootElement())
               
                timerEnabled = false
                gamemodeStarted = true
               
                if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then
                    spawn()
                else
                    outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64)
                    autobalance()
                   
                end
            end
    end
     
    function onStart ()
            timerEnabled = false
            if(getPlayerCount() >= 2) then
                removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT )
                setTimer(escreve, 1500, 1)
            end
    end
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart )
   
   
    function autobalance()
        if(#playersForIMI - #playersForPOL >= 2) then
            local sync = false
            local dif = #playersForIMI - #playersForPOL
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL + 1) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
            end
           
        elseif(#playersForPOL - #playersForIMI >= 2) then
            local sync = false
            local dif = #playersForPOL - #playersForIMI
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                        setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI + 1) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                       
Link to comment

I tested the whole script, and it worked, i don't understand it's not even in the script you posted, because i just tested it and it worked.

Here that's what i tested:

local skinsForEMI = {183,158,159,160,162,132,136} 
 
addEvent("buttonClicked",true)
gamemodeStarted = false
playersForIMI = {}
playersForPOL = {}
 
 
function setcolor(playerSource)
    outputChatBox("cona")
 
 
  setPlayerNametagColor(playerSource, 255, 10, 40)
end
  addCommandHandler("nametagcolor", setcolor)
 
 
function joinHandler(equipa)
    if (gamemodeStarted == false) then
   
   
       
        if(equipa == 'imigrante') then
            table.insert(playersForIMI, source)
            --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63))
        elseif(equipa == 'police') then
            table.insert(playersForPOL, source)
            --setPlayerNametagColor(source, 30, 144, 255)
        else
       
            local numberOfTeam = math.random(2)
           
            if numberOfTeam == 1 then
                table.insert(playersForIMI, source)
            else
                table.insert(playersForPOL, source)
            end
       
       
        end
    end
end
addEventHandler("buttonClicked", root, joinHandler)
 
 
function playerJoin ()
 
   
    local name = getPlayerName(source)
 
    for i, v in ipairs(getElementsByType("player")) do
        if (v ~= source) then
            outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64)
        end
    end
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin )
 
 
 
function destroyBlipsWhenPlayerLeavesServer ( quitType)
 
    local name = getPlayerName(source)
   
   
    outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64)
   
   
   
   
    if source then
        local attacheds = getAttachedElements ( source )
        if ( attacheds ) then
            for k,element in ipairs(attacheds) do
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer )
 
 
 
function colocarDeNoite ()
    setTime ( 1, 0)
    --setWeather ( 22 )
   
   
end
addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite)
 
 
 
 
 
 
 
 
    segundos = 30
    timerEnabled = false
    gamemodeStarted = false
    local mostrou = false
     
     addEvent("checkTwoPlayersOnMode", true)
     function checkTwoAndNotStartedRunIT ()
     
        if gamemodeStarted == false then
            if timerEnabled == false then
                if(getPlayerCount() >= 1) then
                    setTimer(escreve, 200, 1)
                    triggerClientEvent("canShowGUISPAWN",getRootElement())
                   
                    mostrou = true
                else
                    outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source)
                end
            else
                setElementData(source,"secondsRemaining",tostring(segundos))
                triggerClientEvent ( source, "showDX", source )
                triggerClientEvent(source,"canShowGUISPAWN",source)
            end
       
        else
            outputChatBox("You will need to wait the gamemode to finish, sorry", source)
        end
     
     
     end
     addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT)
     
     
     
     
     
 
     
    function escreve ()
        timerEnabled = true
        for i,v in pairs(getElementsByType("player")) do
            setElementData(v,"secondsRemaining",tostring(segundos))
            triggerClientEvent ( v, "showDX", v )
            if(mostrou ~= true) then
                triggerClientEvent(v,"canShowGUISPAWN",v)
            end
        end
        setTimer(countDown,1000,30)
    end
   
     
    function countDown()
        segundos = segundos -1
            for i,v in pairs(getElementsByType("player")) do
                setElementData(v,"secondsRemaining",tostring(segundos))
            end
           
            if segundos == 3 then
                triggerClientEvent("hadChosenTeam", getRootElement())
            end
           
            if segundos == 0 then
               
                triggerClientEvent ( "hideDX", getRootElement() )
                triggerClientEvent("hideSpawnGUI", getRootElement())
               
                timerEnabled = false
                gamemodeStarted = true
               
                if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then
                    spawn()
                else
                    outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64)
                    autobalance()
                   
                end
            end
    end
     
    function onStart ()
            timerEnabled = false
            if(getPlayerCount() >= 2) then
                removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT )
                setTimer(escreve, 1500, 1)
            end
    end
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart )
   
   
    function autobalance()
        if(#playersForIMI - #playersForPOL >= 2) then
            local sync = false
            local dif = #playersForIMI - #playersForPOL
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL + 1) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
            end
           
        elseif(#playersForPOL - #playersForIMI >= 2) then
            local sync = false
            local dif = #playersForPOL - #playersForIMI
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                        setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI + 1) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                       
Link to comment
I tested the whole script, and it worked, i don't understand it's not even in the script you posted, because i just tested it and it worked.

Here that's what i tested:

local skinsForEMI = {183,158,159,160,162,132,136} 
 
addEvent("buttonClicked",true)
gamemodeStarted = false
playersForIMI = {}
playersForPOL = {}
 
 
function setcolor(playerSource)
    outputChatBox("cona")
 
 
  setPlayerNametagColor(playerSource, 255, 10, 40)
end
  addCommandHandler("nametagcolor", setcolor)
 
 
function joinHandler(equipa)
    if (gamemodeStarted == false) then
   
   
       
        if(equipa == 'imigrante') then
            table.insert(playersForIMI, source)
            --setPlayerNametagColor(source, tonumber(205), tonumber(133), tonumber(63))
        elseif(equipa == 'police') then
            table.insert(playersForPOL, source)
            --setPlayerNametagColor(source, 30, 144, 255)
        else
       
            local numberOfTeam = math.random(2)
           
            if numberOfTeam == 1 then
                table.insert(playersForIMI, source)
            else
                table.insert(playersForPOL, source)
            end
       
       
        end
    end
end
addEventHandler("buttonClicked", root, joinHandler)
 
 
function playerJoin ()
 
   
    local name = getPlayerName(source)
 
    for i, v in ipairs(getElementsByType("player")) do
        if (v ~= source) then
            outputChatBox("[" .. name .. "] has joined the server", v, 255, 64, 64)
        end
    end
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin )
 
 
 
function destroyBlipsWhenPlayerLeavesServer ( quitType)
 
    local name = getPlayerName(source)
   
   
    outputChatBox("[" .. name .. "] has left the server [" .. quitType .."]", getRootElement(), 255, 64, 64)
   
   
   
   
    if source then
        local attacheds = getAttachedElements ( source )
        if ( attacheds ) then
            for k,element in ipairs(attacheds) do
                if getElementType ( element ) == "blip" then
                    destroyElement ( element )
                end
            end
        end
    end
end
addEventHandler ( "onPlayerQuit", getRootElement(), destroyBlipsWhenPlayerLeavesServer )
 
 
 
function colocarDeNoite ()
    setTime ( 1, 0)
    --setWeather ( 22 )
   
   
end
addEventHandler ( "onResourceStart", getRootElement(), colocarDeNoite)
 
 
 
 
 
 
 
 
    segundos = 30
    timerEnabled = false
    gamemodeStarted = false
    local mostrou = false
     
     addEvent("checkTwoPlayersOnMode", true)
     function checkTwoAndNotStartedRunIT ()
     
        if gamemodeStarted == false then
            if timerEnabled == false then
                if(getPlayerCount() >= 1) then
                    setTimer(escreve, 200, 1)
                    triggerClientEvent("canShowGUISPAWN",getRootElement())
                   
                    mostrou = true
                else
                    outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source)
                end
            else
                setElementData(source,"secondsRemaining",tostring(segundos))
                triggerClientEvent ( source, "showDX", source )
                triggerClientEvent(source,"canShowGUISPAWN",source)
            end
       
        else
            outputChatBox("You will need to wait the gamemode to finish, sorry", source)
        end
     
     
     end
     addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT)
     
     
     
     
     
 
     
    function escreve ()
        timerEnabled = true
        for i,v in pairs(getElementsByType("player")) do
            setElementData(v,"secondsRemaining",tostring(segundos))
            triggerClientEvent ( v, "showDX", v )
            if(mostrou ~= true) then
                triggerClientEvent(v,"canShowGUISPAWN",v)
            end
        end
        setTimer(countDown,1000,30)
    end
   
     
    function countDown()
        segundos = segundos -1
            for i,v in pairs(getElementsByType("player")) do
                setElementData(v,"secondsRemaining",tostring(segundos))
            end
           
            if segundos == 3 then
                triggerClientEvent("hadChosenTeam", getRootElement())
            end
           
            if segundos == 0 then
               
                triggerClientEvent ( "hideDX", getRootElement() )
                triggerClientEvent("hideSpawnGUI", getRootElement())
               
                timerEnabled = false
                gamemodeStarted = true
               
                if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForPOL + 1 or #playersForPOL == #playersForIMI + 1) then
                    spawn()
                else
                    outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64)
                    autobalance()
                   
                end
            end
    end
     
    function onStart ()
            timerEnabled = false
            if(getPlayerCount() >= 2) then
                removeEventHandler ("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT )
                setTimer(escreve, 1500, 1)
            end
    end
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart )
   
   
    function autobalance()
        if(#playersForIMI - #playersForPOL >= 2) then
            local sync = false
            local dif = #playersForIMI - #playersForPOL
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForIMI ~= #playersForPOL + 1) then
                        table.insert(playersForPOL, playersForIMI[#playersForIMI])
                        table.remove(playersForIMI, #playersForIMI)
                        setPlayerTeam ( playersForPOL[#playersForPOL], team_policeSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForPOL[#playersForPOL], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
            end
           
        elseif(#playersForPOL - #playersForIMI >= 2) then
            local sync = false
            local dif = #playersForPOL - #playersForIMI
           
            if(dif % 2 == 0) then
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                        table.remove(playersForPOL, #playersForPOL)
                        setPlayerTeam ( playersForIMI[#playersForIMI], team_immigrantsSP )
                        outputChatBox(">>Auto-balance system changed your team!", playersForIMI[#playersForIMI], 255, 64, 64)
                    else
                        sync = true
                    end
                end
               
                spawn()
           
            else
           
                while(sync ~= true) do
                    if(#playersForPOL ~= #playersForIMI + 1) then
                        table.insert(playersForIMI, playersForPOL[#playersForPOL])
                       
Link to comment

This will work, but, there is something wrong with the resource, idk what's wrong, because i tested that too, and i tested his whole script file, and it still worked, so i guess it's something in another script file.

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