Random team assigning, team members limit:
#1

I'm working on a gamemode right now and after creating the base, I hoped into the different missions there will be. For everyone mission, we have three teams, but I'll simplify it for you: Team A, Team B and Guy 1. Team A are the ones that must kill the Guy 1. The rest is history.

Now, the main problem is: I don't know how to randomly assign connected players to a team, seeing that Team A and Team B should be balanced and Guy 1 cannot be killed by Team B members. How's it done?
Reply
#2

like this maybe
pawn Код:
#include <foreach>

#define TeamA 1
#define TeamB 2
 
new team[MAX_PLAYERS];
new Iterator:hold<MAX_PLAYERS>;//holds the player which have been assigned to a team already


//on command to assign the the teams to all player connected
new i;
new count = Iter_Count(Player);//returns number of connected players

new ran, b = 0;//for using inside loop

for(i = 1; i <= count; i++)
{
ran = Iter_Random(Player);
while(b == 0)
      {
      If(Iter_Contains(hold, ran))ran = Iter_Random(Player);//means if player is already assigned a team
      else b = 1;//to end the loop
      }

b = 0;//for next loop
if(i % 2 == 0)team[ran] = TeamA;//this for balancing team
else team[ran] = TeamB;
Iter_Add(hold, ran);
}
/*=====================================*/

//on restart of event or event end this --
Iter_Clear(hold);
Reply
#3

use a variable with MAX_TEAM_PLAYERS, assign the player's team to team 1. add if team 1 is more than team 2 then set the player to team 2, otherwise, set them to team 1. if team 1 = MAX_TEAM_PLAYERS then set it to the other team, else return an error message that the server is full.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)