AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to check players in teams? (https://forums.alliedmods.net/showthread.php?t=170999)

Evaldas.Grigas 10-31-2011 09:56

How to check players in teams?
 
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.

reinert 10-31-2011 13:02

Re: How to check players in teams?
 
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 ?

Evaldas.Grigas 10-31-2011 13:28

Re: How to check players in teams?
 
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?

reinert 10-31-2011 14:45

Re: How to check players in teams?
 
you should use cs_get_user_team if you are using CS_TEAM_T and CT values, or use get_user_team == 1 | 2

padilha007 10-31-2011 14:46

Re: How to check players in teams?
 
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...
        
    
}



BrundiX 10-31-2011 15:02

Re: How to check players in teams?
 
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;



Evaldas.Grigas 10-31-2011 15:08

Re: How to check players in teams?
 
Quote:

Originally Posted by reinert (Post 1587318)
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?

reinert 10-31-2011 16:47

Re: How to check players in teams?
 
You created a variable for every player what is not needed for that.

And you should reset the variable counts after counting.

Evaldas.Grigas 10-31-2011 16:51

Re: How to check players in teams?
 
Done.
Quote:

Originally Posted by padilha007 (Post 1587320)
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!

Evaldas.Grigas 10-31-2011 17:36

Re: How to check players in teams?
 
Sorry for double post, but what teams are these?
PHP Code:

if( iPlayers[0] >= && iPlayers[1] >= 

0=CT, and 1=T?


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

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