Raised This Month: $32 Target: $400
 8% 

Sorting players in order of value?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 08-02-2018 , 19:08   Sorting players in order of value?
Reply With Quote #1

Hello! I would really like to know how I can make a plugin that is a top 10 players in order of a value selected by me from my database. Example: I write !top and it says the top 10 players with the most points on my server.

!top

1. Player1 - 10000 points
2. Player2 - 9953 points
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545
cristian20042 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-02-2018 , 19:22   Re: Sorting players in order of value?
Reply With Quote #2

Use your MySQL query to sort your data. Not sourcepawn!

An example query.

Code:
SELECT * FROM `table` ORDER BY `pointscolumn` DESC LIMIT 1,10
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-02-2018 , 19:28   Re: Sorting players in order of value?
Reply With Quote #3

PHP Code:
SELECT FROM table ORDER BY table_points DESC 
@Neuro Toxin
I wouldn't set a LIMIT + 1,10 won't work...

@cristian20042
Using my example of course requires you to have the right columns (name, points, etc... you know the drill).

PHP Code:
public void SQL_Top(Database hDatabaseDBResultSet hResults, const char[] sErrorint iData)
{
    if (
hResults == null)
        
ThrowError(sError);
    
    
int iClient GetClientOfUserId(iData);
    
    
int iRankiPoints;
    
    
char sName[256];
    
    while (
hResults.FetchRow())
    {
        if (++
iRank THE_AMOUNT_OF_PLAYERS_TO_ORDER)
            continue;
        
        
iPoints hResults.FetchInt(YOUR_COLUMN_NUMBER);
        
        
hResults.FetchString(YOUR_COLUMN_NUMBERsName256);
        
        
PrintToChat(iClient"%d %s %d"iRanksNameiPoints);
    }


Last edited by mug1wara; 08-02-2018 at 19:33.
mug1wara is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 08-02-2018 , 19:33   Re: Sorting players in order of value?
Reply With Quote #4

Thanks! What about creating a menu that shows you that? What should I do?
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545
cristian20042 is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-02-2018 , 19:37   Re: Sorting players in order of value?
Reply With Quote #5

Quote:
Originally Posted by cristian20042 View Post
Thanks! What about creating a menu that shows you that? What should I do?
something along the lines of
https://github.com/Headline/Gangs/bl...gangs.sp#L2274
headline is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-02-2018 , 19:39   Re: Sorting players in order of value?
Reply With Quote #6

or just like this :p
PHP Code:
public void SQL_Top(Database hDatabaseDBResultSet hResults, const char[] sErrorint iData)
{
    if (
hResults == null)
        
ThrowError(sError);
    
    
int iClient GetClientOfUserId(iData);
    
    
int iRankiPoints;
    
    
char sName[256], sMenuContent[256];
    
    
Menu hMenu = new Menu(Menu_Handler);
    
    while (
hResults.FetchRow())
    {
        if (++
iRank THE_AMOUNT_OF_PLAYERS_TO_ORDER)
            continue;
        
        
iPoints hResults.FetchInt(YOUR_COLUMN_NUMBER);
        
        
hResults.FetchString(YOUR_COLUMN_NUMBERsName256);
        
        
Format(sMenuContentsizeof(sMenuContent), "%s %d"sNameiPoints);
        
hMenu.AddItem(""sMenuContentITEMDRAW_DISABLED);
    }
    
    
hMenu.Display(iClientMENU_TIME_FOREVER);

mug1wara is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 08-02-2018 , 19:46   Re: Sorting players in order of value?
Reply With Quote #7

Quote:
Originally Posted by mug1wara View Post
or just like this :p
PHP Code:
public void SQL_Top(Database hDatabaseDBResultSet hResults, const char[] sErrorint iData)
{
    if (
hResults == null)
        
ThrowError(sError);
    
    
int iClient GetClientOfUserId(iData);
    
    
int iRankiPoints;
    
    
char sName[256], sMenuContent[256];
    
    
Menu hMenu = new Menu(Menu_Handler);
    
    while (
hResults.FetchRow())
    {
        if (++
iRank THE_AMOUNT_OF_PLAYERS_TO_ORDER)
            continue;
        
        
iPoints hResults.FetchInt(YOUR_COLUMN_NUMBER);
        
        
hResults.FetchString(YOUR_COLUMN_NUMBERsName256);
        
        
Format(sMenuContentsizeof(sMenuContent), "%s %d"sNameiPoints);
        
hMenu.AddItem(""sMenuContentITEMDRAW_DISABLED);
    }
    
    
hMenu.Display(iClientMENU_TIME_FOREVER);

Code:
top.sp(51) : error 017: undefined symbol "Menu_Handler"
PHP Code:
Menu hMenu = new Menu(Menu_Handler); 
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545
cristian20042 is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 08-02-2018 , 20:09   Re: Sorting players in order of value?
Reply With Quote #8

All right, can someone good enough make an example plugin please?
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545

Last edited by cristian20042; 08-02-2018 at 20:09.
cristian20042 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-02-2018 , 20:21   Re: Sorting players in order of value?
Reply With Quote #9

Did you just call me bad?

I thought you were going to do the menu callback at least. :/
mug1wara is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 08-02-2018 , 20:24   Re: Sorting players in order of value?
Reply With Quote #10

Quote:
Originally Posted by mug1wara View Post
Did you just call me bad?

I thought you were going to do the menu callback at least. :/
Some people don’t know how to take help when it’s given
Addicted. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode