Round out players
#1

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!
Reply
#2

*bumpy*

anyone?
Reply
#3

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
Reply
#4

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.
Reply
#5

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?
Reply
#6

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
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)