Get Team Count?
#1

How do i get the number of players on each team? I've got two teams TEAM_HOME and TEAM_AWAY but when i try to get the count it never works.

I tried adding ++ to everytime they connect, switch teams, or disconnect and even tried:

pawn Код:
stock GetPlayersCountInTeam(teamid)
{
     new playercount = 0;
     for(new x = 0; x < MAX_PLAYERS; x ++)
     {
           if(GetPlayerState(x) == PLAYER_STATE_NONE) continue;
           if(GetPlayerTeam(x) != teamid) continue;
           if(iRound[x] == 1) continue;
           playercount++;
     }
     return playercount;
}
This doesn't work either

Any thoughts on how I can get the team count with a command?
Reply
#2

Globally:
pawn Код:
new  
    pCount[ NUMBER_OF_TEAMS_HERE ]
;
Whenever a player joins a certain team:
pawn Код:
pCount[ TEAM_ID ] ++;
Whenever a player leaves a certain team:
pawn Код:
pCount[ TEAM_ID ] ++;
This is the simplest method I can think of.
Reply
#3

I tried doing it on:
When they spawn ++
When they switch --
When they disconnect --

But still sometimes it gets incorrectly counted . I used the same method that you suggested.
Reply
#4

Try using these:

pawn Код:
stock GetPlayersCountInTeamHome()
{
    new count;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerTeam(i) == TEAM_HOME)
            {
                count++;
            }
        }
    }
    return count;
}

stock GetPlayersCountInTeamAway()
{
    new count;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerTeam(i) == TEAM_AWAY)
            {
                count++;
            }
        }
    }
    return count;
}
These are not tested but they should work.
Reply
#5

pawn Код:
stock GetTeamCount(teamid)
{
   new playercount = 0;
   for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
   return playercount;
}
ENTER Teamid in the (temid)

like
pawn Код:
new teamcount1 = GetTeamCount(TEAM_1);
format(string,400, "Team1: %d",teamcount1);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)