Jump to content

help updateColor team


iiv03

Recommended Posts

why does not happen when update color team after i wrote colors for several times?

team = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(playerSource,cmd,R,G,B)
	local playerName = getPlayerName(playerSource)
	local account = getPlayerAccount (playerSource)
	local account_name = getAccountName(account)
	if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
	if not R or not G or not B then outputChatBox("Syntex /color R G B",playerSource,255,255,255,true) return end
		if tonumber(R) <= 50 and tonumber(G) <= 50 and tonumber(B) <= 50 then
		colour.r = 255
		colour.g = 255
		colour.b = 255
		else
		colour.r = R
		colour.g = G
		colour.b = B
		end
		updateTeamColour()
		tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
		triggerClientEvent(getRootElement(), "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag,colour.r,colour.g,colour.b)
		outputChatBox("Done Update",playerSource,255,255,255,true)
		team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
	end
end
addCommandHandler("color",updateTeamSettings)


function updateTeamColour()
	setTeamColor ( team[2], colour.r, colour.g, colour.b )
end

 

Edited by xFabel
Link to comment

Well first off you're trying to set the team color to a team that doesn't exist yet - (update colors after making sure the team exists)
Secondly I would suggest checking if colour.r, colour.g & colour.b are numbers before trying to set anything(to prevent errors)

Try this:

team = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(playerSource,cmd,R,G,B)
    local playerName = getPlayerName(playerSource)
    local account = getPlayerAccount (playerSource)
    local account_name = getAccountName(account)
    if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("Syntex /color R G B",playerSource,255,255,255,true) return end
    if R <= 50 and G <= 50 and B <= 50 then
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
        triggerClientEvent(getRootElement(), "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag,colour.r,colour.g,colour.b)
        outputChatBox("Done Update",playerSource,255,255,255,true)
        local enemyTeam = getTeamFromName(enemyName)
        if enemyTeam then
            team[2] = enemyTeam
            updateTeamColour()
        else
            team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
            if team[2] then
                updateTeamColour()
            end
        end
    end
end
addCommandHandler("color",updateTeamSettings)


function updateTeamColour()
    setTeamColor ( team[2], colour.r, colour.g, colour.b )
end

 

Link to comment
43 minutes ago, Shux said:

Well first off you're trying to set the team color to a team that doesn't exist yet - (update colors after making sure the team exists)
Secondly I would suggest checking if colour.r, colour.g & colour.b are numbers before trying to set anything(to prevent errors)

Try this:


team = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(playerSource,cmd,R,G,B)
    local playerName = getPlayerName(playerSource)
    local account = getPlayerAccount (playerSource)
    local account_name = getAccountName(account)
    if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("Syntex /color R G B",playerSource,255,255,255,true) return end
    if R <= 50 and G <= 50 and B <= 50 then
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
        triggerClientEvent(getRootElement(), "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag,colour.r,colour.g,colour.b)
        outputChatBox("Done Update",playerSource,255,255,255,true)
        local enemyTeam = getTeamFromName(enemyName)
        if enemyTeam then
            team[2] = enemyTeam
            updateTeamColour()
        else
            team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
            if team[2] then
                updateTeamColour()
            end
        end
    end
end
addCommandHandler("color",updateTeamSettings)


function updateTeamColour()
    setTeamColor ( team[2], colour.r, colour.g, colour.b )
end

 

hey, i got error attempt to compare string with number in this line

    if R <= 50 and G <= 50 and B <= 50 then

 

Link to comment
2 minutes ago, DNL291 said:

Function parameters will return as string, you'll need to convert it number.

put this at the beginning of the function:


R,G,B = tonumber(G),tonumber(G),tonumber(B)

 

Oh i forgot but this is very simple. Thank you

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