Raised This Month: $ Target: $400
 0% 

Get players with highest frags on each team


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-22-2009 , 21:10   Re: help getting specific player id
Reply With Quote #4

This should work, let me know if you have any questions. This will place player id's in order from highest frag count to lowest in order for each team. T_Frags holds terrorist while CT_Frags holds counter-terrorist. T_Frags[ # ][ 0 ] holds player id while T_Frags[ # ][ 1 ] holds the number of frags for that player. Remember, array index starts at 0 so T_Frags[ 0 ][ 0 ] holds the first (highest frag) player id and T_Frags[ 0 ][ 1 ] holds his frags.

If you are not using cstrike module, add the below code and replace cs_get_user_team with get_user_team.
PHP Code:
enum _:Teams
{
    
CS_TEAM_T 1,
    
CS_TEAM_CT

PHP Code:
public GetHighestScore()
{
    new 
iPlayers32 ] , iNum id iFrags iTeam;
    new 
T_Frags33 ][ ]; 
    new 
CT_Frags33 ][ ]; 
    
    
get_playersiPlayers iNum );

    
//This will loop through all connected players and assign their player id and frags to the array for the appropriate team.
    //Once the arrays are filled with player data they will then be sorted.

    //Array[ id ][ 0 ] = id
    //Array[ id ][ 1 ] = frags
    
for ( new iNum i++ )
    {
        
id iPlayers];
        
iFrags get_user_fragsid );
        
iTeam _:cs_get_user_teamid );
        
        switch ( 
iTeam )
        {
            case 
CS_TEAM_T
            {
                
T_Fragsid ][ ] = id;
                
T_Fragsid ][ ] = iFrags;
            }
            case 
CS_TEAM_CT:
            {
                
CT_Fragsid ][ ] = id;
                
CT_Fragsid ][ ] = iFrags;            
            }
        }    
    }
    
    
SortCustom2DT_Frags 33 "fn_StatsCompare" );
    
SortCustom2DCT_Frags 33 "fn_StatsCompare" );
    
    
//The arrays now each hold player data in order in each respective team array.
    //To retrieve the highest frag players in order, loop from 0 to max-1.
    //Below is a 1 - 15 example for loop
    
new szName33 ];
    for ( new 
15 p++ )
    {
        
//Get player id from array. Since we are using the value more than once it is better
        //to store the array value in a variable.
        
id T_Frags][ ];

        
//Check if a player id is held before doing anything else (getting name, steam id, or whatever else)
        //As you can see above, our T_Frags\CT_Frags are sized large enough to handle the max possible player id of 32 [size=33]. 
        //This does not mean that our arrays will always be full of valid player id's so we must always check to see if a player
        //id is held in the array slot before attempting to call any functions on that player. If at any time we find that the id
        //in the array slot is 0 then we can exit the loop because that means there are no players from that point on.
        
if ( id 
        {
            
get_user_nameid szName 32 );
            
client_printprint_chat "%s has %d frags. Ranked #%d on his team." szName T_Frags][ ] , p+);
        }
        else
        {
            
//id is 0 which means from the current array element up to 32 are all 0\empty so we can
            //exit the for loop
            
break;
        }
    }

    
/*
    #1 Terrorist playerid = T_Frags[ 0 ][ 0 ] , frags = T_Frags[ 0 ][ 1 ]
    #2 Terrorist playerid = T_Frags[ 1 ][ 0 ] , frags = T_Frags[ 1 ][ 1 ]
    #3 Terrorist playerid = T_Frags[ 2 ][ 0 ] , frags = T_Frags[ 2 ][ 1 ]
    
    #1 CT playerid = CT_Frags[ 0 ][ 0 ] , frags = CT_Frags[ 0 ][ 1 ]
    #2 CT playerid = CT_Frags[ 1 ][ 0 ] , frags = CT_Frags[ 1 ][ 1 ]
    #3 CT playerid = CT_Frags[ 2 ][ 0 ] , frags = CT_Frags[ 2 ][ 1 ]*/
}

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

__________________

Last edited by Bugsy; 11-23-2009 at 00:03.
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 13:43.


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