Help with this command
#1

Can someone tell me what's wrong? This /top is supposed to show top 5 players with highest score, money, deaths and exp, but when i do /top ingame, it shows no name and 0, at every value.

pawn Код:
CMD:top(playerid, params[])
{
if(GetPVarInt(playerid,"CmdTime")>GetTickCount())return SCM(playerid,0xFF0000FF,"Please wait before using this command again.");
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");
mysql_store_result();
new num, top[6][24], score[6][10], deaths[6][10], cash[6][20], exp[6][25];
while(mysql_retrieve_row())
{
    mysql_fetch_field_row(top[num], "user");
    mysql_fetch_field_row(score[num], "Scores");
    mysql_fetch_field_row(deaths[num], "Deaths");
    mysql_fetch_field_row(cash[num], "Cash");
    mysql_fetch_field_row(exp[num], "Exp");
    num++;
}
mysql_free_result();

    new temp[1500];
    new info[1500];

    //Score
    strcat(info,"{53C506}Top 5 players with most score:\n\n");
    format(temp, sizeof(temp), "{FFFFFF}N° 1: %s with {A1C2FF}%d Score \n", top[0], score[0]);
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 2: %s with {A1C2FF}%d Score \n", top[1], strval(score[1]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 3: %s with {A1C2FF}%d Score \n", top[2], strval(score[2]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 4: %s with {A1C2FF}%d Score \n", top[3], strval(score[3]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 5: %s with {A1C2FF}%d Score \n\n", top[4], strval(score[4]));
    strcat(info, temp);
   
    //Deaths
    strcat(info,"{53C506}Top 5 players with most deaths:\n\n");
    format(temp, sizeof(temp), "{FFFFFF}N° 1: %s with {A1C2FF}%d Deaths \n", top[0], deaths[0]);
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 2: %s with {A1C2FF}%d Deaths \n", top[1], strval(deaths[1]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 3: %s with {A1C2FF}%d Deaths \n", top[2], strval(deaths[2]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 4: %s with {A1C2FF}%d Deaths \n", top[3], strval(deaths[3]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 5: %s with {A1C2FF}%d Deaths \n\n", top[4], strval(deaths[4]));
    strcat(info, temp);
   
    //Cash
    strcat(info,"{53C506}Top 5 players with most deaths:\n\n");
    format(temp, sizeof(temp), "{FFFFFF}N° 1: %s with {A1C2FF}%i CSCash \n", top[0], cash[0]);
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 2: %s with {A1C2FF}%i CSCash \n", top[1], strval(cash[1]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 3: %s with {A1C2FF}%i CSCash \n", top[2], strval(cash[2]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 4: %s with {A1C2FF}%i CSCash \n", top[3], strval(cash[3]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 5: %s with {A1C2FF}%i CSCash \n\n", top[4], strval(cash[4]));
    strcat(info, temp);
   
    //Exp
    strcat(info,"{53C506}Top 5 players with most deaths:\n\n");
    format(temp, sizeof(temp), "{FFFFFF}N° 1: %s with {A1C2FF}%d Exp \n", top[0], exp[0]);
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 2: %s with {A1C2FF}%d Exp \n", top[1], strval(exp[1]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 3: %s with {A1C2FF}%d Exp \n", top[2], strval(exp[2]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 4: %s with {A1C2FF}%d Exp \n", top[3], strval(exp[3]));
    strcat(info, temp);
    format(temp, sizeof(temp), "{FFFFFF}N° 5: %s with {A1C2FF}%d Exp \n", top[4], strval(exp[4]));
    strcat(info, temp);

    ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_MSGBOX,"Top 5 BWH Players",info,"Close","");

SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
return true;
}
Reply
#2

Bump.
Reply
#3

Quote:
Originally Posted by Face9000
Посмотреть сообщение
Bump.
I think the problem is this part:

Код:
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 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:

Код:
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;
}
NOTE: I didn't even try compiling this so there will probably be some errors.
Reply
#4

Nope, doesn't works. Doesn't show names and the scores.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)