Raised This Month: $ Target: $400
 0% 

How to count team players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 03-04-2010 , 03:34   How to count team players
Reply With Quote #1

Simple question i found 1/2 forum threads but not helped me.
Something like this: CT %s vs T %s
__________________
As soon as possible.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 03-04-2010 , 05:20   Re: How to count team players
Reply With Quote #2

Code:
#include < amxmodx > #include < cstrike > public example_function( id ) {     new iCTPlayers = GetPlayerCount( CS_TEAM_CT ),         iTPlayers = GetPlayerCount( CS_TEAM_T );             client_print( 0, print_chat, "CT %i - T %i", iCTPlayers, iTPlayers ); } GetPlayerCount( CsTeams:iTeam ) {     new szPlayers[ 32 ], iPlayerCount;     get_players( szPlayers, iPlayerCount, "e", iTeam == CS_TEAM_CT ? "CT" : "TERRORIST" );         return iPlayerCount; }

This may return incorrect results sometime because the "e" flag is known to be buggy.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 03-04-2010 , 05:32   Re: How to count team players
Reply With Quote #3

Thx
__________________
As soon as possible.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-04-2010 , 08:53   Re: How to count team players
Reply With Quote #4

If you get false results with the above function or want to retrieve counts for Unassigned\Spectator, use one of these.

With this function you can retrieve CS_TEAM_UNASSIGNED, CS_TEAM_T, CS_TEAM_CT, or CS_TEAM_SPECTATOR.
PHP Code:
public TeamCheck()
{
    new 
iUnassigned GetPlayerCountCS_TEAM_UNASSIGNED ) ,
              
iT GetPlayerCountCS_TEAM_T ) ,
             
iCT GetPlayerCountCS_TEAM_CT ) , 
           
iSpec GetPlayerCountCS_TEAM_SPECTATOR );
           
    
server_print"U=%d T=%d CT=%d Spec=%d" iUnassigned iT iCT iSpec );
}

GetPlayerCountCsTeams:iTeam )
{
    new 
iPlayers32 ] , iPlayerCount;
    new 
iTeamPlayersCsTeams ];
    
    
get_playersiPlayers iPlayerCount ); 
    
    for ( new 
iPlayerCount i++ )
        
iTeamPlayerscs_get_user_teamiPlayers] ) ]++;
  
    return 
iTeamPlayersiTeam ];

With this one, you can retrieve number of Unassigned , T , CT , and Spectator with a single call by passing an array sized at CsTeams (4). Just make sure that the array you pass to the function contains all 0's {0,0,0,0} since this is passed byref.
PHP Code:
public TeamCheck()
{
    new 
iTeamsCsTeams ];
    
GetPlayerCount2iTeams );

    
server_print"U=%d T=%d CT=%d Spec=%d" iTeamsCS_TEAM_UNASSIGNED ] , 
                          
iTeamsCS_TEAM_T ] ,
                          
iTeamsCS_TEAM_CT ] ,
                          
iTeamsCS_TEAM_SPECTATOR ] );
}

GetPlayerCount2iTeamPlayersCsTeams ] )
{
    new 
iPlayers32 ] , iPlayerCount;
    
    
get_playersiPlayers iPlayerCount ); 
    
    for ( new 
iPlayerCount i++ )
        
iTeamPlayerscs_get_user_teamiPlayers] ) ]++;

You can also extend functionality for all teams with the Xellalths function like this. Usage is the same.
PHP Code:
GetPlayerCountCsTeams:iTeam )
{
    new 
iPlayers32 ], iPlayerCount;
    new 
szTeamsCsTeams ][] = 
    {
        
"UNASSIGNED",
        
"TERRORIST",
        
"CT",
        
"SPECTATOR"
    
}
    
    
get_playersiPlayers iPlayerCount "e" szTeamsiTeam ] );
    
    return 
iPlayerCount;

__________________

Last edited by Bugsy; 03-04-2010 at 09:26.
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 08:41.


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