Top command (again) -
Face9000 - 05.01.2014
Ok forget last topic, whats wrong with this code?
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;
}
The top 5 score works, the other no. It shows always 0 even if i have more exp or cash or deaths than others.
Re: Top command (again) -
Eth - 05.01.2014
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 temp1[1500];
new temp2[1500];
new temp3[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(temp1, sizeof(temp1), "{FFFFFF}N° 1: %s with {A1C2FF}%d Deaths \n", top[0], deaths[0]);
strcat(info, temp1);
format(temp1, sizeof(temp1), "{FFFFFF}N° 2: %s with {A1C2FF}%d Deaths \n", top[1], strval(deaths[1]));
strcat(info, temp1);
format(temp1, sizeof(temp1), "{FFFFFF}N° 3: %s with {A1C2FF}%d Deaths \n", top[2], strval(deaths[2]));
strcat(info, temp1);
format(temp1, sizeof(temp1), "{FFFFFF}N° 4: %s with {A1C2FF}%d Deaths \n", top[3], strval(deaths[3]));
strcat(info, temp1);
format(temp1, sizeof(temp1), "{FFFFFF}N° 5: %s with {A1C2FF}%d Deaths \n\n", top[4], strval(deaths[4]));
strcat(info, temp1);
//Cash
strcat(info,"{53C506}Top 5 players with most deaths:\n\n");
format(temp2, sizeof(temp2), "{FFFFFF}N° 1: %s with {A1C2FF}%i CSCash \n", top[0], cash[0]);
strcat(info, temp2);
format(temp2, sizeof(temp2), "{FFFFFF}N° 2: %s with {A1C2FF}%i CSCash \n", top[1], strval(cash[1]));
strcat(info, temp2);
format(temp2, sizeof(temp2), "{FFFFFF}N° 3: %s with {A1C2FF}%i CSCash \n", top[2], strval(cash[2]));
strcat(info, temp2);
format(temp2, sizeof(temp2), "{FFFFFF}N° 4: %s with {A1C2FF}%i CSCash \n", top[3], strval(cash[3]));
strcat(info, temp2);
format(temp2, sizeof(temp2), "{FFFFFF}N° 5: %s with {A1C2FF}%i CSCash \n\n", top[4], strval(cash[4]));
strcat(info, temp2);
//Exp
strcat(info,"{53C506}Top 5 players with most deaths:\n\n");
format(temp3, sizeof(temp3), "{FFFFFF}N° 1: %s with {A1C2FF}%d Exp \n", top[0], exp[0]);
strcat(info, temp3);
format(temp3, sizeof(temp3), "{FFFFFF}N° 2: %s with {A1C2FF}%d Exp \n", top[1], strval(exp[1]));
strcat(info, temp3);
format(temp3, sizeof(temp3), "{FFFFFF}N° 3: %s with {A1C2FF}%d Exp \n", top[2], strval(exp[2]));
strcat(info, temp3);
format(temp3, sizeof(temp3), "{FFFFFF}N° 4: %s with {A1C2FF}%d Exp \n", top[3], strval(exp[3]));
strcat(info, temp3);
format(temp3, sizeof(temp3), "{FFFFFF}N° 5: %s with {A1C2FF}%d Exp \n", top[4], strval(exp[4]));
strcat(info, temp3);
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_MSGBOX,"Top 5 BWH Players",info,"Close","");
SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
return true;
}
check this out
Re: Top command (again) -
Face9000 - 06.01.2014
Same problem.
Re: Top command (again) -
Konstantinos - 06.01.2014
It can store only 1 query with mysql_store_result.
Just do that with this way:
pawn Код:
mysql_query("SELECT user, Scores FROM `playerdata` ORDER BY `Scores` DESC LIMIT 5");
mysql_store_result();
// assign..
mysql_free_result();
mysql_query("SELECT user, Deaths FROM `playerdata` ORDER BY `Deaths` DESC LIMIT 5");
mysql_store_result();
// assign..
mysql_free_result();
mysql_query("SELECT user, Cash FROM `playerdata` ORDER BY `Cash` DESC LIMIT 5");
mysql_store_result();
// assign..
mysql_free_result();
mysql_query("SELECT user, Exp FROM `playerdata` ORDER BY `Exp` DESC LIMIT 5");
mysql_store_result();
// assign..
mysql_free_result();
// show dialog..
Re: Top command (again) -
Face9000 - 06.01.2014
I made in this way:
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_store_result();
mysql_free_result();
mysql_query("SELECT user, Deaths FROM `playerdata` ORDER BY `Deaths` DESC LIMIT 5");
mysql_store_result();
mysql_free_result();
mysql_query("SELECT user, Cash FROM `playerdata` ORDER BY `Cash` DESC LIMIT 5");
mysql_store_result();
mysql_free_result();
mysql_query("SELECT user, Exp FROM `playerdata` ORDER BY `Exp` DESC LIMIT 5");
mysql_store_result();
mysql_free_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;
}
But now it doesnt even show the name and the score, exp, deaths and cash are always 0.
Re: Top command (again) -
Konstantinos - 06.01.2014
You need to get the data of the first query and assign them somewhere and then do the same for the rest.
Re: Top command (again) -
Face9000 - 06.01.2014
I dont get it. Sorry im new to MySQL.
Re: Top command (again) -
Face9000 - 07.01.2014
Bump.
Re: Top command (again) -
Face9000 - 08.01.2014
Bump.
Re: Top command (again) -
Vince - 08.01.2014
I really don't know how to explain this in simple English. If you're not doing anything between storing and freeing the result, it would be like being handed an apple, then throwing it away without taking a bite.