AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting team number function with cstrike (https://forums.alliedmods.net/showthread.php?t=98506)

shadow.hk 07-26-2009 05:09

Getting team number function with cstrike
 
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;



xPaw 07-26-2009 05:16

Re: Getting team number function with cstrike
 
it looks fine, atleast you should check what player is alive..

shadow.hk 07-26-2009 05:22

Re: Getting team number function with cstrike
 
Quote:

Originally Posted by xPaw (Post 881994)
it looks fine, atleast you should check what player is alive..

... Can't believe I missed that out. I'll try it now. :shock:

Arkshine 07-26-2009 05:23

Re: Getting team number function with cstrike
 
And new i -> new i = 1 ; Otherwise it looks fine.

ConnorMcLeod 07-26-2009 05:27

Re: Getting team number function with cstrike
 
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



G-Dog 07-26-2009 09:42

Re: Getting team number function with cstrike
 
@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.

Arkshine 07-26-2009 11:01

Re: Getting team number function with cstrike
 
He should, yes.

ConnorMcLeod 07-26-2009 13:11

Re: Getting team number function with cstrike
 
Fixed.


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

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