Loading HEX from a MySQL field -
Luis- - 15.04.2012
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.
Re: Loading HEX from a MySQL field -
MP2 - 15.04.2012
Convert it to an integer.
Re: Loading HEX from a MySQL field -
admantis - 15.04.2012
if I'm not wrong there is a %h specifier, so you can load it with that, someone correct me.
Re: Loading HEX from a MySQL field -
Luis- - 15.04.2012
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.
Re: Loading HEX from a MySQL field -
Luis- - 15.04.2012
Bump.
Re: Loading HEX from a MySQL field -
Ricop522 - 15.04.2012
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
Re: Loading HEX from a MySQL field -
Vince - 15.04.2012
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:
Re: Loading HEX from a MySQL field -
Luis- - 15.04.2012
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?
Re: Loading HEX from a MySQL field -
Luis- - 15.04.2012
Could someone tell me how to do this please?
Re: Loading HEX from a MySQL field -
Vince - 15.04.2012
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.