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 = GetPlayerCount( CS_TEAM_UNASSIGNED ) ,
iT = GetPlayerCount( CS_TEAM_T ) ,
iCT = GetPlayerCount( CS_TEAM_CT ) ,
iSpec = GetPlayerCount( CS_TEAM_SPECTATOR );
server_print( "U=%d T=%d CT=%d Spec=%d" , iUnassigned , iT , iCT , iSpec );
}
GetPlayerCount( CsTeams:iTeam )
{
new iPlayers[ 32 ] , iPlayerCount;
new iTeamPlayers[ CsTeams ];
get_players( iPlayers , iPlayerCount );
for ( new i = 0 ; i < iPlayerCount ; i++ )
iTeamPlayers[ cs_get_user_team( iPlayers[ i ] ) ]++;
return iTeamPlayers[ iTeam ];
}
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 iTeams[ CsTeams ];
GetPlayerCount2( iTeams );
server_print( "U=%d T=%d CT=%d Spec=%d" , iTeams[ CS_TEAM_UNASSIGNED ] ,
iTeams[ CS_TEAM_T ] ,
iTeams[ CS_TEAM_CT ] ,
iTeams[ CS_TEAM_SPECTATOR ] );
}
GetPlayerCount2( iTeamPlayers[ CsTeams ] )
{
new iPlayers[ 32 ] , iPlayerCount;
get_players( iPlayers , iPlayerCount );
for ( new i = 0 ; i < iPlayerCount ; i++ )
iTeamPlayers[ cs_get_user_team( iPlayers[ i ] ) ]++;
}
You can also extend functionality for all teams with the Xellalths function like this. Usage is the same.
PHP Code:
GetPlayerCount( CsTeams:iTeam )
{
new iPlayers[ 32 ], iPlayerCount;
new szTeams[ CsTeams ][] =
{
"UNASSIGNED",
"TERRORIST",
"CT",
"SPECTATOR"
}
get_players( iPlayers , iPlayerCount , "e" , szTeams[ iTeam ] );
return iPlayerCount;
}
__________________