Raised This Month: $ Target: $400
 0% 

How to check players in teams?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-31-2011 , 09:56   How to check players in teams?
Reply With Quote #1

I want to check if there is more than 5 player in each team (CT and T). Oh. And check that only at round start. Thanks.
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-31-2011 at 09:56.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
reinert
Veteran Member
Join Date: Feb 2007
Old 10-31-2011 , 13:02   Re: How to check players in teams?
Reply With Quote #2

Hook round start event.
make each variable for each team (CTvar, Tvar).
Loop though all players and check their team, if they are CT then CTvar++ if T then Tvar++
After the loop check if(CTvar > 5 && Tvar > 5)
problem ?
reinert is offline
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-31-2011 , 13:28   Re: How to check players in teams?
Reply With Quote #3

Maybe. Like this? I use hamsandwich, so its the same if round start or player spawn.
PHP Code:
new CTvar[33], Tvar[33]
/*...*/
RegisterHam(Ham_Spawn"player""PlayerSpwan"1
/*...*/
public PlayerSpawn(id)
{
    if(
get_user_team(id) == CS_TEAM_CT)
    {
        
CTvar[id]++
    }
    if(
get_user_team(id) == CS_TEAM_T)
    {
        
Tvar[id]++
    }
}
/*...*/
if(CTvar[id] < && Tvar[id] <5)
     return; 
That code is ok?
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-31-2011 at 13:32.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
reinert
Veteran Member
Join Date: Feb 2007
Old 10-31-2011 , 14:45   Re: How to check players in teams?
Reply With Quote #4

you should use cs_get_user_team if you are using CS_TEAM_T and CT values, or use get_user_team == 1 | 2
reinert is offline
padilha007
Senior Member
Join Date: Jul 2008
Old 10-31-2011 , 14:46   Re: How to check players in teams?
Reply With Quote #5

PHP Code:
new iPlayers[2];
new 
g_iMaxplayers;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// MaxPlayers
    
g_iMaxplayers get_maxplayers();
    
    
// Round Start
    
register_logevent"EventRoundStart"2"1=Round_Start" );
}

public 
EventRoundStart( ) 
{
    
// Loop
    
for( new 1g_iMaxplayersi++ )
    {
        if( 
is_user_connected(i) && is_user_alive) && get_user_team(i) != )
            
iPlayers[get_user_team(i) - 1]++;
    }
}

public 
yourfunction()
{
    if( 
iPlayers[0] >= && iPlayers[1] >= )
    {
        
// Do...
        
    
}

__________________


Last edited by padilha007; 10-31-2011 at 15:29.
padilha007 is offline
BrundiX
Junior Member
Join Date: Dec 2010
Old 10-31-2011 , 15:02   Re: How to check players in teams?
Reply With Quote #6

How about this?:
PHP Code:
#include <amxmodx>

new _gMaxPlayers;

public 
plugin_init()
{
    
set_task(133.7"_Function")
    
    
_gMaxPlayers get_maxplayers();
}

public 
_Function()
{
    if(
_This_Boolean())
    {
        
server_print("Theres more then five players in each team");
    }
    
    
/* Code */
    
    /* ......................... */
}

stock bool:_This_Boolean()
{
    new 
_tPl_CtPl;
    
    for(new 
i<= _gMaxPlayersi++)
    {
        if(
is_user_connected(i))
        {
            switch(
get_user_team(i))
            {
                case 
1:
                {
                    
_tPl++;
                }
                case 
2:
                {
                    
_CtPl++;
                }
            }
        }
    }
    if(
_tPl && _CtPl 5)
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
    
    return 
false;

BrundiX is offline
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-31-2011 , 15:08   Re: How to check players in teams?
Reply With Quote #7

Quote:
Originally Posted by reinert View Post
you should use cs_get_user_team if you are using CS_TEAM_T and CT values, or use get_user_team == 1 | 2
Oh right! But my code should work right?
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
reinert
Veteran Member
Join Date: Feb 2007
Old 10-31-2011 , 16:47   Re: How to check players in teams?
Reply With Quote #8

You created a variable for every player what is not needed for that.

And you should reset the variable counts after counting.
reinert is offline
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-31-2011 , 16:51   Re: How to check players in teams?
Reply With Quote #9

Done.
Quote:
Originally Posted by padilha007 View Post
PHP Code:
new iPlayers[2];
new 
g_iMaxplayers;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// MaxPlayers
    
g_iMaxplayers get_maxplayers();
    
    
// Round Start
    
register_logevent"EventRoundStart"2"1=Round_Start" );
}

public 
EventRoundStart( ) 
{
    
// Loop
    
for( new 1g_iMaxplayersi++ )
    {
        if( 
is_user_connected(i) && is_user_alive) && get_user_team(i) != )
            
iPlayers[get_user_team(i) - 1]++;
    }
}

public 
yourfunction()
{
    if( 
iPlayers[0] >= && iPlayers[1] >= )
    {
        
// Do...
        
    
}

Thank you!
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-31-2011 at 17:16.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
Evaldas.Grigas
Senior Member
Join Date: Sep 2011
Location: Lithuania
Old 10-31-2011 , 17:36   Re: How to check players in teams?
Reply With Quote #10

Sorry for double post, but what teams are these?
PHP Code:
if( iPlayers[0] >= && iPlayers[1] >= 
0=CT, and 1=T?
__________________
Please enter this website everyday: http://forums.alliedmods.net/showthread.php?t=169067

Last edited by Evaldas.Grigas; 10-31-2011 at 17:43.
Evaldas.Grigas is offline
Send a message via Skype™ to Evaldas.Grigas
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 12:32.


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