Raised This Month: $ Target: $400
 0% 

get team players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 10-25-2013 , 09:32   get team players
Reply With Quote #1

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

Debesėlis is offline
Firippu
Senior Member
Join Date: Jan 2007
Old 10-25-2013 , 09:59   Re: get team players
Reply With Quote #2

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

__________________

Last edited by Firippu; 10-25-2013 at 10:02. Reason: OCD Correction
Firippu is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 10-25-2013 , 10:05   Re: get team players
Reply With Quote #3

Quote:
Originally Posted by Firippu View Post
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
    
}

Debesėlis is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-25-2013 , 10:21   Re: get team players
Reply With Quote #4

The user has not joined a team when client_putinserver is called
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Firippu
Senior Member
Join Date: Jan 2007
Old 10-25-2013 , 10:22   Re: get team players
Reply With Quote #5

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.
__________________
Firippu is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 10-25-2013 , 10:40   Re: get team players
Reply With Quote #6

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);
    }

Debesėlis is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-25-2013 , 12:49   Re: get team players
Reply With Quote #7

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);
        }
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 10-25-2013 , 13:04   Re: get team players
Reply With Quote #8

Thanks Connor you are the best.
Debesėlis is offline
Reply


Thread Tools
Display Modes

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 23:22.


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