hex to RGBA?
#1

Is there a way to convert HEX color to RGBA? I'm trying to make something like a custom chat color.
Reply
#2

Delete.
Reply
#3

http://hex2rgba.devoth.com/
Reply
#4

I understand that they're both integers, but I am not able to make something like a dialog where a player enters a HEX value color and then set an object material's color to that HEX color. I read on WIKI that the material color is in ARGB format.
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=268417
https://sampforum.blast.hk/showthread.php?tid=337033
Reply
#6

I want to make when I type for example 'FFFF00' which is yellow in HEX value.. to be converted to ARGB format and then be able to use it with SetObjectMaterial because I can't find a solution for this.
Reply
#7

sscanf, you can use it for any string to something converting
https://github.com/Y-Less/sscanf/wiki/%22h%22-Specifier
pawn Код:
new hex;
sscanf(params, "h", hex);
// checking if the value is only between 0 and 0xFFFFFF
if(0 <= hex <= 0xFFFFFF) {
    // adding the full alpha (0xFF) in front of it
    hex |= 0xFF << 24;
}
Reply
#8

Delete.
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
sscanf, you can use it for any string to something converting
https://github.com/Y-Less/sscanf/wiki/%22h%22-Specifier
pawn Код:
new hex;
sscanf(params, "h", hex);
// checking if the value is only between 0 and 0xFFFFFF
if(0 <= hex <= 0xFFFFFF) {
    // adding the full alpha (0xFF) in front of it
    hex |= 0xFF << 24;
}
Okay here's my dialog:
For example if my input is "FFFF00" the HEX will become FFFFFF00 without the 0x at the beginning and the color of the object wouldn't change either.

pawn Код:
if(response)
                {
                    new hex, matmodel, txdname[45], texturename[45], color;
                    if(isnull(inputtext) || sscanf(inputtext, "h", hex))
                        return RedNoticeEx(playerid, "Invalid HEX color."), ShowTextureColorChange(playerid, FMatSlot[playerid]);
                    hex |= 0xFF << 24;
                    SCMEx(playerid, hex, "%h", hex);
                    new object = Furniture[FHouse[playerid]][FSlot[playerid]][fObject];
                    GetDynamicObjectMaterial(object, FMatSlot[playerid], matmodel, txdname, texturename, color, 45, 45);
                    SetDynamicObjectMaterial(object, FMatSlot[playerid], matmodel, txdname, texturename, hex);
                    ShowTextureColorChange(playerid, FMatSlot[playerid]);
                }
Reply
#10

Quote:
Originally Posted by Albon
Посмотреть сообщение
Okay here's my dialog:
For example if my input is "FFFF00" the HEX will become FFFFFF00 without the 0x at the beginning and the color of the object wouldn't change either.

pawn Код:
//CODE
Yeah pretty much

If you use sscanf you don't need isnull, if you still want to use it you need to use && (and) not || (or)
pawn Код:
if(response)
{
    new hex;
    if(sscanf(inputtext, "h", hex))
        return RedNoticeEx(playerid, "Invalid HEX color."), ShowTextureColorChange(playerid, FMatSlot[playerid]);
    new matmodel, txdname[45], texturename[45], color;
    //some as before
}
For SCMEx i hope you use a function and not a macro, see
http://pastebin.com/JcX7qFGd
macro would be SCM1, use a version with emit like SCM2, SCM3 or SM4 (best) \/
http://forum.sa-mp.com/showthread.ph...88#post2857588
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)