AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   bubble sort (https://forums.alliedmods.net/showthread.php?t=99642)

biscuit628 08-07-2009 23:55

bubble sort
 
first of all, sorry for my poor english.

i need to use bubble sort(or other way you can help me) im my code.

it show a hud about top 3 killer before map change
Quote:

Name_Frags
PlayerA 60
PlayerB 40
PlayerC 33
but i don't know how to sort the frags

Bugsy 08-08-2009 00:42

Re: bubble sort
 
You will need to do the MOTD work on your own. This will print the topX in server console just for demonstration.
PHP Code:

//Declare array to store player frags for sorting
new g_PlayerFrags33 ][ ];

//Assign player data to array
g_PlayerFragsid ][ ] = id;
g_PlayerFragsid ][ ] = get_user_fragsid );

//Display
public DisplayInfo()
{
    new 
iPlayer szName33 ];

    
//Sort frags
    
SortCustom2Dg_PlayerFrags 33 "fn_StatsCompare" );

    
//If you want only top 3 use "i < 3" instead of "i < sizeof g_PlayerFrags"
    
for ( new sizeof g_PlayerFrags i++ )
    {
        
iPlayer g_PlayerFrags][ ];
    
        if ( 
is_user_connectediPlayer ) )
        {
            
get_user_nameiPlayer szName 32 );
            
server_print"Name: %s - Rank: %d - Frags: %d" szName i+1g_PlayerFrags][ ] );
        }
    }
}

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



biscuit628 08-08-2009 11:50

Re: bubble sort
 
i am trying to script like this
http://www.youtube.com/watch?v=q9bwz36rljM
it show the first/second/third...etc
but i don't know how to do this..
PHP Code:

public DisplayInfo()
{

    new 
iPlayer szName33 ];

    
//Sort frags
    
SortCustom2Dg_PlayerFrags 33 "fn_StatsCompare" );

    
//If you want only top 3 use "i < 3" instead of "i < sizeof g_PlayerFrags"
    
for ( new i++ )
    {
        
//Assign player data to array
        
g_PlayerFrags][ ] = get_user_frags);
        
iPlayer g_PlayerFrags][ ];
    
        if ( 
is_user_connectediPlayer ) )
        {
        
get_user_nameiPlayer szName[i] , 32 );
        
set_hudmessage(123,104,238,0.415,0.7,01.01.00.10.21)
        
show_hudmessage(0,"Name: %s - Rank: 1 - Frags: %d^nName: %s - Rank: 2 - Frags: %d^nName: %s - Rank: 3 - Frags: %d" szName[i] , g_PlayerFrags][ ],szName[i+1] , g_PlayerFragsi+][ ],szName[i+2] , g_PlayerFragsi+][ ] )
        }
    }



Bugsy 08-08-2009 11:57

Re: bubble sort
 
Quote:

Originally Posted by biscuit628 (Post 893468)
i am trying to script like this
http://www.youtube.com/watch?v=q9bwz36rljM
it show the first/second/third...etc
but i don't know how to do this..

I provided the method, it is up to you to implement it.

If you are unable to, post your plugin source w\ php tags and I will try to do it for you.

biscuit628 08-08-2009 13:29

Re: bubble sort
 
i try,,but still not work
the sort haven't update
PHP Code:

#include <amxmodx>



public plugin_init()
{
    
register_plugin("???","?","?")
    
set_task(1.0,"DisplayInfo",_,_,_,"b")
}

new 
g_PlayerFrags33 ][ ];



//Display
public DisplayInfo()
{
    new  
szName33 ],top[199]


    for ( new 
i++ )
    {
        if ( 
is_user_connected) )
        {
            
g_PlayerFrags][ ] = i
            g_PlayerFrags
][ ] = get_user_frags);
            
SortCustom2Dg_PlayerFrags 33 "fn_StatsCompare" );
            
get_user_nameszName 32 );
            
format(top,198,"%s ^nName: %s - Rank: %d - Frags: %d" ,topszName ig_PlayerFrags][ ]);
            
set_hudmessage(123,104,238,0.415,0.7,01.01.00.10.21)
            
show_hudmessage(0,"%s",top)
        }
    }
}


//format(top,99,"%s ^nName: %s - Rank: %d - Frags: %d" ,top, szName , i+1, Frags);
public fn_StatsCompareelem1[] , elem2[] )
{
    if( 
elem1[1] > elem2[1] ) 
        return -
1;
    else if( 
elem1[1] < elem2[1] )
        return 
1;
    
    return 
0;



Bugsy 08-08-2009 23:38

Re: bubble sort
 
Try this:

Edit: *correction made*
PHP Code:

#include <amxmodx>

#define PLUGIN     "Frag Rank HUD"
#define VERSION "1.0"
#define AUTHOR     "bugsy"

new g_PlayerFrags33 ][ ];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event"ScoreInfo" "fw_EvScoreInfo" "a" );
    
    
set_task0.5 "DisplayHUD" ___"b" );
}

