Jump to content

How to make guiLabelSetColor with hex?


Cadu12

Recommended Posts

this is youre lucky day, I needed that conwerter recently ;)

  
function guiLabelSetHexColor (theelement, color) 
   local hexTodecim = {["0"]=0,["1"]=1,["2"]=2,["3"]=3,["4"]=4,["5"]=5,["6"]=6,["7"]=7,["8"]=8,["9"]=9,["a"]=10,["b"]=11,["c"]=12,["d"]=13,["e"]=14,["f"]=15} 
   local red = (hexTodecim[string.lower(string.sub(color, 2, 2))]*16) + hexTodecim[string.lower(string.sub(color, 3, 3))] 
   local green = (hexTodecim[string.lower(string.sub(color, 4, 4))]*16) + hexTodecim[string.lower(string.sub(color, 5, 5))] 
   local blue = (hexTodecim[string.lower(string.sub(color, 6, 6))]*16) + hexTodecim[string.lower(string.sub(color, 7, 7))] 
   guiLabelSetColor(theelement,red,green,blue) 
end 
  

paste the function somewhere in youre script and use

 guiLabelSetHexColor (theelement, hexcode) 

instead of

guiLabelSetColor(theelement,red,green,blue) 

Link to comment

It works, but rankingboard_clint.lua in race resource, it says PiG|#FF0000Cadu12

I wanted to be PiG|Cadu12

here code:

  
function createShadowedLabelFromSpare(x, y, width, height, text, align) 
  
    if #spareElems < 2 then 
        if not donePrecreate then 
            outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) 
        end 
        return createShadowedLabel(x, y, width, height, text, align) 
    else 
         
        local shadow = table.popLast( spareElems ) 
        guiSetSize(shadow, width, height, false) 
        guiSetText(shadow, text) 
        --guiLabelSetColor(shadow, 255, 119, 0) 
        --guiSetSize(shadow, 1, 1, true) 
         
        guiSetPosition(shadow, x + 1, y + 1, false) 
        guiSetVisible(shadow, true) 
  
        local label = table.popLast( spareElems ) 
        guiSetSize(label, width, height, false) 
        guiLabelSetHexColor(label, text) 
        guiSetText(label, string.gsub ( text, '#%x%x%x%x%x%x', '' )) 
         
        --guiSetSize(label, 1, 1, true) 
         
        guiSetPosition(label, x, y, false) 
        guiSetVisible(label, true) 
        if align then 
            guiLabelSetHorizontalAlign(shadow, align) 
            guiLabelSetHorizontalAlign(label, align) 
        else 
            guiLabelSetHorizontalAlign(shadow, 'left') 
            guiLabelSetHorizontalAlign(label, 'left') 
        end 
        return label, shadow 
    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...