SA-MP Forums Archive
Hexadecimal in samp .... ? - 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: Hexadecimal in samp .... ? (/showthread.php?tid=646020)



Hexadecimal in samp .... ? - wallee - 09.12.2017

From this:

0xFFFFFFAA (currently as a string)

How to get it as an integer that i can use in functions?

I used this:

Код:
new hex;
sscanf("0xFFFFFFAA", "x", hex);
But the output is without 0x and the functions don't accept that ...


Re: Hexadecimal in samp .... ? - Sithis - 09.12.2017

What are you trying to do with the hex value? There’s got to be a easier way.


Re: Hexadecimal in samp .... ? - wallee - 09.12.2017

I have it saved in a string and i need it in integer form so i can use it in functions like SetPlayerColor etc.


Re: Hexadecimal in samp .... ? - Sjn - 09.12.2017

There is this function called HexToInt created by few people around, search for it.

You can also use a web tool to convert your hex color code into an integer value, just search for it.


Re: Hexadecimal in samp .... ? - Sithis - 09.12.2017

Just define the hex colors using #define COLOR_NAME hexvalue.


Re: Hexadecimal in samp .... ? - wallee - 09.12.2017

Quote:
Originally Posted by Sjn
Посмотреть сообщение
There is this function called HexToInt created by few people around, search for it.

You can also use a web tool to convert your hex color code into an integer value, just search for it.
HexToInt uses the same code you see in my first post, and i can't use web tools on the fly


Re: Hexadecimal in samp .... ? - Konstantinos - 09.12.2017

Quote:
Originally Posted by wallee
Посмотреть сообщение
But the output is without 0x and the functions don't accept that ...
The output is an integer which is accepted. In your case, hex will have the value of -86

But the question is why do you save it as a string? If the player inputs a hex as their desired color, convert it using sscanf and save it as an integer. It will not only take less space but can be easily be embedded in formatting text (using color >>> 8 as argument).


Re: Hexadecimal in samp .... ? - wallee - 09.12.2017

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The output is an integer which is accepted. In your case, hex will have the value of -86

But the question is why do you save it as a string? If the player inputs a hex as their desired color, convert it using sscanf and save it as an integer. It will not only take less space but can be easily be embedded in formatting text (using color >>> 8 as argument).
but what if i need to adjust the alpha? how do i do that with numbers like -86?


Re: Hexadecimal in samp .... ? - Konstantinos - 09.12.2017

You remove the alpha and set the new one. Say the player types "FF" as the new alpha which sscanf will convert to 255. It replaces the alpha to the new color so it returns -1 which is 0xFFFFFFFF
pawn Код:
new alpha_hex;
sscanf("FF", "x", alpha_hex);
printf("x: %i", alpha_hex);
   
new color = -86;
color = ChangeAlpha(color, alpha_hex);
printf("color: %i", color);
pawn Код:
ChangeAlpha(color, alpha)
{
    return (color & ~0xFF) | alpha;
}



Re: Hexadecimal in samp .... ? - wallee - 09.12.2017

still kinda confused but will test stuff out, thanks