24.11.2013, 14:55
Hi, im trying to script a AAD command. What i am trying to do is to whenever the command is typed, players are equally distribuited into two teams. How can i do that?
new TeamPlayers[ <Amount of teams here> ]; public OnPlayerRequestSpawn(playerid) { for(new teams; teams < [Team Amount]; teams++) { if(teams == GetPlayerTeam(playerid)) continue; //Or gTeam[playerid], or w/e you use. if(TeamPlayers[Player Team Variable] > TeamPlayers[teams] + 3) { SendClientMessage(playerid, COLOR_RED, "You can't join this team as it would unbalance the game!"); return 0; } } }
CMD:balanceteams(playerid, params[])
{
new TotalPlayers = 0;
new A=0, B=1;
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
switch (i)
{
case A: SetPlayerTeam(playerid, 1); // First team
case B: SetPlayerTeam(playerid, 2); // Second team
}
}
A += 2;
B += 2;
}
return 1;
}
new
half = floatround( Iter_Count(Player) / 2 ),
count = -1
;
foreach(new i : Player)
{
if( ++count <= half ) SetPlayerTeam( i, 1 );
else SetPlayerTeam( i, 2 );
}
new
rand,
count,
i = -1,
tmp[MAX_PLAYERS]
;
// 1)
while(++i != MAX_PLAYERS) {
if(IsPlayerConnected(i)) {
tmp[count++] = i;
}
}
// 2) 3) 4)
for(i = count / 2; count; ) {
if(i < count) {
rand = random(count--);
SetPlayerTeam(tmp[rand], 1);
tmp[rand] = tmp[count];
} else {
SetPlayerTeam(tmp[--count], 2);
}
}