Raised This Month: $ Target: $400
 0% 

Get players with highest frags on each team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 11-22-2009 , 02:29   Get players with highest frags on each team
Reply With Quote #1

Hello there,

i've run into the problem that i dont know how to code this:

i want to get a specific player id from a specific team.
i try to explain a bit more.

let us say my server runs with 6:6 players on

6 are on ct side and 6 on terror side

so now i use in my plugin some functions to check things
on function checks the score for each team and log this to MySQL

now i want it so that the first or the first 2 players for a specific team
should be checked with some other stuffs.

but not randomly. need the exact first 2 player id's maybe more with a cvar like:

amx_check_teamplayers 1

but this is not important i know that kind of code. i need just help
to getting the first 1 till X amount of players with the highest frags (like in scoreboard) for specific team
that the function will return (like: CT or T but this can change everyround)

hope u understand what i try to explain here lol
thanks

Last edited by platzpatrone; 11-24-2009 at 21:03. Reason: better Thread Title :)
platzpatrone is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-22-2009 , 18:15   Re: help getting specific player id
Reply With Quote #2

I have an idea of how to do it but the number of players per team that you want to retrieve would be hard coded (one would be easiest ).
__________________
fysiks is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 11-22-2009 , 18:46   Re: help getting specific player id
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
I have an idea of how to do it but the number of players per team that you want to retrieve would be hard coded (one would be easiest ).
well this is not a problem if it is hardcoded, im happy with any idea to
get this running lol
platzpatrone is offline
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
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 11-22-2009 , 22:27   Re: help getting specific player id
Reply With Quote #5

thank you, but i have some questions just to know if im right:

for this loop
PHP Code:
for ( new 15 p++ ) 
the 15 is for players currently playing on server or is it for max players the server can handle ?

like if i run a 20 slot server i have to change it to 19 or is it like
i run a 20 slot server but 16 are playing on it so i have to set it to 15 ?

very confusing lol

and if i just want the #1 ranked player so i can use just:

PHP Code:
client_printprint_chat "%s has %d frags. and is the best ranked player on his team." szName T_Frags][ ] ); 
platzpatrone is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-22-2009 , 23:51   Re: help getting specific player id
Reply With Quote #6

Quote:
Originally Posted by platzpatrone View Post
thank you, but i have some questions just to know if im right:

for this loop
PHP Code:
for ( new 15 p++ ) 
the 15 is for players currently playing on server or is it for max players the server can handle ?
I just used 15 as an example, replace it with whatever number of players for that team you want to display\manipulate. If you want to manipulate\display all players connected to the server then use get_maxplayers() value instead of 15 and if you want it to display only the top 3, change it to 3.

Quote:
Originally Posted by platzpatrone View Post
like if i run a 20 slot server i have to change it to 19 or is it like
i run a 20 slot server but 16 are playing on it so i have to set it to 15 ?

very confusing lol
Again, 15 is just a random number I used for example. You can leave it at fifteen and it will display from 1-15 players on each team; if there are less than 15 then it will display only that many (if you make sure to check if a player id is held in the [C]T_Frags[ X ][ 0 ] array element, break\exit loop otherwise). If there are more than 15 players on a given team then players 16+ will not get recognized\displayed.

Quote:
Originally Posted by platzpatrone View Post
and if i just want the #1 ranked player so i can use just:

PHP Code:
client_printprint_chat "%s has %d frags. and is the best ranked player on his team." szName T_Frags][ ] ); 
Make sure you check that a player id is held in the [C]T_Frags[][] array before attempting to use get_user_name, get_user_authid, etc. Example, suppose there are only 2 Terrorists currently playing and you attempt to do get_user_name( T_Frags[ 2 ][ 0 ] , szName , 32 ) then you will get an error because that value will be 0 which means there is no player id held in that slot. If you do a simple if ( T_Frags[ X ][ 0 ] ) check then you will be good to go. Refer to my code above where you see if ( id ). I added a more thorough explanation to help you understand.

Use:
PHP Code:
new szName33 ];
get_user_nameT_Frags][ ] , szName 32 );
client_printprint_chat "%s has %d frags. and is the best ranked player on his team." szName T_Frags][ ] ); 
Rank 1 Terrorist
id = T_Frags[ 0 ][ 0 ]
frags = T_Frags[ 0 ][ 1 ]

Rank 1 CT
id = CT_Frags[ 0 ][ 0 ]
frags = CT_Frags[ 0 ][ 1 ]

I hope this helps, if you are unsure of anything let me know.
__________________

Last edited by Bugsy; 11-23-2009 at 00:06.
Bugsy is offline
Reply



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