28.01.2015, 18:44
(
Последний раз редактировалось ReD_HunTeR; 14.02.2015 в 12:27.
)
fixxed.
new connectionHandle;
// Threaded Query
mysql_tquery(connectionHandle, "SELECT score, username FROM usertable ORDER BY score DESC LIMIT 10", "OnTopPlayersLoaded");
// Called when the data is loaded to cache
forward OnTopPlayersLoaded();
public OnTopPlayersLoaded()
{
for(new row, rows = cache_get_row_count(connectionHandle); row < rows; row ++)
{
new
username[MAX_PLAYER_NAME + 1],
score
;
cache_get_field_content(row, "username", username, connectionHandle);
score = cache_get_field_content_int(row, "score", connectionHandle);
printf("[Row %i] Username: %s, Score: %i", row, username, score);
}
return 1; // prevent memory leak
}
forward OnTopScores(playerid);
public OnTopScores(playerid)
{
for(new row, rows = cache_get_row_count(mysql); row < rows; row ++)
{
new username[MAX_PLAYER_NAME + 1], score, string[128];
cache_get_field_content(row, "Username", username, mysql);
score = cache_get_field_content_int(row, "Scores", mysql);
format(string, sizeof(string), "%i. Username: %s, Scores: %i", row, username, score);
ShowPlayerDialog(playerid,DIALOG_TOPSTATS,DIALOG_STYLE_MSGBOX,"Top Scored",string,"Okey","");
return 1;
}
return 1;
}
forward OnTopScores(playerid);
public OnTopScores(playerid)
{
new full_info[500];
for(new row, rows = cache_get_row_count(mysql); row < rows; row ++)
{
new
username[MAX_PLAYER_NAME + 1],
score,
sub_info[50]
;
cache_get_field_content(row, "Username", username, mysql);
score = cache_get_field_content_int(row, "Scores", mysql);
format(sub_info, sizeof sub_info, "%02i. Username: %s, Score: %i\n", row + 1, username, score);
strcat(full_info, sub_info);
}
ShowPlayerDialog(playerid, DIALOG_TOPSTATS, DIALOG_STYLE_MSGBOX, "Top Scores", full_info, "Close", "");
return 1;
}