11.02.2015, 20:51
Is there a way to convert HEX color to RGBA? I'm trying to make something like a custom chat color.
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;
}
sscanf, you can use it for any string to something converting
https://github.com/Y-Less/sscanf/wiki/%22h%22-Specifier 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]);
}
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;
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
}