View Single Post
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 03-24-2018 , 00:19   Re: [HELP] Alive CT and T Help For Fix
Reply With Quote #2

Code:
public fnGetAlive( szTeam[ ] ) // szTeam CAN BE "CT" or "TERRORIST"
{
    new iPlayers[ 32 ], iNum, iCount;

    //get_players_ex( iPlayers, iNum, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, szTeam ); // AMXX 1.8.3
    get_players( iPlayers, iNum, "ae", szTeam ); // AMXX 1.8.2

    return iNum;
}

public fnGetAlive( iTeam ) // Without CSTRIKE -> iTeam can be 0 = UNASSIGNED - 1 = TERRORIST 2 - CT 3 - SPECTATOR
{
    new iMax = get_maxplayers( );
    new iCount = 0;

    for( new iClient = 1; iClient < iMax; iClient++ )
        if( is_user_alive( iClient ) )
            if( get_user_team( iClient ) == iTeam )
                iCount++;

    return iCount;
}

public fnGetAlive( CsTeams:csTeam ) // csTeam can be CS_TEAM_CT, CS_TEAM_T, CS_TEAM_UNASSIGNED, CS_TEAM_SPECTATOR
{
    new iMax = get_maxplayers( );
    new iCount = 0;

    for( new iClient = 1; iClient < iMax; iClient++ )
        if( is_user_alive( iClient ) )
            if( cs_get_user_team( iClient ) == csTeam )
                iCount++;

    return iCount;
}
You can use any of them, the first one is better.
Usage
First -> fnGetAlive( "TERRORIST" ) or fnGetAlive( "CT" );
Second -> fnGetAlive( 1 ) or fnGetAlive( 2 );
Third ->fnGetAlive( CS_TEAM_CT ) or fnGetAlive( CS_TEAM_T );

Last edited by marcelowzd; 03-28-2018 at 20:26. Reason: First method now counting right
marcelowzd is offline