SA-MP Forums Archive
Random team assigning, team members limit: - 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: Random team assigning, team members limit: (/showthread.php?tid=526989)



Random team assigning, team members limit: - Twizted - 20.07.2014

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?


Re: Random team assigning, team members limit: - BroZeus - 20.07.2014

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



Re: Random team assigning, team members limit: - TakeiT - 20.07.2014

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.