SA-MP Forums Archive
[MySQL]Setcolor - 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: [MySQL]Setcolor (/showthread.php?tid=521915)



[MySQL]Setcolor - Affan - 25.06.2014

Problem : The color code saves correctly, but it does not set the color.
Objective : Set the color which I saved to the database.


OnPlayerConnect
pawn Код:
format(Query2,sizeof(Query2),"SELECT * FROM `users` WHERE `Name` = '%s'", GetName(playerid));
    mysql_function_query(cHandle, Query2, true, "CheckStats", "d", playerid);

pawn Код:
public CheckStats(playerid, name[])
{
    new rows, fields;
    cache_get_data (rows, fields, cHandle);
    if(rows)
    {
        new mHolder[128], color;
        cache_get_field_content(0, "Color", mHolder, cHandle);
        SetPlayerColor(playerid, color);
    }
    return 1;
}
pawn Код:
// example of colorcode = 0x00CC00FF
format(Query1,sizeof(Query1),"UPDATE `users` SET `Color` = '%s' WHERE `Name` = '%s'", colorcode, GetName(playerid));
    mysql_function_query(cHandle, Query1, false, "", "d", playerid);



Re: [MySQL]Setcolor - Konstantinos - 25.06.2014

Colours are integers so save it as an integer and load it as an integer.


Re: [MySQL]Setcolor - Affan - 25.06.2014

I've been trying 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 on saving, I did:

pawn Код:
format(color, sizeof(color), "0x%sFF", mHolder);
        SetPlayerColor(playerid, HexToInt(str));
But my colors are :
0xFFFF00AA
0xFF0000AA