Random Teams
#1

Okay, I have it set so players join an event and get placed into a random team and spawn... The random spawn location works perfectly, however the random team selection doesn't... They join random teams but I'm unsure on how I could set it so it spawns them evenly rather than it turning out as 10vs3


pawn Код:
if(ActiveEvent == 2)
    {
        rSpawn++;
        if(rSpawn == MAX_SPAWNS) rSpawn = 0;
        new randomteam = 1+random(2);
        SetPlayerTeam(playerid, randomteam);
        if(randomteam == 1)
        {
            SetPlayerPos(playerid, EventSpawn1[rSpawn][0], EventSpawn1[rSpawn][1], EventSpawn1[rSpawn][2]);
            SetPlayerFacingAngle(playerid, EventSpawn1[rSpawn][3]);
            SetPlayerInterior(playerid,10);
            SetPlayerColor(playerid,RCTeam1);
            SetPlayerVirtualWorld(playerid,1337);
            TeamAmount1++;
        }
        else if(randomteam == 2)
        {
            SetPlayerPos(playerid, EventSpawn2[rSpawn][0], EventSpawn2[rSpawn][1], EventSpawn2[rSpawn][2]);
            SetPlayerFacingAngle(playerid, EventSpawn2[rSpawn][3]);
            SetPlayerInterior(playerid,10);
            SetPlayerColor(playerid,Team2);
            SetPlayerVirtualWorld(playerid,1337);
            TeamAmount2++;
        }
}
Reply
#2

there are 2 ways i can offer.
1) u may keep current amount of players in each team and put player in the team with min amount;
2) if you keep list of your players, you may calculate amount of players in teams (a = ALL_COUNT/2, b = ALL_COUNT-a) and set team=1 for A random players and team=2 for the other.
Reply
#3

Not 100% sure on how I could go about that.
Reply
#4

For 1st way instead of your line "new randomteam=.." use
pawn Код:
new randomteam = (TeamAmount2 > TeamAmount1 ? 1:2);
And not forget to set both counters to 0 when starting event

UPD: you should check if rSpawn >=, not ==, 'coz it can cause out of bounds error
Reply
#5

Something like this!

pawn Код:
new RedTeam, BlueTeam;
foreach(Player, i)
{
    if(GetPlayerTeam(i) == 1) ++RedTeam;
    else if(GetPlayerTeam(i) == 2) ++BlueTeam;
}
SetPlayerTeam(playerid, (RedTeam > BlueTeam)+1); // This will be either 1 or 2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)