AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get team count? (https://forums.alliedmods.net/showthread.php?t=152585)

tRipLe. 03-11-2011 14:35

How to get team count?
 
I'm having a problem with a plugin, i know what i have to do to solve it. I need to check if terrorist team size is bigger than 0 or not. If yes then do the action or else do nothing.

I don't know how to get terrorist team size :D, but i think it has to be quite simple, please help! :)

Thanks.

Emp` 03-11-2011 14:44

Re: How to get team count?
 
Pseudo code:
Code:

loop through players
    if player is on terrorist team
          increase variable by 1


tRipLe. 03-11-2011 14:55

Re: How to get team count?
 
PHP Code:

new countnumplayers[32]
get_players(players,num)
for(new 
i=0;i<num;i++) {
        new 
plrplr=players[i]
        if(
cs_get_user_team(plr)==CS_TEAM_T&&is_user_connected(plr)) {
              
count++
        }
        if(
count>0) {
               return 
PLUGIN_HANDLED
        
} else {
               
// do my action, because there are no terrorists
        
}


Like this? Sry, im not very experienced :D.

E: actually if i look at this i don't understand at all :(

drekes 03-11-2011 15:29

Re: How to get team count?
 
PHP Code:

new countnumplayers[32], tempid;
get_players(playersnum);

for(new 
0numi++)
{
    
tempid players[i];

    if(
cs_get_user_team(tempid) == CS_TEAM_T)
        
count++;
}

// Count now equals the amount of connected terrorist players. 


tRipLe. 03-11-2011 15:52

Re: How to get team count?
 
Thanks.

Emp` 03-11-2011 16:16

Re: How to get team count?
 
Quote:

Originally Posted by drekes (Post 1431592)
PHP Code:

new countnumplayers[32];
get_players(playersnum);

for(new 
0numi++)
{
    if(
cs_get_user_team(id) == CS_TEAM_T)
        
count++;
}

// Count now equals the amount of connected terrorist players. 


You might want to fix that.

drekes 03-11-2011 17:17

Re: How to get team count?
 
Quote:

Originally Posted by Emp` (Post 1431618)
You might want to fix that.

Done, can't believe i missed that :oops:

diablix 03-11-2011 18:28

Re: How to get team count?
 
Won't be easier to count with a team flag?

wrecked_ 03-11-2011 18:35

Re: How to get team count?
 
Quote:

Originally Posted by diablix (Post 1431665)
Won't be easier to count with a team flag?

Using get_players() with the flag "e" is bugged unless also used with the flag "a". This is because when players swap teams while dead, TeamInfo isn't called until they are alive. Since the OP doesn't want to get only the number of players on each team that are alive, looping or caching team join is necessary.

fysiks 03-11-2011 18:43

Re: How to get team count?
 
Quote:

Originally Posted by wrecked_ (Post 1431669)
Using get_players() with the flag "e" is bugged unless also used with the flag "a". This is because when players swap teams while dead, TeamInfo isn't called until they are alive. Since the OP doesn't want to get only the number of players on each team that are alive, looping or caching team join is necessary.

I think Exolent submitted a fix for that but hasn't been pushed onto 1.8.2


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

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