Loading HEX from a MySQL field
#1

Right, I have a row in for my airlines table called "Colour", it's set like this, "C2A2DA", how can I make it so it sets the players colour to the colour on the "Colour" row? I've tried converting to "binary" and "decimal" but it wont work, no doubt i've done something wrong. I am loading it as a string, is that right? Thanks.
Reply
#2

Convert it to an integer.
Reply
#3

if I'm not wrong there is a %h specifier, so you can load it with that, someone correct me.
Reply
#4

Alright, i'm using this;
pawn Код:
stock HexToInt(string[]) // By DracoBlue
{
    if (string[0]==0) return 0;
    new i;
    new cur=1;
    new res=0;
    for (i=strlen(string);i>0;i--) {
        if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
        cur=cur*16;
    }
    return res;
}
and it's converting but not setting correctly, my new airline colour is Yellow and it just isn't setting it to my name.
Reply
#5

Bump.
Reply
#6

pawn Код:
stock IntToHex(int)
{
    new
        str[15];
    format(str, sizeof(str), "%x", int);
    return str;
}

stock HexToInt(hex)
{
    new
        str[15];
    format(str, sizeof(str), "%i", hex);
    return strval(str);
}
IntToHex to load
Reply
#7

Just save the values as integers in MySQL in the first place. Problem solved. Unless you constantly override these values manually (in phpMyAdmin or something), there's no reason why you shouldn't do that.

Tip: To add the alpha for the player color:
pawn Код:
((color << 8) | FF)
Reply
#8

I've not set the row on PhpMyAdmin to an integer and used integer colour codes, i'm having trouble with the IntToHex;

pawn Код:
SetPlayerColor(playerid, IntToHex(AirlineInfo[PlayerInfo[playerid][pAirline]][aColours]));
Is that the correct way to use it?
Reply
#9

Could someone tell me how to do this please?
Reply
#10

You don't need that function at all, SetPlayerColor (or any other function, for that matter) just accepts a numerical value. Just put it there.
pawn Код:
SetPlayerColor(playerid, 0xC2A2DAFF);
SetPlayerColor(playerid, 3265452799);
Both are valid and both produce exactly the same output.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)