Loading offline player Data (MySQL System) - 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: Loading offline player Data (MySQL System) (
/showthread.php?tid=613467)
Loading offline player Data (MySQL System) -
Juvanii - 28.07.2016
Why should i type the this command two times for loading offline player's data?
First Time: Money: Sends Message with 0
Second Time: Sends Message with the correct amount (15000 'for example')
PHP код:
new Variable[MAX_PLAYERS];
CMD:test(playerid, params[])
{
    new string[128];
    mysql_tquery(ConnectionHandle, "SELECT money FROM accounts WHERE username = 'Someone'", "LoadOtherPlayerData", "i", playerid);
    format(string, sizeof(string), "Money: %i", Variable[playerid]); SendClientMessage(playerid, -1, string);
    return 1;
}
forward LoadOtherPlayerData(playerid);
public LoadOtherPlayerData(playerid)
{
    new rows, fields; cache_get_data(rows, fields, ConnectionHandle);
    if(!rows) return 1;
    Variable[playerid] = cache_get_field_content_int(0, "money");
    return 1;
}Â
Re: Loading offline player Data (MySQL System) -
Vince - 28.07.2016
The point of threading is that the result
isn't immediately available. I don't really know how to explain this, but the order of execution isn't query -> load data -> format, but query -> format -> load data.
Re: Loading offline player Data (MySQL System) -
Rdx - 28.07.2016
You are formating before setting variable value.
And don't use cache_get_content int in case like that.
Also you don't need multithread here (unthreaded queries are supported too, they talking shi*) .
Correct code:
Код HTML:
new Variable[MAX_PLAYERS];
CMD:test(playerid, params[])
{
new string[128];
mysql_query(ConnectionHandle, "SELECT money FROM accounts WHERE username = 'Someone'");
new rows, fields;
cache_get_data(rows, fields);
if(!rows) return 1;
Variable[playerid] = cache_get_row_int(0, 0);
format(string, sizeof(string), "Money: %i", Variable[playerid]); SendClientMessage(playerid, -1, string);
return 1;
}
Re: Loading offline player Data (MySQL System) -
Juvanii - 30.07.2016
Thanks guys, i got everything well.