Raised This Month: $ Target: $400
 0% 

How can I find out the # of players on a team?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
I3lade203
Junior Member
Join Date: Jun 2007
Old 09-18-2007 , 09:32   How can I find out the # of players on a team?
Reply With Quote #1

This is probably a very simple question; but i'm new so give me a break. What can I use to find out how many players are on a team?

Last edited by I3lade203; 09-18-2007 at 10:16.
I3lade203 is offline
_Tool_
Junior Member
Join Date: Sep 2007
Old 09-18-2007 , 11:23   Re: How can I find out the # of players on a team?
Reply With Quote #2

new players[32],num,teamnum=0;
get_players(players,num,"ce","team");
for(new i=0;i<num;i++) teamnum++;

/*flags:
"a" - Don't return dead players
"b" - Don't return alive players
"c" - Skip bots
"d" - Skip real players
"e" - Match with passed team
"f" - Match with part of name
"g" - Ignore case sensitivity
"h" - Skip HLTV
*/

Last edited by _Tool_; 09-18-2007 at 11:32.
_Tool_ is offline
I3lade203
Junior Member
Join Date: Jun 2007
Old 09-18-2007 , 16:34   Re: How can I find out the # of players on a team?
Reply With Quote #3

Thanks, I figured I was going to have to use a for loop but I wasn't sure if there was already a pre-defined function that would just retrieve the number or not. Guess not, but I do have a question...

Here's what my code looks like so far:

Code:
public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR)    
    register_menucmd(register_menuid("Team_Select"), MENU_KEY_1 | MENU_KEY_2, "jointeam")    
    register_clcmd("jointeam 1", "jointeam") 
    register_clcmd("jointeam 2", "jointeam") 
    register_clcmd("jointeam 5", "jointeam")
    
}
Code:
public jointeam()
{
    new red_players, blue_players, x, numplayers
    numplayers = get_playersnum()
    
    for(x=0; x<=32; x++)
    {
    
        
        
        if( get_user_team(x) == 2 )
        {
            blue_players = blue_players + 1
            set_cvar_num("cr_demoman", -1)
        
        }else if (get_user_team(x) == 1 )
        {
            red_players = red_players +1
            set_cvar_num("cr_sniper", -1)
        }
    
    }
    
  
    
    
}
Thanks to you, I was able to get the number of players per team working. HOWEVER, the problem i'm now having is that the above code only exectues when a player CHANGES teams, rather then joins teams. So, if I join a server with the above code running, and I pick "Team 1" nothing will happen. If however after I spawn I join team 2, and then join team 1 again the "team 1" code will work. How can I fix this so that it'll execute the code whenever the player chooses the team, rather then switches to the team?

Last edited by I3lade203; 09-18-2007 at 18:46.
I3lade203 is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-18-2007 , 18:34   Re: How can I find out the # of players on a team?
Reply With Quote #4

As a side note, get_players() and is kind of buggy when parsing out teams. It doesn't look like you should have any problems, but beware :O....
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
I3lade203
Junior Member
Join Date: Jun 2007
Old 09-18-2007 , 18:46   Re: How can I find out the # of players on a team?
Reply With Quote #5

Quote:
Originally Posted by Zenith77 View Post
As a side note, get_players() and is kind of buggy when parsing out teams. It doesn't look like you should have any problems, but beware :O....
Well, I've tried my code with both get_players() and get_player_team -- however in either case when a user is initally joining a team after connecting to the server it doesn't execute the code within the for loop. However, if I join the game and change to the oppisite team it then DOES in fact execute the code.

How can I resolve this issue so that the code executes whenever a player joins a team, even if they weren't on one previously?
I3lade203 is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 09-18-2007 , 20:45   Re: How can I find out the # of players on a team?
Reply With Quote #6

It does execute the code within the loop. But your code does not do anything because it does not fall within the paramters of your if statements.

get_user_team(x) will not work on the player that just executed the command to join the team.

Think of the sequence of it:
1-Player joins server, with "no team assigned yet."
2-Player executes the "jointeam" command.
3-AMXX interrupts the command and executes code.
4-Player is then assigned to the team he joined.

Theoretically, you could block the person from joining the team, which is why AMXX interrupts and comes before, not after in this case.

So anyway,

Instead of doing a get_user_team() on the player joining the team, you should instead read the argument of the command being executed.

Code:
public cmd_jointeam(id) {    new args[8];    read_args( args, 7 );    new new_team = str_to_num( args ); }

In the above code block, the integer variable new_team will be equal to the team the client tried to join. Like I said, get_user_team() won't return anything for that client yet as the team has yet to be set.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
I3lade203
Junior Member
Join Date: Jun 2007
Old 09-19-2007 , 01:27   Re: How can I find out the # of players on a team?
Reply With Quote #7

Quote:
Originally Posted by Wilson [29th ID] View Post
It does execute the code within the loop. But your code does not do anything because it does not fall within the paramters of your if statements.

get_user_team(x) will not work on the player that just executed the command to join the team.

Think of the sequence of it:
1-Player joins server, with "no team assigned yet."
2-Player executes the "jointeam" command.
3-AMXX interrupts the command and executes code.
4-Player is then assigned to the team he joined.
Ah, that makes perfect sense - no wonder I was having so many issues with this. Thanks for explaining that. However..


Quote:
So anyway,

Instead of doing a get_user_team() on the player joining the team, you should instead read the argument of the command being executed.

Code:
public cmd_jointeam(id) { new args[8]; read_args( args, 7 ); new new_team = str_to_num( args ); }


In the above code block, the integer variable new_team will be equal to the team the client tried to join. Like I said, get_user_team() won't return anything for that client yet as the team has yet to be set.
In theory, I understand exactly what the code you've posted is supposed to do. I'm just having trouble interpreting it and integrating it into my existing code - could you show me how to take what you've written and place it in to what I had earlier to make the whole thing run altogether?
I3lade203 is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 09-19-2007 , 03:46   Re: How can I find out the # of players on a team?
Reply With Quote #8

Code:
public jointeam() {     new red_players, blue_players, x, numplayers     args[8], numplayers = get_playersnum()     read_args( args, 7 );     new cmd_team = str_to_num( args );     if( cmd_team == 2 )     {             blue_players = blue_players + 1             set_cvar_num("cr_demoman", -1)     }     else if( cmd_team == 1 )     {             red_players = red_players +1             set_cvar_num("cr_sniper", -1)     }     // For everyone else, loop     // (it will skip the above player since get_user_team() == 0 for him)     for(x=0; x<=32; x++)     {         if( get_user_team(x) == 2 )         {             blue_players = blue_players + 1             set_cvar_num("cr_demoman", -1)                 }else if (get_user_team(x) == 1 )         {             red_players = red_players +1             set_cvar_num("cr_sniper", -1)         }         }               }

This basically does the stuffs for the player doing the command, and then does it in addition for everyone else. This just an example and obviously not the most efficient way. But this way you get the idea.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
I3lade203
Junior Member
Join Date: Jun 2007
Old 09-19-2007 , 08:23   Re: How can I find out the # of players on a team?
Reply With Quote #9

OH, I see now. Thanks! I'm still learning, so most efficient way or not, if it works and I learned a new way do so something, it's successfully. Thanks for the help, I'll try the code out when I get home later today and see what happens.
I3lade203 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 16:08.


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