Jump to content

[Problem] setTeamColor


GrubaS

Recommended Posts

Posted

Hello, i'm trying to make a script example, "/setteamcolor 00ff00"

  
    team1 = createTeam("example", r, g, b) 
  
function RGBToHex(red, green, blue, alpha) 
    if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then 
        return nil 
    end 
    if(alpha) then 
        return string.format("#%.2X%.2X%.2X%.2X", red,green,blue,alpha) 
    else 
        return string.format("#%.2X%.2X%.2X", red,green,blue) 
    end 
end 
  
function setteamcolor( red, green, blue) 
if ( team1 ) then       
    local hex = RGBToHex (red, green, blue) 
    setTeamColor (team1, hex) 
end 
end 
addCommandHandler ( "setteamcolor", setteamcolor ) 
  
  

error in debug:

Line: 5

attempt to compare nil with number 

please help me.

Posted

try this

    team1 = createTeam("example", r, g, b) 
  
  
addCommandHandler('stc', function ( player , cmd , r , g , b ) -- stc = Set Team Color  
if ( cmd and r and g and b ) then 
if ( team1 ) then 
setTeamColor ( team1 , r , g , b ) 
end 
end 
end 
) 
  
Posted
try this

    team1 = createTeam("example", r, g, b) 
  
  
addCommandHandler('stc', function ( player , cmd , r , g , b ) -- stc = Set Team Color  
if ( cmd and r and g and b ) then 
if ( team1 ) then 
setTeamColor ( team1 , r , g , b ) 
end 
end 
end 
) 
  

It's works but i need write ex. "/stc 255 255 0" i want write html code ex. "/stc 00ff00"

Posted

As Well as ?

    team1 = createTeam("example", r, g, b) 
  
  
addCommandHandler('stc', function ( player , cmd , hex) -- stc = Set Team Color  
if ( cmd and hex ) then 
if ( team1 ) then 
local Color = { getColorFromString ( tostring ( hex ) ) }  
setTeamColor ( team1 , Color[1] , Color[2] , Color[3] ) 
end 
end 
end 
) 
  
Posted
try this

    team1 = createTeam("example", r, g, b) 
  
  
addCommandHandler('stc', function ( player , cmd , r , g , b ) -- stc = Set Team Color  
if ( cmd and r and g and b ) then 
if ( team1 ) then 
setTeamColor ( team1 , r , g , b ) 
end 
end 
end 
) 
  

This example is wrong. You are not converting string to number.

  
r = tonumber(r) 
g = tonumber(g) 
b = tonumber(g) 

Not critisizing but I'm sure many new newbies will try to learn something from this code but they will find that it doesn't work.

Posted
function setteamcolor(player, cmd, hex) 
  if ( team1 ) then 
    if hex:sub(1,1) == "#" then outputChatBox("Incorrect syntax: Invalid HEX colour", player) end 
    if #(hex:sub(2)) == 3 or #(hex:sub(2)) == 6 then -- ensure the hex is either 3 characters long (eg. FFF) or 6 (eg. FFFFFF) 
    local r, g, b =  getColorFromString(hex) --inject the hex to the function, with # appended in front. Returns RGB. 
    setTeamColor(team1, r, g, b) 
  end 
end 
addCommandHandler ( "setteamcolor", setteamcolor ) 

/setteamcolor #123456 will set the team colour to RGB(18,52,86)

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