AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Solved Sort order is mixing sometimes (https://forums.alliedmods.net/showthread.php?t=331907)

tepegoz 04-12-2021 11:28

Sort order is mixing sometimes
 
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


Bugsy 04-12-2021 17:54

Re: Sort order is mixing sometimes
 
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



tepegoz 04-13-2021 09:30

Re: Sort order is mixing sometimes
 
thank you very much.


All times are GMT -4. The time now is 19:55.

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