Note: there seems to be some bug with this code in some particular situations, I've already fixed it, and hope to update the tutorial as soon as possible ;).
Welcome to my first tutorial: Beginners' guide: solving the lobby problems. I decided to write this after asking repeatedly around here and researching myself. It wasn't very hard to fix this problem, and most of my obstacles were basic "Is there a function for that?" situations. I hope this helps everyone, mostly beginners, fix their lobby problems and move to the development of their custom maps :).
So you have your own nice custom map, and you decide to place some shinny units and buildings.
Everything was ok; until you made the game have more than 1 team and the world exploded.
This tutorial is a very basic beginners' guide with the purpose of solving the main problem of the lobby right now (Patch 1.3.4). As you know (or maybe not) lobby slots have nothing to do with ingame players. Player number is determined by joining order (bravo, Blizz! /sarcasm).
And yes, if you switch team after joining, once the game starts, that player will have the units supposed to be in the other team, the units matching his player number by joining order. You can always lock the team so they can't switch, but well, it's 2011 right now.
This short tutorial is divided in 8 parts, which you'll understand even if you think *insert joke about how noob you may be*.
I'll use a 4v4 protoss vs zerg example (my actual custom map). I'm sorry for the lack of images, but I use the Spanish version, so, well :P. If you don't understand some basic terms, go the the end of the tutorial. I may have translated some functions incorrectly, so feel free to ask anything you don't understand (I made it on GUI so beginners can understand it better, and I could try to update the file later, although I'm not a fan of the copy+paste and don't understand how it works xD).
Step 1: game variants
First of all, I'll suppose you already know how this section works (or else you wouldn't be getting the problems). I only wanted to explain what I have here, so you understand my examples.
Players 1.3.5.7.9 are team 1, and players 2.4.6.8.10. 9 and 10 are computers. I do this instead of the simpler 12345 - 678910 because people logging in will spread between each team instead of filling team 1 and then team 2. Of course, doing it like this will make the loops a bit more complicated, but it isn't a big deal
Now, let's go!
Step 2: global variables
These variables don't need to be global, but you may find them useful for later. You need x arrays to store players of each team, and x player groups for alliances. You can make those arrays be separate or be inside another array, as you prefer. For this particular case, it doesn't matter too much.
ProtossPlayers: Integer array of [4]
ZergPlayers: Integer array of [4]
ProtossPlayerGroup: empty player group
ZergPlayerGroup: empty player group
Step 3, 1/6 on the trigger: Detecting each player's lobby team
Actually, you can't detect lobby slot (as far as I know), but you can detect the team. For this, I'll make a new local variable, an array of integers equal to the number of players, in my case, 8. Make another variable, a normal integer, named PlayerNumber, too.
DetectTeam: Integer array of [8]
PlayerNumber: Integer = 0
Now let's go with the code:
General -Pick each integer from 1 to 2 and do (actions) [1 to 2 because I have 2 teams]
Player Group -For each PlayerNumber in (Players on team (Picked Integer)) do (actions)
Set DetectTeam[PlayerNumber] to Picked Integer
What does this? you store inside an array each player's lobby team. It's not strictly necessary, but the code will be cleaner.
Step 4, 2/6 on the trigger: Initializing the new players array
As described in Step 1, each team has a computer ally. In this step, we'll initialize the new player numbers, and store them at those global variables from Step 2.
Pick each integer from 0 to 4 and do (actions) [0 to 4 because I have 4 players per team]
Set ProtossPlayers[Picked Integer] = Player 9
Set ZergPlayers[Picked Integer] = Player 10
This will make sure inactive players are controlled by the computers, and can't be used by the players. What I'm gonna use 0 for? to make sure I store the AI if the game is full house.
In my case, both teams have 4 players, so I can include both "set"s inside the same loop. Shall the teams have different number of max players, you would need 2 "pick"s with 1 "set" on each.
Step 5, 3/6 on the trigger: making the new players array
We have detected each player's team, so now, we'll create the new player numbers, writing over the initialized variable. Make 2 integers to keep track of the number of active players on each team:
ContProtossPlayers: integer = 1
ContZergPlayers: integer = 1
Let's go:
Player Group -for each PlayerNumber in Active Players do (actions)
If DetectGroup[PlayerNumber] = 1 then
Set ProtossPlayers[ContProtossPlayers] = PlayerNumber
Set ContProtossPlayers = ContProtossPlayers + 1
else
Set ZergPlayers[ContZergPlayers] = PlayerNumber
Set ContZergPlayers = ContZergPlayers + 1
If you have more than 2 teams, put more "if"s inside the "else" until you cover all cases. You could ignore the "else" and make 1 "if" with empty "else" for each team, but nesting them is more efficient, since the game won't check all "if"s in case it already matched a condition above.
With this, you have 2 arrays with all the players inside. Now, instead of using "Player x" you should use "ProtossPlayers[x]" or "Zerg Players[x]". The main problem should be solved.
Step 6, 4/6 on the trigger: alliances
This isn't necessary in most cases, but do it just in case anyway. We'll put all players inside a player group and then make them allied. You could do this one by one, but this is shorter.
Pick each integer from 0 to ContProtossPlayers and do (actions)
Player Group -Add ProtossPlayers[Picked Integer] to ProtossPlayerGroup
Pick each integer from 0 to ContZergPlayers and do (actions)
Player Group -Add ZergPlayers[Picked Integer] to ZergPlayerGroup
Player -Make all players inside group ProtossPlayerGroup treat each other as allies with shared vision
Player -Make all players inside group ZergPlayerGroup treat each other as allies with shared vision
You don't usually need to repeat this for enemies, since they start hostile by default, but do it if the AIs don't attack each other or some other weird stuff.
Step 7, 5/6 on the trigger: Save units' players
Now we're gonna change the ownership of all the placed units. Simply changing them is risky, because overwriting may give as a result 1 player without any unit at all and another with 2 players' units. Instead of using a third variable to save what we move and make sure we switch ownership when changing it, we're gonna simply save all players' by default. You'll need an array of unit group equal to the number of players:
Units: Unit Group array of [8]
Simple code now:
Pick each integer from 1 to 8 and do (actions)
Unit Group -Pick every unit matching (any unit in entire map owned by player(picked integer))
Add picked unit to Units[picked integer]
Now the original owners are saved for the last step.
Step 8, 6/6 on the trigger: Changing the ownership of the units
We'll need 2 integer variables for the looping here:
c1: integer = 1
c2: integer = 2
If you had 1234 players in team 1 and 5678 players in team 2 this would be more simpler, but this version isn't much more complexer anyway:
Pick each integer from 1 to 4
Unit Group -Pick each unit in Units[c1] and do (actions)
Unit -Change ownership of unit to ProtossPlayers[picked integer]
Unit Group -Pick each unit in Units[c2] and do (actions)
Unit -Change ownership of unit to ZergPlayers[picked integer]
Set c1 = c1 + 1;
Set c2 = c2 + 1;
Congratulations, now the lobby problems should be gone. You won't be able to match the exact slot, but now, each player will be at its correct team. The AIs will get control of empty players and no one will mess with them.
I hope this tutorial was of help for everyone. I didn't believe I would spend all this time writing it, lol.
Any doubt/problem, don't worry to ask me here :).
Don't understand some terms?
Differences between global and local variables: global can be accessed from any trigger, and keep their information safe, while locals are limited to its trigger, and get new values each time the trigger runs. Global variable appear outside, and locals appear inside its trigger.
Arrays: they're just a collection of variables, they're useful for navigating across that collection.
Loop/For/While: they repeat everything inside them until they reach their limit.
If/Else: executes actions depending on a condition.
Examples please, from all that I've read on all of this from other threads and also from here I have now a tumor the size of this post. I kinda understand what you mean and I've written much complicated things then this but am too frustrated to even comprehend whats going on.
Sorry if that sounds impatient but I know you know that this is such an annoying topic to be addressing if you haven't had an accomplished product to go off, In all honesty I've seen threads on this that are just blatant "Here's my code" and I understood those better then your thread... Maybe I'm just over thinking it.
EDIT: So I've sat down and am working through this code copying everything to the letter, I have come across some disturbing things, first of all I cant tell when you start a new trigger or not and the most disturbing thing is:
Set ProtossPlayers[Picked Integer] = Player 9
Set ZergPlayers[Picked Integer] = Player 10
How the hell did you just type "Player 9" when I search for 20 minutes that seems to be completely impossible unless it is a variable which you have not once stated so I am still dumbfounded as to how. I tried typing it in script then saving the map but it said error.
Sorry for new post but I cant put code in edited posts.
This is what I have, However I dont know how to use any of this to adjust the map. Player 9 and 10 are not allying anyone.
Sorry, but the code has a fatal error of pure-noobnes. If you copied it like it is and tested it with a decent number of player, you'll notice it gives array-size errors, because computer players are read wrong. I don't remember the exact bug. Yes, the code up there is B-A-D and you should ignore it. I'm sorry I forgot to update the tutorial and left an ambiguous "note: it's wrong" >_<.
I already fixed the code some weeks ago, but I'm remaking it right now for something more dynamic. I'll probably create a new tutorial with the third code and link it here.
And I'll attach a map with the code, don't worry. The translation they did to Spanish is pretty confusing most of the time, and no matter how well I translate it, if it was wrong from the beginning I can't fix it, and thus the code may be pretty confusing :S.
Wouldn't it be c1 + 2 and c2 + 2? Because if you just add 1, wouldn't you be taking the same player twice? Like for example, you set all c1 (set to 1) player units, and set them to protoss. Then you set all c2 (set to 2) player units, and set them to zerg. If you add 1 to each, wouldn't you then be setting player 2's units to being protoss, because wouldn't c1 then equal 2?
EDIT: Oh, nvm. Ur using picked integer to control which player, not the variables.
EDIT2: But it is still setting the ownership of a set of units to 2 different players. Hmmmm, I am confused lol
I tried using this for my map and spent a great deal of time changing all my triggers to work with this setup and couldn't get it to work in the slightest.
The worst part is, to test these triggers, I have to publish my map every time. There has got to be an easier way. If you're still looking at this and can take a look at my triggers (or anyone) it would be much appreciated.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Note: there seems to be some bug with this code in some particular situations, I've already fixed it, and hope to update the tutorial as soon as possible ;).
Welcome to my first tutorial: Beginners' guide: solving the lobby problems. I decided to write this after asking repeatedly around here and researching myself. It wasn't very hard to fix this problem, and most of my obstacles were basic "Is there a function for that?" situations. I hope this helps everyone, mostly beginners, fix their lobby problems and move to the development of their custom maps :).
So you have your own nice custom map, and you decide to place some shinny units and buildings.
Everything was ok; until you made the game have more than 1 team and the world exploded.
This tutorial is a very basic beginners' guide with the purpose of solving the main problem of the lobby right now (Patch 1.3.4). As you know (or maybe not) lobby slots have nothing to do with ingame players. Player number is determined by joining order (bravo, Blizz! /sarcasm).
And yes, if you switch team after joining, once the game starts, that player will have the units supposed to be in the other team, the units matching his player number by joining order. You can always lock the team so they can't switch, but well, it's 2011 right now.
This short tutorial is divided in 8 parts, which you'll understand even if you think *insert joke about how noob you may be*.
I'll use a 4v4 protoss vs zerg example (my actual custom map). I'm sorry for the lack of images, but I use the Spanish version, so, well :P. If you don't understand some basic terms, go the the end of the tutorial. I may have translated some functions incorrectly, so feel free to ask anything you don't understand (I made it on GUI so beginners can understand it better, and I could try to update the file later, although I'm not a fan of the copy+paste and don't understand how it works xD).
Step 1: game variants
First of all, I'll suppose you already know how this section works (or else you wouldn't be getting the problems). I only wanted to explain what I have here, so you understand my examples.
Players 1.3.5.7.9 are team 1, and players 2.4.6.8.10. 9 and 10 are computers. I do this instead of the simpler 12345 - 678910 because people logging in will spread between each team instead of filling team 1 and then team 2. Of course, doing it like this will make the loops a bit more complicated, but it isn't a big deal
Now, let's go!
Step 2: global variables
These variables don't need to be global, but you may find them useful for later. You need x arrays to store players of each team, and x player groups for alliances. You can make those arrays be separate or be inside another array, as you prefer. For this particular case, it doesn't matter too much.
Step 3, 1/6 on the trigger: Detecting each player's lobby team
Actually, you can't detect lobby slot (as far as I know), but you can detect the team. For this, I'll make a new local variable, an array of integers equal to the number of players, in my case, 8. Make another variable, a normal integer, named PlayerNumber, too.
Step 4, 2/6 on the trigger: Initializing the new players array
As described in Step 1, each team has a computer ally. In this step, we'll initialize the new player numbers, and store them at those global variables from Step 2.
This will make sure inactive players are controlled by the computers, and can't be used by the players. What I'm gonna use 0 for? to make sure I store the AI if the game is full house.
In my case, both teams have 4 players, so I can include both "set"s inside the same loop. Shall the teams have different number of max players, you would need 2 "pick"s with 1 "set" on each.
Step 5, 3/6 on the trigger: making the new players array
We have detected each player's team, so now, we'll create the new player numbers, writing over the initialized variable. Make 2 integers to keep track of the number of active players on each team:
If you have more than 2 teams, put more "if"s inside the "else" until you cover all cases. You could ignore the "else" and make 1 "if" with empty "else" for each team, but nesting them is more efficient, since the game won't check all "if"s in case it already matched a condition above.
With this, you have 2 arrays with all the players inside. Now, instead of using "Player x" you should use "ProtossPlayers[x]" or "Zerg Players[x]". The main problem should be solved.
Step 6, 4/6 on the trigger: alliances
This isn't necessary in most cases, but do it just in case anyway. We'll put all players inside a player group and then make them allied. You could do this one by one, but this is shorter.
You don't usually need to repeat this for enemies, since they start hostile by default, but do it if the AIs don't attack each other or some other weird stuff.
Step 7, 5/6 on the trigger: Save units' players
Now we're gonna change the ownership of all the placed units. Simply changing them is risky, because overwriting may give as a result 1 player without any unit at all and another with 2 players' units. Instead of using a third variable to save what we move and make sure we switch ownership when changing it, we're gonna simply save all players' by default. You'll need an array of unit group equal to the number of players:
Step 8, 6/6 on the trigger: Changing the ownership of the units
We'll need 2 integer variables for the looping here:
I hope this tutorial was of help for everyone. I didn't believe I would spend all this time writing it, lol.
Any doubt/problem, don't worry to ask me here :).
Don't understand some terms?
Examples please, from all that I've read on all of this from other threads and also from here I have now a tumor the size of this post. I kinda understand what you mean and I've written much complicated things then this but am too frustrated to even comprehend whats going on.
Sorry if that sounds impatient but I know you know that this is such an annoying topic to be addressing if you haven't had an accomplished product to go off, In all honesty I've seen threads on this that are just blatant "Here's my code" and I understood those better then your thread... Maybe I'm just over thinking it.
EDIT: So I've sat down and am working through this code copying everything to the letter, I have come across some disturbing things, first of all I cant tell when you start a new trigger or not and the most disturbing thing is: Set ProtossPlayers[Picked Integer] = Player 9 Set ZergPlayers[Picked Integer] = Player 10 How the hell did you just type "Player 9" when I search for 20 minutes that seems to be completely impossible unless it is a variable which you have not once stated so I am still dumbfounded as to how. I tried typing it in script then saving the map but it said error.
Sorry for new post but I cant put code in edited posts. This is what I have, However I dont know how to use any of this to adjust the map. Player 9 and 10 are not allying anyone.
I also moved to Team 2 and still spawned on team 1 following the "player 1 rules".
Sorry, but the code has a fatal error of pure-noobnes. If you copied it like it is and tested it with a decent number of player, you'll notice it gives array-size errors, because computer players are read wrong. I don't remember the exact bug. Yes, the code up there is B-A-D and you should ignore it. I'm sorry I forgot to update the tutorial and left an ambiguous "note: it's wrong" >_<.
I already fixed the code some weeks ago, but I'm remaking it right now for something more dynamic. I'll probably create a new tutorial with the third code and link it here.
And I'll attach a map with the code, don't worry. The translation they did to Spanish is pretty confusing most of the time, and no matter how well I translate it, if it was wrong from the beginning I can't fix it, and thus the code may be pretty confusing :S.
Wouldn't it be c1 + 2 and c2 + 2? Because if you just add 1, wouldn't you be taking the same player twice? Like for example, you set all c1 (set to 1) player units, and set them to protoss. Then you set all c2 (set to 2) player units, and set them to zerg. If you add 1 to each, wouldn't you then be setting player 2's units to being protoss, because wouldn't c1 then equal 2?
EDIT: Oh, nvm. Ur using picked integer to control which player, not the variables.
EDIT2: But it is still setting the ownership of a set of units to 2 different players. Hmmmm, I am confused lol
Great to be back and part of the community again!
I tried using this for my map and spent a great deal of time changing all my triggers to work with this setup and couldn't get it to work in the slightest.
The worst part is, to test these triggers, I have to publish my map every time. There has got to be an easier way. If you're still looking at this and can take a look at my triggers (or anyone) it would be much appreciated.