Raised This Month: $51 Target: $400
 12% 

Solved Sorting Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 03-02-2018 , 15:28   Sorting Problem
Reply With Quote #1

I am trying thing to do with sort but I still don't understand how to use it.

PHP Code:
enum
{
    
PLAYER_ID 0,
    
PLAYER_SCORE
}
//Testing
Player_Score[0] = 100
Player_Score
[1] = 200
Player_Score
[2] = 300
...
Player_Score[32] = 3300

...

//Begin Sorting
public SortKills()
{
    new 
iCount 0
    
for(new i=0sizeof(Player_Score); i++)
    {
        
Ranking[iCount][PLAYER_ID] = i
        Ranking
[iCount][PLAYER_SCORED] = Player_Score[i]
        
iCount++
    }

    
SortCustom2D(Ranking iCount"SortKills_Sort")
}

public 
SortKills_Sort(iElem1[], iElem2[])
{
    new 
iKills1 iElem1[PLAYER_SCORED]
    new 
iKills2 iElem2[PLAYER_SCORED]

    if(
iKills1 iKills2)
        return -
1
    
else if(iKills1 iKills2)
        return 
1
    
    
return 0

After that, I make a test function
PHP Code:
public test_fuction(id)
{
    new 
name[33][33]
    for(new 
i=0i<sizeof(name); i++)
    {
        if(
is_user_connected(Ranking[i][PLAYER_ID]))
        {
            
get_user_name(Ranking[i][PLAYER_ID], name[i], sizeof(name[]))
        }
        else
        {
            
formatex(name[i], sizeof(name[]), "NONE")
        }
    }
    
client_print(idprint_chat"Rank 1:%i || Rank 2:%i || Rank 3: %i"Ranking[0][PLAYER_SCORED], Ranking[1][PLAYER_SCORED], Ranking[2][PLAYER_SCORED])
    
client_print(idprint_chat"Rank 1:%s || Rank 2:%s || Rank 3: %s"name[0], name[1], name[2])


But the score is all 0 and the name is all NONE

Please help

P/S: I did search but I still don't understand how to use it.
__________________
My plugin:

Last edited by Celena Luna; 03-09-2018 at 16:37.
Celena Luna is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 03-02-2018 , 16:18   Re: Sorting Problem
Reply With Quote #2

You must to use a save data to make a rank or top 15... like fvault, nvault, adv_vault....

Last edited by Saint Sinner; 03-02-2018 at 16:19.
Saint Sinner is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-02-2018 , 17:40   Re: Sorting Problem
Reply With Quote #3

PHP Code:
#include <amxmodx>

new Top15Player[33][2];

enum
{
    
ID,
    
KILLS
}

public 
plugin_init()
{
    
register_clcmd("say /top15fraggers""show_top15fraggers")
}

public 
show_top15fraggers(id)
{
    
GetTop15PlayerInGame();
    
    new 
motd[1024], iLen;
    
    
iLen formatex(motdcharsmax(motd), "<!DOCTYPE HTML><html><head><title>Top15Fraggers</title></head><body>");
    
    new 
players[32], pnum;
    
get_players(playerspnum"h");
    
    if( 
pnum 15 pnum 15;
    
    for(new 
iszName[32]; pnumi++)
    {
        
get_user_name(Top15Player[i][ID], szNamecharsmax(szName))
        
iLen += formatex(motd[iLen], charsmax(motd)-iLen"<p>%d. %s with %d Kills!</p><br>"i+1szNameTop15Player[i][KILLS]);
    }
    
    
iLen += formatex(motd[iLen], charsmax(motd)-iLen"</body></html>");
    
    
show_motd(idmotd"Top15 Fraggers InGame!");
}

GetTop15PlayerInGame()
{
    for(new 
zsizeof Top15Playerz++) arrayset(Top15Player[z], 0sizeof Top15Player[]);
    
    new 
players[32], pnum;
    
get_players(playerspnum"h");
    
    for(new 
iplayerpnumi++)
    {
        
player players[i];
        
Top15Player[i][ID] = player;
        
Top15Player[i][KILLS] = get_user_frags(player);
    }
    
    
SortCustom2D(Top15Playersizeof Top15Player"MySortFunc");
}

public 
MySortFunc(const elem1[], const elem2[], const array[], data[], data_size)
{
    if(
elem1[ID] == && elem2[ID] == 0) return 0;
    if(
elem1[ID] == 0) return 1;
    if(
elem2[ID] == 0) return -1;
    if(
elem1[KILLS] > elem2[KILLS]) return -1;
    if(
elem1[KILLS] < elem2[KILLS]) return 1;
    return 
0;

This code will retrieve the top15 fraggers connected!!!

try to understand the code. its so simple
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-02-2018 at 18:17.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 03-09-2018 , 16:37   Re: Sorting Problem
Reply With Quote #4

I managed to make it work. Thank ^^
__________________
My plugin:
Celena Luna 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 02:37.


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