Jump to content

[Help] From R,G,B to Hex


AlvarO

Recommended Posts

Posted

Hey, so I was wondering how to pass a r,g,b colorcode to hex one, and if it is possible, how to do it with a raimbow colorcode?

Thanks.

MTA:SA SPANISH DEATHMATCH PLAYER

Posted (edited)

Thanks! but not that raimbow, I wanted a rainbow like the car colors ones.

Edited by Guest

MTA:SA SPANISH DEATHMATCH PLAYER

Posted

Hmm, I'm not sure what do you mean by 'raimbow like the car colors ones'.

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted
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 ) 

Nothing is impossible when you acquire the knowledge
 
Posted
Like a color, and that color goes changing from white to black infinite times.

That is not a colour but a sequence of different colours.

Previously known as MrTasty.

Posted (edited)
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

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted

onClientRender may be better (although it might cause lags, since we don't know how much impact on the CPU will the setVehicleColor ( .. ) cause. Thumbs up for the interpolateBetween (..) method, though.

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted
And for a team? Also thanks, the code for vehicle works perfectly ;)

If you're referring for applying rainbow color to teams, then just use setTeamColor (..) instead of setVehicleColor (..) with the same arguments for R, G and B.

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted

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) 
  
  

MTA:SA SPANISH DEATHMATCH PLAYER

Posted

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 

yDORrdn.png

Posted

He's not looking for RGB to Hex anymore — He wants to make colours smoothly change from one to another on team color (or at least that's what I understood. Read the full topic.

Previously known as MrTasty.

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