24.01.2014, 12:12
I think the problem is this part:
I think the only one that is actually effective here is the last call to mysql_query (`Exp`), since it just overwrites the results each time.
I would highly recommend that instead of making calls to mysql every time someone calls any command, you instead load the player when they connect to the server and save these things in variables. Then when their Exp goes up, do PlayerInfo[playerid][Exp] += MoreExp;
and periodically save their stats to the database again (PlayerInfo[playerid][Exp], etc)
HOWEVER, I threw this together, feel free to try it. Please do let me know if it works for you:
NOTE: I didn't even try compiling this so there will probably be some errors.
Код:
mysql_query("SELECT user, Scores FROM `playerdata` ORDER BY `Scores` DESC LIMIT 5"); mysql_query("SELECT user, Deaths FROM `playerdata` ORDER BY `Deaths` DESC LIMIT 5"); mysql_query("SELECT user, Cash FROM `playerdata` ORDER BY `Cash` DESC LIMIT 5"); mysql_query("SELECT user, Exp FROM `playerdata` ORDER BY `Exp` DESC LIMIT 5");
I would highly recommend that instead of making calls to mysql every time someone calls any command, you instead load the player when they connect to the server and save these things in variables. Then when their Exp goes up, do PlayerInfo[playerid][Exp] += MoreExp;
and periodically save their stats to the database again (PlayerInfo[playerid][Exp], etc)
HOWEVER, I threw this together, feel free to try it. Please do let me know if it works for you:
Код:
TopFive(playerid, column_name[], name[]) { new Query[64]; new temp[1500]; new info[1500]; format(Query, sizeof(Query), "SELECT user, %s FROM playerdata ORDER BY `%s` DESC LIMIT 5", column_name, column_name); mysql_query(Query); mysql_store_result(); new num, top[6][24], results[6][25] while (mysql_retrieve_row()) { mysql_fetch_field_row(top[num], "user"); mysql_fetch_field_row(results[num], column_name); num++; } mysql_free_result(); format(temp, sizeof(temp), "{53C506}Top 5 players with most %s:\n\n", name); strcat(info, temp); format(temp, sizeof(temp), "{FFFFFF}N° 1: %s with {A1C2FF}%s %s \n", top[0], results[0], name); strcat(info, temp); format(temp, sizeof(temp), "{FFFFFF}N° 2: %s with {A1C2FF}%s %s \n", top[1], results[1], name); strcat(info, temp); format(temp, sizeof(temp), "{FFFFFF}N° 3: %s with {A1C2FF}%s %s \n", top[2], results[2], name); strcat(info, temp); format(temp, sizeof(temp), "{FFFFFF}N° 4: %s with {A1C2FF}%s %s \n", top[3], results[3], name); strcat(info, temp); format(temp, sizeof(temp), "{FFFFFF}N° 5: %s with {A1C2FF}%s %s \n\n", top[4], results[4]); strcat(info, temp); ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_MSGBOX, "Top 5 BWH Players", info, "Close", ""); } CMD:top(playerid, params[]) { if (GetPVarInt(playerid, "CmdTime") > GetTickCount()) return SCM(playerid, 0xFF0000FF, "Please wait before using this command again."); TopFive(playerid, "Scores", "Scores"); SetPVarInt(playerid, "CmdTime", GetTickCount() + 5000); return true; }