Simple Tug of War Spawning System - Data & Trigger working hand in hand!
To create this system we will do, 1 Behavior, 1 Effect (Issue Order). Modify our "Barrack & Marine" unit's to allow simple testing. Create a "Trigger & Action Definition" to manage our attack commands. Let's get to it!
First go to the behavior's tab.
If you do not already have the behavior tab open, click on the green + sign then game data and select behaviors like shown in this picture.
Create a new behavior (Right-click -> Add Behavior) and make it a buff type behavior.
Ok. We are going to leave that there for now and we will go create our "Issue Order" effect. Go to the "Effect" Tab using the same + sign as the behavior if you don't already have it open. Right click and add "Effect".
Remember when you are naming your data entries to always click suggest to set it's ID correctly.
In this "Issue Order" effect we are going to change the following values:
"Effect: Ability" Which we will set to Barracks - Train. We are setting it to that ability since we want to affect the barrack's training system. Had it been the starport, it would have been starport - train. This can be set to any "Train Like" Ability.
"Effect: Ability Command" Here we don't change it for the simple reason that our marine is at the first position of the command card already.
"Effect: Player+" Set to (None):Caster. So the effect affects who? The casting unit's player. Us! :D
"Effect: Unit+" Set to (None):Caster. Same principle as before. Who do we want it to affect. US!!!
"Target: Target+" Set to (None): Caster Unit. Again same idea as the last 3...
Going back to our "Behavior" in the "Behavior" tab!!!
Now that we have created an "Effect" that will queue a unit, we need to connect it with the unit. Our behavior that we created earlier will do this.
For the purpose of this tutorial, I decided that queuing a unit every 5 seconds would be perfect.
Field's to be modified in our "Behavior"
"Behavior: Buff Flags" Uncheck them all exept Remove Exhausted Damage Response (Could probably uncheck that one too but I never messed with that so...)
"Effect: Effect - Periodic" Set to your "Issue Order Effect" That we created.
"Stats: Flags" Check Hidden since we don't want the player to see that the barrack has a "Behavior".
"Stats: Period" Set to 5. This will regulate the time between the "Issue Order Effect". Since we are adding the behavior directly on the unit it will take 5 seconds before the first queue starts.
As you can see in the picture I have "Effect: Effect - Initial" Set to the same (Issue Order). I was attempting to make the queue order trigger directly when the game started but to no avail. When the behavior is already on a unit it will take "Period Time" before the first action happends.
Ok. We now have a "Behavior" which trigger's an "Effect". This Said effect is to queue a marine. Sweet! Now we need to add that "Behavior" to our Barrack.
Select the Units tab with the Green + sign again.
Search for the "Barrack" unit and select it. We are going to be modifying the "Behavior: Behavior+".
Double click on the field and Add a behavior.
Select the behavior you created earlier.
Bam!!! you've got a working Automatic Marine Factory but it won't work just yet. Our marine still costs us 50 Mineral (Freaking overpriced crap! Can you believe that? pfff) and requires 1 Supply depot!!!
Let's go remove that small requirement.
In the same tab (Units tab!!!)
Search for marine.
Search for the Cost+ Field (just write cost) and put it's mineral cost to 0!
then scroll down to "Starts: Supplies" and set that to 0.
Voila. The data side is over!
On to Triggers!
First, create your trigger (CTRL+T). For the purpose of this tutorial we will be using the "Unit enter's region" Event.
This trigger is pretty much just like our behavior. It will only serve to give us the information we need to proceed.
Leave that trigger empty with it's event for now. Let's create an action definition! (CTRL+ALT+R)
Name it how ever you want but I like to put a +sign to find my action's faster and keep the name simple and to the point. For this tutorial, +Unit is Created.
Click the option's and check on "Create Thread". (Please refer to my triggering tutorial for information on this. Link is in my signature.)
In the "Parameter's" add an integer value "Parameter". I named it PlayerID but feel free to call it whatever. It will refer to the "Triggering Player".
Add a "Unit" Parameter which we will use to figure out which kind of unit has just spawned.
In this "Action Def" We will create an "If then Else" statement. Create an If then else action in the general tab of triggers.
In the "IF" part of this statement, which is where we set our condition's, we will check if the unit that has just spawned (Our "Unit" parameter) is a marine.
So (CTRL+W) and click on the ( bracket on the left. That will pop up a menu. Search for type of unit and select "Unit Type of Unit".
For the other side of the statement select the "Marine".
In the "Then" part of the statement, we want to "Issue an order" to the unit that has just spawned. (CTRL+W) and in the unit tab select "Issue order".
Set the "Unit" Variable in the "Issue order" Action to our "Unit Parameter" value.
For the next field, click on the ( bracket again like last time and select "Order Targeting Point" (or relative point like in this tutorial). Then the location is up to you. You can switch it to a region or just use a simple point. That's up to you.
And the last but not the least. In most Tug of war maps the player cannot select the spawned units. This can be done though data or triggers. I did it with a simple line in this tutorial. The command is "Set Unit State". Set the "Unit Variable" to our unit parameter and the state is selectable which we set to off.
Few.... Our "Action def" is finished!!!!!!
Now all we have to do is link it with our trigger.
Voila. Working (simple) tug of war system.
I included the demo map. Enjoy!
Special thanks to Zeldarules and FockeWulf for adding detail into the idea and fixing a few bugs that I missed :D.