20.07.2014, 12:29
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);