SA-MP Forums Archive
Round out 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Round out players (/showthread.php?tid=73300)



Round out players - StrickenKid - 13.04.2009

ok, i want t be able to count the players in server (already made function for that) and round and even out the teams with the rounded ammount, and if one team is full it wont let them join...

for example lets say theirs 100 people in the server (i wish lol) and theirs 4 teams. So that 25% of players per team. i want the script to automatically know to assign 25 slots to each team (25%)

How will i do this?

Thanks For Any Help!


Re: Round out players - StrickenKid - 14.04.2009

*bumpy*

anyone?


Re: Round out players - ICECOLDKILLAK8 - 14.04.2009

pawn Код:
// Top of script
#define TeamAmount 10 // Replace this if you want more teams
#define MaxTeamPlayers 25 // Max players allowed on a team

PlayersOnTeam[TeamAmount];

// Anywhere in script
public OnPlayerSpawn(playerid)
{
  if(PlayersOnTeam[Team[playerid]] > MaxTeamPlayers) // Replace team with your variable for teams e.g. gTeam
  {
    SendClientMessage(playerid, color, "Team full, Assigning you to a different team"); // Replace color with a color of your choice
    Team[playerid] = random(MaxTeamPlayers);// Replace team with your variable for teams e.g. gTeam
    SetPlayerHealth(playerid, 0);
    return 1;
  }
  else
  {
    PlayersOnTeam[Team[playerid]]++;// Replace team with your variable for teams e.g. gTeam
  }
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  PlayersOnTeam[Team[playerid]]--;// Replace team with your variable for teams e.g. gTeam
  return 1;
}
That should give you a rough idea of what you need to do


Re: Round out players - Backwardsman97 - 14.04.2009

pawn Код:
new TeamStatus; //At the top

//When you assign teams
for(new i=0; i<MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(playerid))
   {
      /* Team Variable */ = TeamStatus;
     TeamStatus++;
     if(TeamStatus == 4) TeamStatus = 0;
   }
}
Try that. It should deal players out to the teams.

Edit:Beat me to it. But two different ways. Maybe I read the post wrong.


Re: Round out players - StrickenKid - 14.04.2009

ok but what i wanted it do is have the server round it to the number of players in server,...

maby this?

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

new CurPlayers = CountPlayers()
new devide;
devide = (CurPlayers / 4);
/* and do the rest */ maby?



Re: Round out players - Backwardsman97 - 14.04.2009

You wanted the server to figure out how many players needed to be on each team? You need mod for that.

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

new CurPlayers = CountPlayers();
if(!CurPlayers % 4)
{
   //The amount of players in the server is evenly dividable by 4
}
else
{
   //You have extras ( at most 3 ) that don't fit on a team
}