Raised This Month: $ Target: $400
 0% 

Count players of a team?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MasterKy
Junior Member
Join Date: Aug 2009
Old 08-25-2009 , 15:28   Count players of a team?
Reply With Quote #1

How to count players of a team and print the total?
ex:

There are %s terrorists!

plz, help me!
MasterKy is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-25-2009 , 16:04   Re: Count players of a team?
Reply With Quote #2

PHP Code:
new players[32],num,id
get_players
(playersnum)

new 
count_tcount_ct

for (new i=0;i<num;i++)
{
  switch (
cs_get_user_team(players[i]))
{
  case 
CS_TEAM_Tcount_t++;
  case 
CS_TEAM_CTcount_ct++;
}

client_print(0print_chat"TERO: %d"count_t)
client_print(0print_chat"CT: %d"count_ct)

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-25-2009 , 20:47   Re: Count players of a team?
Reply With Quote #3

Quote:
Originally Posted by ot_207 View Post
PHP Code:
new players[32],num,id
get_players
(playersnum)

new 
count_tcount_ct

for (new i=0;i<num;i++)
{
  switch (
cs_get_user_team(players[i]))
{
  case 
CS_TEAM_Tcount_t++;
  case 
CS_TEAM_CTcount_ct++;
}

client_print(0print_chat"TERO: %d"count_t)
client_print(0print_chat"CT: %d"count_ct)

Just 2 minor typo's:
- client_print's are within the loop - I can't tell if this was intended because of the indentation (or lack, thereof)
- variable id is never used

PHP Code:
new players[32] , num
get_players
(playersnum)

new 
count_tcount_ct

for (new i=0;i<num;i++)
{
    switch (
cs_get_user_team(players[i]))
    {
        case 
CS_TEAM_Tcount_t++;
        case 
CS_TEAM_CTcount_ct++;
    }
}

client_print(0print_chat"TERO: %d"count_t)
client_print(0print_chat"CT: %d"count_ct
Another way to do this:

get_players() is no longer supported and is a bit buggy depending on which flags you use.
See this link.

PHP Code:
new iPlayers32 ];
new 
iPlayerCount;

get_players iPlayers iPlayerCount "e" "TERRORIST" );
client_printprint_chat "Terrorist: %d" iPlayerCount );

get_players iPlayers iPlayerCount "e" "CT" );
client_printprint_chat "CT: %d" iPlayerCount ); 
__________________

Last edited by Bugsy; 08-25-2009 at 20:57.
Bugsy is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 08-25-2009 , 20:54   Re: Count players of a team?
Reply With Quote #4

also could use get_user_team( id ) case 1 for t's case 2 for ct's
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
MasterKy
Junior Member
Join Date: Aug 2009
Old 08-25-2009 , 21:57   Re: Count players of a team?
Reply With Quote #5

Thats good!!

the two codes has been sucessful ^^
very thanks for all !!
MasterKy is offline
Reply


Thread Tools
Display Modes

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 15:00.


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