AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to count team players (https://forums.alliedmods.net/showthread.php?t=120365)

xakintosh 03-04-2010 03:34

How to count team players
 
Simple question i found 1/2 forum threads but not helped me.
Something like this: CT %s vs T %s

Xellath 03-04-2010 05:20

Re: How to count team players
 
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.

xakintosh 03-04-2010 05:32

Re: How to count team players
 
Thx :)

Bugsy 03-04-2010 08:53

Re: How to count team players
 
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;




All times are GMT -4. The time now is 08:41.

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