SA-MP Forums Archive
Team Players - 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: Team Players (/showthread.php?tid=361734)



Team Players - (_AcE_) - 22.07.2012

Hi, I was wondering if there was a way of getting the total amount of players on each team?

Like when I start the round, we can play a TDM and then the round will end.

pawn Код:
if (gTeam[playerid] == TEAM_HOME)
    {
        SetPlayerColor(playerid, TEAM_HOME_COLOR);
        SetPlayerTeam(playerid, 1);
        bluecount++;
        if(First[playerid] == 1)
        {
            format(string, sizeof(string), "** %s has spawned as the team HOME.", pname);
            SendClientMessageToAll(TEAM_HOME_COLOR, string);
        }
    }
    else
    {
        SetPlayerColor(playerid, TEAM_AWAY_COLOR);
        SetPlayerTeam(playerid, 2);
        redcount++;
        if(First[playerid] == 1)
        {
            format(string, sizeof(string), "** %s has spawned as the team AWAY.", pname);
            SendClientMessageToAll(TEAM_AWAY_COLOR, string);
        }
    }
IS THERE ANYWAY I CAN GET THE TOTAL COUNT OF EACH TEAM?


Re: Team Players - [KHK]Khalid - 22.07.2012

pawn Код:
stock GetTeamCount(teamid)
{
    if(teamid == TEAM_HOME)
        return bluecount;
       
    if(teamid == TEAM_AWAY) // that's your second team id huh?
        return redcount;
       
    return -1; // returns -1 if the team is not defined (In the stock)
}



Re: Team Players - (_AcE_) - 22.07.2012

How do I use that as a stock?


Re: Team Players - [KHK]Khalid - 22.07.2012

pawn Код:
// Usage: GetTeamCount(teamid);
// Example:
printf("The home team count is %d", GetTeamCount(TEAM_HOME));



Re: Team Players - maramizo - 22.07.2012

Using foreach inc.
pawn Код:
stock GetTeamPlayers()
{
    new blueteam, redteam;
    foreach(Player, i)
    {
        if(GetPlayerTeam(i) == 1)
        {
            blueteam++
        }
        if(GetPlayerTeam(i) == 2)
        {
            redteam++
        }
    }
    new str[128];
    format(str, 128, "Red team has %i players, while blue team has %i players.", redteam, blueteam);
    return str;
}