SA-MP Forums Archive
hex to RGBA? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: hex to RGBA? (/showthread.php?tid=562805)



hex to RGBA? - Albon - 11.02.2015

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


Re: hex to RGBA? - Vince - 11.02.2015

Delete.


Re: hex to RGBA? - Dignity - 11.02.2015

http://hex2rgba.devoth.com/


Re: hex to RGBA? - Albon - 11.02.2015

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.


Re: hex to RGBA? - Jefff - 11.02.2015

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


Re: hex to RGBA? - Albon - 12.02.2015

Quote:
Originally Posted by Jefff
Посмотреть сообщение
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.


AW: hex to RGBA? - Nero_3D - 12.02.2015

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;
}



Re: hex to RGBA? - PaulDinam - 12.02.2015

Delete.


Re: AW: hex to RGBA? - Albon - 12.02.2015

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]);
                }



AW: Re: AW: hex to RGBA? - Nero_3D - 12.02.2015

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