Raised This Month: $ Target: $400
 0% 

Getting team number function with cstrike


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 07-26-2009 , 05:09   Getting team number function with cstrike
Reply With Quote #1

Topic title may be a bit confusing, but can't think of anything else. Whenever I use cs_get_user_team() in a function like this, it doesn't work. Is there anything obvious that I've done wrong or... something I don't know.

PHP Code:
// Function to get alive team count
fnGetAliveTeamCount(CsTeams:Team)
{
    new 
iCount 0;
    for(new 
i<= g_iMaxPlayersi++)
    {
        if(
cs_get_user_team(i) == Team)
            ++
iCount;
    }
    
    return 
iCount;

shadow.hk is offline
Send a message via MSN to shadow.hk
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-26-2009 , 05:16   Re: Getting team number function with cstrike
Reply With Quote #2

it looks fine, atleast you should check what player is alive..
__________________
xPaw is offline
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 07-26-2009 , 05:22   Re: Getting team number function with cstrike
Reply With Quote #3

Quote:
Originally Posted by xPaw View Post
it looks fine, atleast you should check what player is alive..
... Can't believe I missed that out. I'll try it now.
shadow.hk is offline
Send a message via MSN to shadow.hk
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2009 , 05:23   Re: Getting team number function with cstrike
Reply With Quote #4

And new i -> new i = 1 ; Otherwise it looks fine.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-26-2009 , 05:27   Re: Getting team number function with cstrike
Reply With Quote #5

Start id should be 1 and not 0, also, don't forfet to retrieve maxplayers value.

PHP Code:
enum {
    
All,
    
Alive,
    
Dead
}

fnGetTeamCount(CsTeams:TeamiType)
{
    new 
iCount 0
    
for(new id 1id <= g_iMaxPlayersid++)
    {
        switch( 
iType )
        {
            case 
All:
            {
                if( !
is_user_connected(id) )
                {
                    continue
                }
            }
            case 
Alive:
            {
                if( !
is_user_alive(id) )
                {
                    continue
                }
            }
            case 
Dead:
            {
                if(  !
is_user_connected(id) || is_user_alive(id) )
                {
                    continue
                }
            }
        }
        if( 
cs_get_user_team(id) == Team )
        {
            ++
iCount
        
}
    }

    return 
iCount


Also, if you only need alive players, you can use this passing team NAME :
PHP Code:
fnGetAliveTeamCount(const szTeam[])
{
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"ae"szTeam)
    return 
iNum

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-26-2009 at 13:10.
ConnorMcLeod is offline
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 07-26-2009 , 09:42   Re: Getting team number function with cstrike
Reply With Quote #6

@Connor: shouldn't you use continue instead of return in the loop? otherwise it'll break out of the function and return a value of 0.
__________________
If at first you don't succeed, then skydiving isn't for you.
G-Dog is offline
Send a message via AIM to G-Dog
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2009 , 11:01   Re: Getting team number function with cstrike
Reply With Quote #7

He should, yes.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-26-2009 , 13:11   Re: Getting team number function with cstrike
Reply With Quote #8

Fixed.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 18:19.


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