public 
client_disconnectid )
{
    
g_PlayerFragsid ][ ] = 0;
    
g_PlayerFragsid ][ ] = 0;
}

public 
fw_EvScoreInfo()
{
    static 
idid read_data);
    
g_PlayerFragsid ][ ] = id;
    
g_PlayerFragsid ][ ] = read_data);
}

public 
DisplayHUDid )
{
    static 
iPlayer iFrags szName33 ];
    static 
iPlayerFrags33 ][ ];
    static 
szHUD512 ] , iPos;
    
    
iPlayerFrags g_PlayerFrags;
    
    
SortCustom2DiPlayerFrags 33 "fn_StatsCompare" );

    
iPos 0;
    for ( new 
sizeofg_PlayerFrags ) ; i++ )
    {
        
iPlayer iPlayerFrags][ ];
        
iFrags iPlayerFrags][ ];
        
        if ( 
is_user_connectediPlayer ) && iFrags )
        {
            
get_user_nameiPlayer szName 32 );
            
iPos += formatexszHUDiPos ] , 512-iPos "%s - Rank: %d - Frags: %d^n" szName i+1iFrags );
        }
    }
    
    if ( 
iPos )
    {
        
szHUDiPos ] = 0;
        
set_hudmessage85 255 0.05 0.15 0.0 1.0 )
        
show_hudmessageszHUD );
    }
}

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



biscuit628 08-09-2009 00:20

Re: bubble sort
 
little error
PHP Code:

public fw_EvScoreInfo() 

:arrow:
PHP Code:

public fw_EvScoreInfo(id

the plugin only show one line hud
and the frags sort also not correct

Bugsy 08-09-2009 00:27

Re: bubble sort
 
Quote:

Originally Posted by biscuit628 (Post 893968)
little error
PHP Code:

public fw_EvScoreInfo() 

:arrow:
PHP Code:

public fw_EvScoreInfo(id


ScoreInfo is a global event so id is not passed as a param. I made an erroneous edit to the code in my post and have since corrected it. This is why you may have assumed id was missing from the fw_EvScoreInfo param list. Re-try the code above.

Quote:

Originally Posted by biscuit628 (Post 893968)
the plugin only show one line hud
and the frags sort also not correct

It didn't work because of the above error/mistake.

biscuit628 08-09-2009 09:08

Re: bubble sort
 
100% work!! thanks!
+k

biscuit628 08-09-2009 15:02

Re: bubble sort
 
halo, i am trying to make it with ts top3 ct top3
but i think i am in a wrong way..
PHP Code:

public DisplayHUDid )
{
    static 
iPlayer iFrags szName33 ];
    static 
iPlayerFrags33 ][ ];
    static 
TSszHUD512 ] ,CTszHUD512 ], TSiPos,CTiPos
    
    iPlayerFrags 
g_PlayerFrags;
    
    
SortCustom2DiPlayerFrags 33 "fn_StatsCompare" );

    
TSiPos 0;
    
CTiPos 0
    
for ( new sizeofg_PlayerFrags ) ; i++ )
    {
        
iPlayer iPlayerFrags][ ];
        
iFrags iPlayerFrags][ ];
        
        if ( 
is_user_connectediPlayer ) && iFrags && get_user_team(iPlayer) == 1)
        {
            
get_user_nameiPlayer szName 32 );
            
TSiPos += formatexTSszHUDTSiPos ] , 512-TSiPos "Rank:%d - Frag:%d -Name:%s^n" i+1,iFrags,szName );
        }
    else if( 
is_user_connectediPlayer ) && iFrags && get_user_team(iPlayer) == 2)
        {
            
get_user_nameiPlayer szName 32 );
            
CTiPos += formatexCTszHUDCTiPos ] , 512-CTiPos "Rank:%d - Frag:%d -Name:%s^n" i+1,iFrags,szName );
        }
    }
    
    if ( 
TSiPos )
    {
        
TSszHUDTSiPos ] = 0;
        
set_hudmessage255 0.05 0.15 0.0 1.0 )
        
show_hudmessageTSszHUD );
    }
    if ( 
CTiPos )
    {
        
CTszHUDCTiPos ] = 0;
        
set_hudmessage255 0.75 0.15 0.0 1.0 )
        
show_hudmessageCTszHUD );
    }




All times are GMT -4. The time now is 18:28.

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