PDA

View Full Version : How to set a random team for a player?


Score
25/08/2018, 03:14 AM
Hello, recently i was trying to create an event system everything else works except one thing, i can't set a random team for each player.

For example when player 1 joins the event, he gets into team A, player 2 Team B, player 3 Team A, player 4 Team B like this.

Can someone give me a code example how to do that?

UFF
25/08/2018, 06:54 AM
new PlayersTeam1=0;
new PlayersTeam2=0;

if(PlayersTeam1 <= PlayersTeam2)
{
SetPlayerTeamA(playerid);
}
else if(PlayersTeam2 <= PlayersTeam1)
{
SetPlayerTeamB(playerid);
}

SetPlayerTeamA(playerid)
{

// codes for Team A

PlayersTeam1++;
}

SetPlayerTeamB(playerid)
{
// codes for Team B
PlayersTeam2++;
}

Beckett
25/08/2018, 08:25 AM
#define MAX_TEAMS 4
new rteam = random(MAX_TEAMS);
switch(rteam)
{
case 0: // Team 1
case 1: // Team 2
case 2: // Team 3
case 3: // Team 4
}

UFF
25/08/2018, 05:13 PM
#define MAX_TEAMS 4
new rteam = random(MAX_TEAMS);
switch(rteam)
{
case 0: // Team 1
case 1: // Team 2
case 2: // Team 3
case 3: // Team 4
}

Well bro,
He meant, 2 random teams for a event system.
when player 1 joins the event, he gets into team A, player 2 Team B, player 3 Team A, player 4 Team B like this.

and the code which you provided will not work for perfect balance for teams.