AlliedModders

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

Debesėlis 10-25-2013 09:32

get team players
 
How to get/know there is player in T team and there is player in CT team?

PHP Code:

if ( players in T_TEAM && players in CT_TEAM )
{
     
// do something



Firippu 10-25-2013 09:59

Re: get team players
 
There are multiple ways of doing this.. One way, you could loop through all possible player IDs and count the ones under given conditions.

This example here stores player counts in variables for both teams.
PHP Code:

new iTEcount,iCTcount
for(new id=1id<=32id++) {
    if(
is_user_connected(id)) {
        switch(
cs_get_user_team(id)) {
            case 
CS_TEAM_T: {
                
iTEcount++
            } case 
CS_TEAM_CT: {
                
iCTcount++
            }
        }
    }
}

// iTEcount = number of players in terrorist team
// iCTcount = number of players in counter terrorist team

// example
if(iTEcount>=5) {
    
// this will run if there are 5 or more players in terrorist team



Debesėlis 10-25-2013 10:05

Re: get team players
 
Quote:

Originally Posted by Firippu (Post 2052729)
There are multiple ways of doing this.. One way, you could loop through all possible player IDs and count the ones under given conditions.

This example here stores player counts in variables for both teams.
PHP Code:

new iTEcount,iCTcount
for(new id=1id<=32id++) {
    if(
is_user_connected(id)) {
        switch(
cs_get_user_team(id)) {
            case 
CS_TEAM_T: {
                
iTEcount++
            } case 
CS_TEAM_CT: {
                
iCTcount++
            }
        }
    }
}

// iTEcount = number of players in terrorist team
// iCTcount = number of players in counter terrorist team

// example
if(iTEcount>=5) {
    
// this will run if there are 5 or more players in terrorist team




Can i use it in client_putinserver ?
PHP Code:

public client_putinserver id )
{
    new 
iTEcountiCTcount;
    for( new 
id 1id <= 32id++ )
    {
        if ( 
is_user_connectedid ) )
        {
            switch ( 
cs_get_user_teamid ) )
            {
                case 
CS_TEAM_TiTEcount++
                case 
CS_TEAM_CTiCTcount++
            }
        }
    }
}
    
    if ( 
iTEcount >= && iCTcount >= )
    {
        if ( !
g_bIsFreezeTime && !is_user_botid ) && !is_user_hltvid ) )
            
// next stage
    
}



YamiKaitou 10-25-2013 10:21

Re: get team players
 
The user has not joined a team when client_putinserver is called

Firippu 10-25-2013 10:22

Re: get team players
 
It depends on what you're trying to achieve by using the team counts. Maybe explain a little more about what the code will be used for so someone can give a more accurate response.

Debesėlis 10-25-2013 10:40

Re: get team players
 
PHP Code:

#include < amxmodx >
#include < fakemeta >
#pragma semicolon 1

const m_iNumSpawns 365;
new 
bool:g_bIsFreezeTime true;

public 
plugin_init ( )
{
    
register_plugin"No Spawn After FreezeTime""0.0.1""ConnorMcLeod" );
    
register_event"HLTV""Event_HLTV_New_Round""a""1=0""2=0" );
    
register_logevent"LogEvent_Round_Start"2"1=Round_Start" );
}

public 
Event_HLTV_New_Round ( )
    
g_bIsFreezeTime true;

public 
LogEvent_Round_Start ( )
{
    
g_bIsFreezeTime false;
    
    new 
players32 ], num;
    
get_playersplayersnum"h" );
    for ( --
numnum >= 0num-- )
    {
        
set_pdata_intplayersnum ], m_iNumSpawns);
    }
}

public 
client_putinserver id )
{
    new 
iTEcountiCTcount;
    for ( new 
iPlayer 1iPlayer <= 32iPlayer++ )
    {
        if ( 
is_user_connectediPlayer ) )
        {
            switch ( 
cs_get_user_teamiPlayer ) )
            {
                case 
CS_TEAM_TiTEcount++
                case 
CS_TEAM_CTiCTcount++
            }
        }
    }
    
    if ( 
iTEcount >= && iCTcount >= )
    {
        if ( !
g_bIsFreezeTime && !is_user_botid ) && !is_user_hltvid ) )
            
set_pdata_intidm_iNumSpawns);
    }



ConnorMcLeod 10-25-2013 12:49

Re: get team players
 
Don't use #2 code
get_players is always better than looping from 1 to 32, or than from 1 to maxplayers.

PHP Code:

public client_putinserver id )
{
    if( !
g_bIsFreezeTime && !is_user_botid ) && !is_user_hltvid ) )
    {
        new 
iTEcountiCTcountplayers[32];
        
get_players(playersiTEcount"e""TERRORIST");
        
get_players(playersiCTcount"e""CT");
    
        if ( 
iTEcount >= && iCTcount >= )
        {
                
set_pdata_intidm_iNumSpawns);
        }
    }



Debesėlis 10-25-2013 13:04

Re: get team players
 
Thanks Connor you are the best.


All times are GMT -4. The time now is 23:22.

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