AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   return amount of players in CT / T (https://forums.alliedmods.net/showthread.php?t=147208)

Pantheon 01-06-2011 13:46

return amount of players in CT / T
 
Like the title says; Is there a way to return the amount of players in each team?

MyDooMJr 01-06-2011 14:00

Re: return amount of players in CT / T
 
Humm yes, there's a way to return the amount of players, but nice idea, i think i know how to make it , it's look simple , but i'm at firsts steps so you will wait like me for an AMXX #1337# Coder answer this :)

reinert 01-06-2011 14:45

Re: return amount of players in CT / T
 
create 2 arrays for each team...

then use get_players() and cs_get_user_team()

wrecked_ 01-06-2011 14:59

Re: return amount of players in CT / T
 
Code:
/**  * Gets amount of players on a certain team (since get_players is buggy)  *  * @param &num    Number to store amount in  * @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( &num, CsTeams:iTeam, alive=0 ) {     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++         }     } }
Example usage:
Code:
new iDeadTerrorists GET_Users_Team( iDeadTerrorists, CS_TEAM_T, -1 )

Pantheon 01-06-2011 15:05

Re: return amount of players in CT / T
 
Quote:

Originally Posted by reinert (Post 1387554)
create 2 arrays for each team...

then use get_players() and cs_get_user_team()

Could you post an example?

EDIT: Thanks wrecked_

ARES[ro] 01-06-2011 15:06

Re: return amount of players in CT / T
 
Quote:

Originally Posted by Pantheon (Post 1387571)
Could you post an example?

Quote:

Originally Posted by wrecked_ (Post 1387568)
Code:
/**
* Gets amount of players on a certain team (since get_players is buggy)
*
* @param &num Number to store amount in
* @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( &num, CsTeams:iTeam, alive=0 ) { new iPlayers[32] new iNum

switch( clamp( alive, -1, 1 ) ) { case -1: get_players( iPlayers, iNum, "b" ) case 0: get_players( iPlayers, iNum ) case 1: get_players( iPlayers, iNum, "a" ) } new id
for( new i = 0; i < iNum; i++ ) { id = iPlayers[i] if( cs_get_user_team( id ) == iTeam ) { num++ } } }


Example usage:
Code:
new iDeadTerrorists
GET_Users_Team( iDeadTerrorists, CS_TEAM_T, -1 )



SnoW 01-06-2011 15:25

Re: return amount of players in CT / T
 
Quote:

Originally Posted by wrecked_ (Post 1387568)
Code:
/**  * Gets amount of players on a certain team (since get_players is buggy)  *  * @param &num    Number to store amount in  * @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( &num, CsTeams:iTeam, alive=0 ) {     new iPlayers[32]     new iNum         switch( clamp( alive, -1, 1 ) )     {         case -1: get_players( iPlayers, iNum, "b" )         case 0:  get_players( iPlayers, iNum )         case 1:  get_players( iPlayers, iNum, "a" )     }         new id     for( new i = 0; i < iNum; i++ )     {         id = iPlayers[i]                 if( cs_get_user_team( id ) == iTeam )         {             num++         }     } }
Example usage:
Code:
new iDeadTerrorists GET_Users_Team( iDeadTerrorists, CS_TEAM_T, -1 )

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.

Pantheon 01-06-2011 15:27

Re: return amount of players in CT / T
 
PHP Code:

public client_connect(id) {
    new 
iAmountTerrorists
    
new iGetUsersT get_users_team(iAmountTerroristsCS_TEAM_T0)
    
    if (
iGetUsersT 1) {
        
cs_set_user_team(idCS_TEAM_CTCS_DONTCHANGE)
    }


I get an warning from this.

"get_users_team should return a value"

SnoW 01-06-2011 15:31

Re: return amount of players in CT / T
 
Quote:

Originally Posted by Pantheon (Post 1387590)
PHP Code:

public client_connect(id) {
    new 
iAmountTerrorists
    
new iGetUsersT get_users_team(iAmountTerroristsCS_TEAM_T0)
    
    if (
iGetUsersT 1) {
        
cs_set_user_team(idCS_TEAM_CTCS_DONTCHANGE)
    }


I get an warning from this.

"get_users_team should return a value"

A good example of the difficult syntax of the function.

wrecked_ 01-06-2011 15:32

Re: return amount of players in CT / T
 
Quote:

Originally Posted by SnoW (Post 1387589)
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 )


All times are GMT -4. The time now is 02:14.

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