Loading offline player Data (MySQL System)
#1

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(playeridparams[])
{
    new 
string[128];
    
mysql_tquery(ConnectionHandle"SELECT money FROM accounts WHERE username = 'Someone'""LoadOtherPlayerData""i"playerid);
    
format(stringsizeof(string), "Money: %i"Variable[playerid]); SendClientMessage(playerid, -1string);
    return 
1;
}
forward LoadOtherPlayerData(playerid);
public 
LoadOtherPlayerData(playerid)
{
    new 
rowsfieldscache_get_data(rowsfieldsConnectionHandle);
    if(!
rows) return 1;
    
Variable[playerid] = cache_get_field_content_int(0"money");
    return 
1;

Reply
#2

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.
Reply
#3

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; 
}
Reply
#4

Thanks guys, i got everything well.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)