Ok, this is my first tutorial, so go easy.
What is this tutorial based upon?
This tutorial shows people how to create a dialog which enables people to select fair teams, in a smart way.
Why is this better than normal team selections?
This uses a mathmatic term of mod (modulo), which makes the teams fair.
Lets say their is 9 players, how are you going to have 2 players per team?
How easy is this going to be?
This will be fairly easy once you know how, but maybe struggle to realise it.
~~
Ok, the actual tutorial
Creating fair team Selection
Firstly, create a new trigger. Call it something like "Team Picking Init", or along those lines.
So now we have a fresh base to work on.
After we have that, lets create the variables.
For this, we will need an array, to show if the allowed set (2v2, 3v3, 4v4, 5v5, 6v6) is allowed.
Their are 5 matchups possible, so make an array of 5, a boolean, and call it something like "AllowMatchup".
The actual array index is the same as the matchup +1. If that makes sense.
So AllowMatchup[1] means Allow (1 + 1) per team.
AllowMatchup[4] means Allow (4 + 1) per team.
And ofcourse, the last would be (5 + 1) which is 6, but that infomation is needed later.
So we have a variable looking like this:
Now lets create the dialog variable.
Just a normal dialog, call it something like "TeamPickDialog".
And another variable, the buttons.
Their is 5 matchups, so we need 5 buttons.
As with the booleans, make a array of 5, type Dialog Button, and call is something like "TeamPickDialogButtons".
And last but not least, the number of players in the map.
This will be a integer, call it something like "NumberOfPlayers"
So our final variables looks like:
Now the variables are done, lets start with the trigger.
If you already have a dialog in your map, and you want that near Map Initialization, then use your own event, or when your other dialog is finished.
Lets add the event: Time - Elapsed game time is 0.25 seconds. Not instant, not a long wait.
Firstly, we need to know how many people are playing.
So lets do that as our first action.
Basically, the Loop and If's, the loop runs all the actions inside it 12 times, because its 1 - 12.
It then checks if player (integer a) is playing.
If he/she is, it will set it to +1.
Now player(integer a) can be 12 different players, because it loops. Its all of them, and makes life easier for optimization.
So now we have the number of players.
Lets check the matchups and set them.
This bit is quite complicated if your new to Integer A and loops.
But here it is.
Mod (Modulo)
Modulo calculates the remains of a division.
Example: 15 / 7 = 2 and 1 remaining.
The reason i use mod, is to check if any players will be left out.
If their are players left out, we wont allow the button to be placed on, otherwise it would currupt the point of this tutorial,
fair teams.
Anyway, the "NumberOfPlayers mod ((Integer A) + 1)" is actually not to complicated when you think about it. Imagine the loop is running for the first time, integer a would mean 1.
Calculation:
NumberOfPlayers mod ((Integer A) + 1)
NumberOfPlayers mod (1 + 1)
NumberOfPlayers mod 2
If their is no remaining players, set Allow 2v2 = true.
Simple as that!
Now we have all the matchups done in that loop, lets start creating the dialog.
I hid the dialog for all players, and changed the title of the dialog to "Pick Team Matchup".
Now another complicated part.
We need to add the buttons, but only the buttons which passed the matchup test.
Also, mod is checking for 0, if there was 6 players, the button for "6 players per team" would pop up, so it would be 6v0.
So lets add a condition checking theres not that many people.
Now, this will loop again, and if the Matchup is ok, it will create a button saying "(Integer A + 1) players per team?"
The integer A + 1 will change everytime the loop runs, so the first time it will say "2 players per team" until it gets to 6.
And it sets the button to the variable.
The dialog is done!
You can show it to maybe all players, or just 1.
Even maybe the host with the get host function!
But their is still one problem.
What if their is a prime number amount of people? (5/7/11) or if their is under 4 people?
This is a problem.
Because we cant divide any of those numbers, we cant have half or bits of a player! and we cant have less than 4 people!
So if thats the case, lets change the matchup to free for all.
Add these functions to the bottom:
So your final Initialization trigger is:
And now we need the response trigger, if the buttons are clicked.
So create a new trigger, and call it something like: "Dialog Response".
And add the following things:
This is yet again another loop, but optimizes it.
Its really saying:
"If you clicked 2v2 then say to all players: "The game mode is 2 players per team!
It will clear the old dialog, hide it for everybody, and you can add your own actions for that 2v2 where it says.
Like another boolean variable called "Is2v2"
But its running it 5 times, so in the above where i said 2, change that to 3, 4, 5 and 6.
All at once, it will check it all and run it.
Thats the end, that should work great.
~~
Thankyou for listening to my tutorial, i enjoyed making it.
I also attached a test map, with the triggers in, which you can test.