Converting colors from 'normal' to embed
#1

Is there a function, that for example, converts 0xFFFFFFFF to FFFFFF?
Reply
#2

pawn Код:
0xFFFFFFFF =


0x
FFFFFF // the embded code
FF // color power
I always use this methods, but I hope you will found a converter It's will help me too. ahah.
Reply
#3

You can use this
https://sampforum.blast.hk/showthread.php?tid=387690
Reply
#4

You know what, i'm going to attempt to make a converter tomorrow. I could do with one as well.
Reply
#5

Quote:
Originally Posted by Luis-
Посмотреть сообщение
You know what, i'm going to attempt to make a converter tomorrow. I could do with one as well.
I'd need a function, converting the color manually is easy, you just remove the 0x and the last 2 characters (opacity), but I'd need a PAWN function that would automatically do that.
Reply
#6

Okay! Something like 'HEX2RGB(colour)' & 'RGB2HEX(colour)'.
Reply
#7

Wrote my own function.

pawn Код:
stock ColorToEmbed(const color[]) {
    new finalclr[7];
    format(finalclr, sizeof finalclr, "%s", color[2]);
    return finalclr;
}

CMD:embed(playerid, params) {
    new str[128], col[7];
    col = ColorToEmbed("0xFFFFFFFF");
    format(str, sizeof str, "Hi {%s}there.", col);
    SendClientMessage(playerid, 0xFF0000FF, str);
    return 1;
}
You need to input your color as a string into ColorToEmbed and it will return a color string without 0x and the last 2 characters. Works like charm.
Reply
#8

Ah, fair enough! How does it remove the 0x and FF though?
Reply
#9

Quote:
Originally Posted by Luis-
Посмотреть сообщение
Ah, fair enough! How does it remove the 0x and FF though?
The trick is in the size of the strings. A string is basically an array with a value for each character and a final value of NUL to signify the end of string. Keep in mind that array keys start at zero. Mean sets the size of finalchr to seven, meaning that only a string six characters in length can fit inside of it. He then formats the string using color[2], which returns the value of color starting from the third character. The first two characters are therefore omitted, leaving us with the "FFFFFFFF". This is eight characters long and so when it tries to fit in to finalchr, the last two characters are omitted to make room, leaving us with "FFFFFF".
Reply
#10

Shifting to the right is the only thing you need to do. You can then format using %06x.

pawn Код:
new embedColor = originalColor >>> 8;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)