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 iPlayers[ 32 ] , iNum , id , iFrags , iTeam;
new T_Frags[ 33 ][ 2 ];
new CT_Frags[ 33 ][ 2 ];
get_players( iPlayers , 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 i = 0 ; i < iNum ; i++ )
{
id = iPlayers[ i ];
iFrags = get_user_frags( id );
iTeam = _:cs_get_user_team( id );
switch ( iTeam )
{
case CS_TEAM_T:
{
T_Frags[ id ][ 0 ] = id;
T_Frags[ id ][ 1 ] = iFrags;
}
case CS_TEAM_CT:
{
CT_Frags[ id ][ 0 ] = id;
CT_Frags[ id ][ 1 ] = iFrags;
}
}
}
SortCustom2D( T_Frags , 33 , "fn_StatsCompare" );
SortCustom2D( CT_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 szName[ 33 ];
for ( new p = 0 ; p < 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[ p ][ 0 ];
//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_name( id , szName , 32 );
client_print( 0 , print_chat , "%s has %d frags. Ranked #%d on his team." , szName , T_Frags[ p ][ 1 ] , p+1 );
}
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_StatsCompare( elem1[] , elem2[] )
{
if( elem1[1] > elem2[1] )
return -1;
else if( elem1[1] < elem2[1] )
return 1;
return 0;
}
__________________