SA-MP Forums Archive
Top kills - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Top kills (/showthread.php?tid=651218)



Top kills - C5Perfect - 15.03.2018

PHP код:
CMD:top(playeridparams[])
{
    if(
LoggedIn[playerid] == false) return SendClientMessage(playeridCOLOR_RED"ERROR: You must be logged in.");
    
mysql_query(MySQL"SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    
mysql_store_result();
    new 
string[128], pName[24], pKills[5], query[256];
    if(
mysql_num_rows() != 0)
    {
        while(
mysql_fetch_row_format(query"|"))
        {
            
mysql_fetch_field_row(pName"User");
            
mysql_fetch_field_row(pKills"Kills");
            
format(stringsizeof(string), "User: %s. Kills: %i"pNamepKills);
            
SendClientMessage(playeridCOLOR_REDstring);
        }
    }
    
mysql_free_result();
    return 
1;

Kills doesn't return correct number.. it is different every time but not correct.. what am I doing wrong?


Re: Top kills - Jefff - 15.03.2018

https://sampforum.blast.hk/showthread.php?tid=282052


Re: Top kills - C5Perfect - 16.03.2018

Quote:
Originally Posted by Jefff
Посмотреть сообщение
PHP код:
CMD:top(playeridparams[])
{
    if(
LoggedIn[playerid] == false) return SendClientMessage(playeridCOLOR_RED"ERROR: You must be logged in.");
    
mysql_query(MySQL"SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    
mysql_store_result();
    new 
string[128], pName[24], pKills[5];
    if(
mysql_num_rows() != 0)
    {
        while(
mysql_retrieve_row())
        {
            
mysql_fetch_field_row(pName"User");
            
mysql_fetch_field_row(pKills"Kills");
            
format(stringsizeof(string), "User: %s. Kills: %i"pNamepKills);
            
SendClientMessage(playeridCOLOR_REDstring);
        }
    }
    
mysql_free_result();
    return 
1;

I changed my code like that but the result is same..? Thanks for the reply


Re: Top kills - Jefff - 16.03.2018

Write always which version of mysql because this is weird mysql_query(MySQL,


Re: Top kills - C5Perfect - 16.03.2018

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Write always which version of mysql because this is weird mysql_query(MySQL,
MySQL R33


Re: Top kills - Jefff - 16.03.2018

Try with cache

pawn Код:
CMD:top(playerid, params[])
{
    if(LoggedIn[playerid] == false) return SendClientMessage(playerid, COLOR_RED, "ERROR: You must be logged in.");

    new Cache:result = mysql_query(MySQL, "SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    if((params[0] = cache_num_rows()))
    {
        new pName[24], pKills, string[128];
        for(new i = 0; i < params[0]; i++)
        {
            cache_get_row(i, 0, pName);
            pKills = cache_get_row_int(i, 1);
            format(string, sizeof(string), "User: %s. Kills: %i", pName, pKills);
            SendClientMessage(playerid, COLOR_RED, string);
        }
    }
    cache_delete(result);
    return 1;
}



Re: Top kills - C5Perfect - 16.03.2018

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Try with cache

pawn Код:
CMD:top(playerid, params[])
{
    if(LoggedIn[playerid] == false) return SendClientMessage(playerid, COLOR_RED, "ERROR: You must be logged in.");

    new Cache:result = mysql_query(MySQL, "SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    if((params[0] = cache_num_rows()))
    {
        new pName[24], pKills, string[128];
        for(new i = 0; i < params[0]; i++)
        {
            cache_get_row(i, 0, pName);
            pKills = cache_get_row_int(i, 1);
            format(string, sizeof(string), "User: %s. Kills: %i", pName, pKills);
            SendClientMessage(playerid, COLOR_RED, string);
        }
    }
    cache_delete(result);
    return 1;
}
Working. Thanks a lot!