HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creating fair team Selection

07-31-2006, 02:10 PM#1
The)TideHunter(
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

Zoom (requires log in)



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.

Trigger:
Team Picking Init
Events
Conditions
Actions

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:

Zoom (requires log in)

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:

Zoom (requires log in)

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.

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Actions

Firstly, we need to know how many people are playing.
So lets do that as our first action.

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
Set NumberOfPlayers = (NumberOfPlayers + 1)
Else - Actions

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.

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
Set NumberOfPlayers = (NumberOfPlayers + 1)
Else - Actions
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(NumberOfPlayers mod ((Integer A) + 1)) Equal to 0
Collapse Then - Actions
Set AllowMatchup[(Integer A)] = True
Else - Actions

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.

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
Set NumberOfPlayers = (NumberOfPlayers + 1)
Else - Actions
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(NumberOfPlayers mod ((Integer A) + 1)) Equal to 0
Collapse Then - Actions
Set AllowMatchup[(Integer A)] = True
Else - Actions
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
Dialog - Change the title of TeamPickDialog to Pick Team Matchup.

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.

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
Set NumberOfPlayers = (NumberOfPlayers + 1)
Else - Actions
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(NumberOfPlayers mod ((Integer A) + 1)) Equal to 0
Collapse Then - Actions
Set AllowMatchup[(Integer A)] = True
Else - Actions
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
Dialog - Change the title of TeamPickDialog to Pick Team Matchup.
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AllowMatchup[(Integer A)] Equal to True
NumberOfPlayers Not equal to ((Integer A) + 1)
Collapse Then - Actions
Dialog - Create a dialog button for TeamPickDialog labelled ((String(((Integer A) + 1))) + players per team?)
Set TeamPickDialogButtons[(Integer A)] = (Last created dialog Button)
Else - Actions

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:

Trigger:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
NumberOfPlayers Less than to 4
NumberOfPlayers Equal to 5
NumberOfPlayers Equal to 7
NumberOfPlayers Equal to 11
Collapse Then - Actions
Game - Display to (All players) the text: The game mode is free for all!
Dialog - Clear TeamPickDialog
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
-------- Your 'Free For All' actions here --------
Else - Actions

So your final Initialization trigger is:

Trigger:
Team Picking Init
Collapse Events
Time - Elapsed game time is 0.25 seconds
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
Set NumberOfPlayers = (NumberOfPlayers + 1)
Else - Actions
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(NumberOfPlayers mod ((Integer A) + 1)) Equal to 0
Collapse Then - Actions
Set AllowMatchup[(Integer A)] = True
Else - Actions
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
Dialog - Change the title of TeamPickDialog to Pick Team Matchup.
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
AllowMatchup[(Integer A)] Equal to True
NumberOfPlayers Not equal to ((Integer A) + 1)
Collapse Then - Actions
Dialog - Create a dialog button for TeamPickDialog labelled ((String(((Integer A) + 1))) + players per team?)
Set TeamPickDialogButtons[(Integer A)] = (Last created dialog Button)
Else - Actions
Dialog - Show TeamPickDialog for Player 1 (Red)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
NumberOfPlayers Less than to 4
NumberOfPlayers Equal to 5
NumberOfPlayers Equal to 7
NumberOfPlayers Equal to 11
Collapse Then - Actions
Game - Display to (All players) the text: The game mode is fr...
Dialog - Clear TeamPickDialog
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
-------- Your 'Free For All' actions here --------
Else - Actions


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:

Trigger:
Dialog Response
Collapse Events
Dialog - A dialog button is clicked for TeamPickDialog
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 5, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Clicked dialog button) Equal to TeamPickDialogButtons[(Integer A)]
Collapse Then - Actions
Game - Display to (All players) the text: ((The game mode is + (String(((Integer A) + 1)))) + players per team!)
Dialog - Clear TeamPickDialog
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Dialog - Hide TeamPickDialog for (Picked player)
Skip remaining actions
-------- Your (Integer A + 1) vs (Integer A + 1) actions here --------
Else - Actions

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.
Attached Images
File type: jpgMatchupVariable.jpg (60.4 KB)
File type: jpgFinal Variables.jpg (72.8 KB)
File type: jpgThumbnail.jpg (113.7 KB)
Attached Files
File type: w3xFair Teams Test.w3x (17.7 KB)
07-31-2006, 11:10 PM#2
ragingspeedhorn
Very long, but nice, good job on it!
07-31-2006, 11:27 PM#3
The)TideHunter(
Quote:
Originally Posted by ragingspeedhorn
Very long, but nice, good job on it!
Thanks, im thinking maybe i could add a few more extras, but i dont want it to be complicated.
08-14-2006, 02:42 PM#4
Blade.dk
Approved. Good job, and sorry it took so long time.
08-14-2006, 05:50 PM#5
The)TideHunter(
Yay, thanks :D.