SA-MP Forums Archive
Get Team Count? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get Team Count? (/showthread.php?tid=427757)



Get Team Count? - (_AcE_) - 03.04.2013

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?


Re: Get Team Count? - LarzI - 03.04.2013

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.


Re: Get Team Count? - (_AcE_) - 03.04.2013

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.


Re: Get Team Count? - JJB562 - 03.04.2013

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.


Re: Get Team Count? - kamzaf - 03.04.2013

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