Quote:
Originally Posted by SnoW
What is the reasoning for such a difficult syntax? The function should return the value so it can be used for initialization and possibly in a straight comparison without using a variable at all. The using of the "id" variable is totally unnecessary. I see no advantage in using clamp, specify please.
|
- Clamp: Just to make sure the alive parameter was within range. I suppose I will change this and just change 0 to default in the switch.
- id: I agree. Changed and fixed. It was like that because it was structured differently in the past and we forgot to change it.
- Syntax: The function was created to be similar to get_players(), since it is replacing its usage due to bugs in the original. I did this because the number is stored with a byref param in get_players() as well, so I figured it would be nice if it was structured similarly.
EDIT: Restructured since apparently following an example is difficult.
Code:
/**
* Gets amount of players on a certain team (since get_players is buggy)
*
* @param iTeam Team to get
* @param alive 0 | Get all players on team (default)
* 1 | Get alive players on team
* -1 | Get dead players
*/
stock GET_Users_Team( CsTeams:iTeam, alive=0 )
{
new num
new iPlayers[32]
new iNum
switch( alive )
{
case -1: get_players( iPlayers, iNum, "b" )
case 1: get_players( iPlayers, iNum, "a" )
default: get_players( iPlayers, iNum )
}
for( new i = 0; i < iNum; i++ )
{
if( cs_get_user_team( iPlayers[i] ) == iTeam )
{
num++
}
}
return num;
}
Example usage:
Code:
new iDeadTerrorists = GET_Users_Team( CS_TEAM_T, -1 )
__________________