AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Count players of a team? (https://forums.alliedmods.net/showthread.php?t=101624)

MasterKy 08-25-2009 15:28

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

There are %s terrorists!

plz, help me!

ot_207 08-25-2009 16:04

Re: Count players of a team?
 
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)



Bugsy 08-25-2009 20:47

Re: Count players of a team?
 
Quote:

Originally Posted by ot_207 (Post 912794)
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 ); 


tuty 08-25-2009 20:54

Re: Count players of a team?
 
also could use get_user_team( id ) case 1 for t's case 2 for ct's :P

MasterKy 08-25-2009 21:57

Re: Count players of a team?
 
Thats good!!

the two codes has been sucessful ^^
very thanks for all !!:wink:


All times are GMT -4. The time now is 15:00.

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