Raised This Month: $231 Target: $400
 57% 

Solved Sort order is mixing sometimes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tepegoz
Senior Member
Join Date: Apr 2019
Old 04-12-2021 , 11:28   Sort order is mixing sometimes
Reply With Quote #1

I have this code but sometimes sort order is mixing for public displayasdls(id).
Example:

Nick1 - 10
Nick2 - 9
Nick3 - 8
Nick4 - 7
Nick5 - 6

But sometime showing this type:
Nick5 - 6
Nick4 - 7
Nick1 - 10
Nick3 - 8
Nick2 - 9

can you fix this problem or can you convert this script ?
PHP Code:
public displayasdls(id)
{
        new 
teals[1025];
        new 
len 0ix;
        new 
temp_name[64];
        new 
tealrecord[33];
        new 
namerecord[64][64];
        
tealrecord[0]=0;
        for(
i=1;i<=maxplayers;i++)
        {
            if(!
is_user_bot(i) &&  !is_user_hltv(i) && is_user_connected(i)){        
                
tealrecord[i]=MaleRecord[i][TEAL];
                
get_user_name(inamerecord[i], 13)
            }
        }
        
            for(
i=1;i<=maxplayers;i++)
            {
                if(
tealrecord[i]>tealrecord[i-1])
                {
                    
x=tealrecord[i];
                    
tealrecord[i]=tealrecord[i-1];
                    
tealrecord[i-1]=x;
                    
temp_name=namerecord[i];
                    
namerecord[i]=namerecord[i-1];
                    
namerecord[i-1]=temp_name;
                }

        }
        
len += format(steals[len], 512-len"TOP TEAL^n^n")
        
len += format(steals[len], 512-len"%s  -  %i^n",namerecord[0], tealrecord[0])
        
len += format(steals[len], 512-len"%s  -  %i^n",namerecord[1], tealrecord[1])
        
len += format(steals[len], 512-len"%s  -  %i^n",namerecord[2], tealrecord[2])
        
len += format(steals[len], 512-len"%s  -  %i^n",namerecord[3], tealrecord[3])
        
len += format(steals[len], 512-len"%s  -  %i",namerecord[4], tealrecord[4])
        
        
set_dhudmessage(02550,  0.380.000.23.00.20.1)
        
show_dhudmessage(id"%s"teals)

PHP Code:
new MaleRecord[MAX_PLAYER 1][RECORDS+1

Last edited by tepegoz; 04-16-2021 at 13:59.
tepegoz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-12-2021 , 17:54   Re: Sort order is mixing sometimes
Reply With Quote #2

Your sort logic is bad, I would use SortCustom2D(). Untested and might need some tweaks.

PHP Code:
public displayasdls(id)
{
    
enum _:RankData
    
{
        
RankID,
        
RankValue
    
}
    
    const 
MaxToRank 5;
    
    new 
steals1025 ] , len;
    new 
rdDataMAX_PLAYERS 1] [ RankData ];
    new 
iPlayers32 ] , iNum iPlayer szName32 ] , iNumRanked;
    
    
get_playersiPlayers iNum "ch" );
    for ( 
iNum i++ )
    {    
        
iPlayer iPlayers];
        
        
rdData][ RankID ] = iPlayer;
        
rdData][ RankValue ] = MadeRecordiPlayer ][ STEAL ];
    }
    
    
SortCustom2D_:rdData iNum "SortCompare" );
    
    
iNumRanked miniNum MaxToRank );

    
len copy(stealscharsmaxsteals ) , "TOP STEAL^n^n")
    
    for ( 
iNumRanked i++ ) 
    {
        
get_user_namerdData][ RankID ] , szName charsmaxszName ) );
        
len += formatexstealslen ] , charsmaxsteals )-len"%s  -  %i^n" szName rdData][ RankValue ] )
    }
    
    
set_dhudmessage(02550,  0.380.000.23.00.20.1)
    
show_dhudmessage(idsteals)
}

public 
SortCompareelem1[] , elem2[] ) 

    if ( 
elem1] > elem2] ) 
        return -
1
    else if(
elem1] < elem2] ) 
        return 
1
    else
        return 
0

__________________

Last edited by Bugsy; 04-12-2021 at 23:44.
Bugsy is offline
tepegoz
Senior Member
Join Date: Apr 2019
Old 04-13-2021 , 09:30   Re: Sort order is mixing sometimes
Reply With Quote #3

thank you very much.
tepegoz is offline
Reply


Thread Tools
Display Modes

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


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