Jump to content

[Help] From R,G,B to Hex


AlvarO

Recommended Posts

Like a color, and that color goes changing from white to black infinite times.

use this code it's clientside

setTimer ( function() 
        if isPedInVehicle( getLocalPlayer( )) then 
            local uVehicle = getPedOccupiedVehicle( getLocalPlayer( ) ) 
            if uVehicle then 
                local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
                setVehicleColor( uVehicle, r, g, b ) 
            end 
        end 
    end, 5000, 1 ) 

Link to comment
local color = {[0] = 0, [1] = 100, [2] = 200} 
local increment = 5 
  
function changeColor() 
    for k in ipairs(color) do 
        color[k] = color[k] + increment 
        if (color[k] > 255) then 
            color[k] = -255 
        end 
    end 
    setVehicleColor(theVehicle, math.abs(color[0]), math.abs(color[1]), math.abs(color[2]), math.abs(color[0]), math.abs(color[1]), math.abs(color[2])) 
end 
local timer = setTimer(changeColor, 50, 0) 

Maybe something like this would work for some kind of rainbow? If you really wish for a rainbow color, then you should define the desired colors and interpolate between them infinite times...

Edited by Guest
Link to comment

And how it with work in an auto team?

CODE:

  
Names={} 
Tags={} 
Colors={} 
  
local names ={"Empire Street Riders"} 
local tags  ={"EsR"} 
local colors ={"#256f5c"} 
  
function loadTeams() 
 for i,name in pairs(names) do 
Names[i]=name 
end 
  
for i,tag in pairs(tags) do 
Tags[i]=tag 
end 
  
for i,color in pairs(colors) do 
Colors[i] = color 
end 
 end 
  
addEventHandler("onResourceStart",root,loadTeams) 
  
function moveOnStart() 
for i,player in pairs(getElementsByType("player")) do 
check(player) 
end 
end 
  
addEventHandler("onResourceStart",root,moveOnStart) 
  
function check (player) 
setPlayerTeam(player,nil) 
 for i,tag in pairs(tags) do 
    if string.find(getPlayerName(player),tag) then 
local name = Names[i] 
local color = Colors[i] 
  if  not getTeamFromName(name) then 
createTeam(name,getColorFromString(color)) 
end 
local team = getTeamFromName(name) 
setPlayerTeam(player,team) 
  
end 
   end 
      end 
  
function remove() 
 for t,teams in pairs(names) do 
 local team = getTeamFromName(teams) 
  if team then 
     if  countPlayersInTeam ( team )==0 then 
         destroyElement(team) 
end 
   end 
       end 
          end 
  
function nick(old,new) 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerChangeNick",root,nick) 
  
function join() 
setTimer(check,4000,1,source) 
end 
  
addEventHandler("onPlayerJoin",root,join) 
  
function quit(player) 
setTimer(remove,1000,1) 
end 
  
addEventHandler("onPlayerQuit",root,quit) 
  
  

Link to comment

Try this function friend:

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 

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