Raised This Month: $ Target: $400
 0% 

sorting floats+id


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2018 , 17:14   Re: sorting floats+id
Reply With Quote #3

Made slight tweaks to this
PHP Code:

#include <amxmodx>

#define MAX_PLAYERS 32

new Float:g_PlayerFragsMAX_PLAYERS ][ ];

public 
plugin_init() 
{
    
//Load player data in array
    // g_PlayerFrags[][ 0 ] = player id
    // g_PlayerFrags[][ 1 ] = float value
    
    
g_PlayerFrags][ ] = Float:3;
    
g_PlayerFrags][ ] = 5.6;
    
    
g_PlayerFrags][ ] = Float:2;
    
g_PlayerFrags][ ] = 3.4;
    
    
g_PlayerFrags][ ] = Float:1;
    
g_PlayerFrags][ ] = 1.2;
    
    
DisplayInfo();
}

public 
DisplayInfo()
{
    new 
iPlayer;

    
SortCustom2D_:g_PlayerFrags sizeofg_PlayerFrags ) , "SortCompare" );

    for ( new 
sizeofg_PlayerFrags ) ; i++ )
    {
        
iPlayer _:g_PlayerFrags][ ];
    
        
//Get players name, or whatever
        //get_user_name( iPlayer , szName , charsmax( szName ) );
        
        
server_print"id=%d - Rank: %d - Frags: %f" iPlayer i+g_PlayerFrags][ ] );
    }
}

public 
SortCompareFloat:elem1[] , Float:elem2[] )
{
    if( 
elem1[1] > elem2[1] ) 
        return -
1;
    else if( 
elem1[1] < elem2[1] )
        return 
1;
    
    return 
0;

__________________

Last edited by Bugsy; 11-25-2018 at 17:30.
Bugsy is offline
 



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 07:29.


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