Raised This Month: $ Target: $400
 0% 

return amount of players in CT / T


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pantheon
Member
Join Date: Jan 2011
Old 01-06-2011 , 13:46   return amount of players in CT / T
Reply With Quote #1

Like the title says; Is there a way to return the amount of players in each team?
Pantheon is offline
MyDooMJr
Member
Join Date: Jun 2009
Location: Portugal
Old 01-06-2011 , 14:00   Re: return amount of players in CT / T
Reply With Quote #2

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
MyDooMJr is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-06-2011 , 14:45   Re: return amount of players in CT / T
Reply With Quote #3

create 2 arrays for each team...

then use get_players() and cs_get_user_team()
reinert is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 01-06-2011 , 14:59   Re: return amount of players in CT / T
Reply With Quote #4

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 )
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 01-06-2011 at 15:32.
wrecked_ is offline
Pantheon
Member
Join Date: Jan 2011
Old 01-06-2011 , 15:05   Re: return amount of players in CT / T
Reply With Quote #5

Quote:
Originally Posted by reinert View Post
create 2 arrays for each team...

then use get_players() and cs_get_user_team()
Could you post an example?

EDIT: Thanks wrecked_
Pantheon is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 01-06-2011 , 15:06   Re: return amount of players in CT / T
Reply With Quote #6

Quote:
Originally Posted by Pantheon View Post
Could you post an example?
Quote:
Originally Posted by wrecked_ View Post
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 )

__________________
okay
ARES[ro] is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 15:25   Re: return amount of players in CT / T
Reply With Quote #7

Quote:
Originally Posted by wrecked_ View Post
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.
SnoW is offline
Send a message via MSN to SnoW
Pantheon
Member
Join Date: Jan 2011
Old 01-06-2011 , 15:27   Re: return amount of players in CT / T
Reply With Quote #8

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"
Pantheon is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 15:31   Re: return amount of players in CT / T
Reply With Quote #9

Quote:
Originally Posted by Pantheon View Post
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.
SnoW is offline
Send a message via MSN to SnoW
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 01-06-2011 , 15:32   Re: return amount of players in CT / T
Reply With Quote #10

Quote:
Originally Posted by SnoW View Post
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 )
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 01-06-2011 at 15:42.
wrecked_ 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 02:14.


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