Hexadecimal in samp .... ?
#1

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 ...
Reply
#2

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

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

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.
Reply
#5

Just define the hex colors using #define COLOR_NAME hexvalue.
Reply
#6

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
Reply
#7

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).
Reply
#8

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?
Reply
#9

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;
}
Reply
#10

still kinda confused but will test stuff out, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)