The goal of this tutorial is to create a buff that can be attached to any unit that will make the unit gain energy while it is attacking. This achieves a WoW-Rogue like effect for your units, where they can spend energy on abilities the more they attack.
This is a very simple tutorial and is useful for starting work with Buffs and Units.
Creating Our Buff
We'll create a new Buff Behavior called "Combo Energy". We basically want this buff to increase the unit's Energy Regeneration Rate while the unit is attacking.
Open the Data Editor and set the Data Type to Behaviors. Buffs are a type of Behavior and they directly affect the unit they are attached to. Right click the list below and choose Add Object.... This will bring up a panel for creating a whole new behavior. Set the Name to Combo Energy. Click the Suggest button. Set the Behavior Type to Buff. The other options on this panel allow you to have the editor automatically fill in some fields based on previously created Behaviors. We're making one from scratch so leave everything else alone and click OK.
On the right panel you'll now see a bunch of fields listed out. It may seem overwhelming at first, but you'll begin to notice the few important fields you'll normally be dealing with while mapping. Some very important fields, you'll notice, are those with a "+" on the end of them. This merely means that the field takes multiple values and generally has a special menu to fill in data, but these tend to be important because a lot of functionality is handled here.
Our Buff is going to work by changing the unit's energy regeneration rate to a non-negative value. All of the important data for Buffs is tucked away in the Modification + field. Again, notice the "+". Go ahead and double click on the Modification + field. It may take a while, but a menu should pop up.
Again, you're presented with a ton of fields and information. Remember, it will take time, but you'll soon begin to understand how to ignore fields that you don't care about and hone in on the important ones. This menu in particular has a lot of information because it shows every possible value we can change for a unit through this buff. That's a lot of stuff, but we're here for just one thing: Energy Regeneration Rate.
Scroll down through the menu until you find Vital Regeneration Bonus. It's not too far down, just keep looking. You will see a list of the "vitals" which are just Energy, Shields, and Life. Clearly, we're going to want to change the Energy vital. Select the Energy item from the list and change the Selected Value(s) to 5.0. We're all done with this panel. Click OK.
So, what we have just done is made our Buff modify the unit's Energy Regeneration Rate by increasing it by 5 points. It is important to note that this is not setting the rate to 5.0, but increasing it by 5.0.
We still have a problem, though, this buff will always be active, and that won't do. We only want energy to increase so long as the unit is attacking something! This is where Validators come in. Validators are yet another element of the Data Editor. They basically allow for conditions to be checked before a Buff, Ability, or what have you is activated. So, we need a validator to check that the unit is attacking and have our buff only active while it is attacking.
As you may have guessed, we'll be editing the Validators (Disable) field at the bottom of our buff. Notice there are two Validator types. Validators (Disable) is a list of validators, that, when one is not valid, will only disable the buff. That is, if conditions change and the validators are all valid, then the buff will become active again. The Validators (Remove) will remove the buff when something is invalid. Meaning, even if the validators are all valid later on, the buff has been removed from the unit and therefore won't affect the unit.
So, inside of the Validators (Disable) field click the green X and in the popup find the CasterIsAttacking (Unnamed) Validator. Select it and click OK. This is the only validator we'll need for this buff, so click the OK button to close the field edit.
Our buff will now be disabled anytime the "caster" isn't attacking. Caster is just basically the unit being affected by this buff.
Ok, so now we have our neat Combo Energy buff. We need to give it to a unit so that the unit can enjoy the glory of energy gain.
In the Data Editor, change the Data Type to Units. Find the Marine element. Right click the Marine and choose Duplicate Object.... In the popup, check the box next Marine under the Actors folder. Click OK.
When we duplicated objects, there is a lot of data associated with the original object. This menu allows us to pick what associated data we would like to copy as well. Why are we only copying the Marine actor? Because Actors are objects which connect visuals to the units. There can only be one Actor per Unit. So, if we weren't to copy the Marine Actor, our new marine, when placed in the game, would appear as a transparent sphere since there is no visual data associated with the unit. So, we copy along the Actor with our new unit. If we wished change data about the Marine's Gauss Rifle, then we would copy this value too. But we're just messing around with energy for now. Again, this is something you'll get a feel for the more you play with the editor.
So, when you clicked OK, it made a new object with the fields copied from the original Marine. At the moment there is no difference between the two units, except for the name. The editor assigns it, by default, to "[Origin Name] Copy". We'll go ahead and change this. Right click the Marine Copy and choose Modify Object....
You'll see a familiar panel pop up. Change the name to Energy Marine and click Suggest. Leave the other options alone and click OK. There, our marine now has a proper name.
With our new Energy Marine selected, look at the fields on the right. These are all of the options we can change for a Unit. We're going to give the Marine some Energy. Scroll down through fields and find and edit the Stats - Energy Maximum field. Change the value to 100. This gives the unit a maximum energy level of 100. Change the Energy Regeneration Rate to -1. This makes the energy level tick down. Note: the energy level will never go negative. Leave the Energy Starting Amount at 0. This way, our marine won't start with energy.
Good, now our Marine will have an energy bar and will lose energy slowly if he ever has energy. If you wanted to give the Marine a standard energy feel, like the Ghost, just set the Regeneration Rate to something positive.
Ok, we're almost done, we now need to actually give the Energy Marine our Combo Energy buff! Find the (None) - Behaviors + field and edit it. Notice there is already a Behavior in here: the Shield. You can remove or keep this. But let's add our Combo Energy buff. Click the green X to the right and, with the new blank line selected, change Behavior to Combo Energy. Click OK.
There we have it. Our Energy Marine now has the Combo Energy buff. To test it out, place an Energy Marine on the map and give him some enemies to fight. Watch as his energy level increases as he attacks, and drops as he idles!
Of course, the Energy Marine has no Abilities to spend energy on, as that is out of the scope of this tutorial, but see if maybe you can't figure it out. Remember, one of the best ways to figure out how to do something is to look at how previously created units already do it. For example, if you want to make your Energy Marine Blink, look at the Stalker Unit.