How to: Create a Creep Revival System

Tutorial By Tinki3

Introduction

This tutorial will explain in great detail, how to create a creep revival system. To understand this tutorial properly, you will need some decent knowledge of how to use the World Editor - mainly triggers, and variables.

We will be covering how to revive creeps 1 by 1, some time after their death, at their original starting location.

So if you're having any trouble at all creating a revival system, or if you just want to know how its done, read closely, and open the World Editor; this tutorial will be the perfect guide for you.

The "Revive creeps 1 by 1" trigger has minor leaks.



Let's get started

We will be needing the following variables:

Creep_X - A real type variable, with an array size of 1.
Creep_Y - A real type variable, with an array size of 1.
Integer - An integer type variable.

(Image)

The best way to initialize our creep's starting locations, is to use a trigger with a Map initialization event, and store their data using the help of our variables that we created earlier. We need to store every creeps starting locations so we know where to revive them when need be. We will be using each creeps X and Y values to accomplish this.

"Creep_X" will store all of our creep's X values and "Creep_Y" will store all of our creep's Y values. X and Y work like locations (Points), except they act more or less like offsets (co-ordinates), which work just fine in a revival system like we are going to produce.

"Integer" does something very important which I will explain soon enough.

So open up the trigger editor, and create a new trigger titled "Creep Revival System Initialization", or whatever, and add in the following:
Creep Revival System Initialization Events Map initialization Conditions Actions Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions) Loop - Actions Set Integer = (Integer + 1) Unit - Set the custom value of (Picked unit) to Integer
So what have we done so far? We've picked every unit in the playable map area (the area that is inside the black border around your map), owned by Neutral Hostile (the player that usually owns creeps) and set that player's creep's custom values to that of the integer's value, so specific reference can be made in-future.

Why are we using "Integer" to set our creep's custom values?

Well, you see the "Loop Actions" located directly below our Unit Group function?

That loop will "loop" through every creep/unit Neutral Hostile owns, until it loops through the last one.

Thus, "Integer" will keep adding 1 to its current value through every loop and thus when we set the picked creep's custom values, it'll end up looking like the following set of data, which is just what we need:

1, 2, 3, 4, 5, 6... and it goes on, right up until the last creep's value, which is actually the total amount of creeps that were pre-placed in your map.

Our creep's custom values are also important for referring to specific variable array values.

So now we need to set those X any Y variables, to store each creep's starting locations, using a Custom Script code:
Creep Revival System Initialization Events Map initialization Conditions Actions Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions) Loop - Actions Set Integer = (Integer + 1) Unit - Set the custom value of (Picked unit) to Integer Custom script: set udg_Creep_X[udg_Integer] = GetUnitX(GetEnumUnit()) Custom script: set udg_Creep_Y[udg_Integer] = GetUnitY(GetEnumUnit())
You see those [ ] marks, with "udg_Integer" between them? They are crucial to each creep's X and Y values.

But how do they work? Well, since they have an array value, those variables have the ability to "duplicate" themselves, enabling us to refer back to each "duplicated" value individually. And, since we are using "Integer" as our array index, we'll end up getting Creep_X[1], Creep_X[2], Creep_Y[1], Creep_Y[2], (etc, etc..), with each value referring to each picked unit as they are picked through the loop in the unit group function.

Note that "GetEnumUnit()", refers to each unit that is picked inside the loop; its just the custom script version for picked unit.

---

Now that we've successfully initialized our creeps, we want to create a trigger that actually revives them.

So what's the best event to use in this case? "Unit - A unit Dies".

This event let's the trigger fire as soon as a unit dies, but, we want to be specific do we not? We need to add in a condition that checks who the dying unit belonged to, and if the dying unit was a "summoned" or not.

Why? Because otherwise the "dying unit" could've belonged to Player Red, who just lost a Footman in battle, or Player Blue, who just sacrificed an Acolyte for a Shade.

And why don't we want the dying unit to be a "summoned"? Simply because a summoned unit isn't a unit that was originally pre-placed on your map, and isn't what we want to revive, is it?

So create a new trigger titled "Revive Creeps 1 by 1", or whatever, and add in the following:
Revive Creeps 1 by 1 Events Unit - A unit Dies Conditions ((Owner of (Triggering unit)) Equal to Neutral Hostile) and (((Triggering unit) is Summoned) Not equal to True) Actions
And now we probably would want to add in a wait to our actions, so the dying creep's revival time is delayed, for obvious reasons.

So what do we do now? Yes, we want to revive, or, re-create the dying creep (notice that I use "triggering unit" - DO NOT use "Dying unit" -> it will be overwritten by any other instances of the trigger).

Add the following action in to your trigger, below the wait action:
Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at ((Center of (Entire map)) offset by (Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))])) facing (Random angle) degrees

You might be wondering "how do I get to the point where I have one massive line of text across my screen"

You will need to note that the unit is created at an offset:

(Image)

It's best to break the whole unit creation action down, if you're unsure:

Unit-type of (Triggering unit) - We want to re-create the type of unit that has died.

Neutral Hostile - We want to re-create the type of unit that has died, for Neutral Hostile, the "creep owner".

at ((Center of (Entire map)) offset by.. - We want to re-create the type of unit that has died, for Neutral Hostile, the "creep owner", at the Center of the Entire map, offset by our creeps original X and Y location, that we first initialized in the initialization trigger. Remember that our Creep's X and Y value is the key to the "offset".

(Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))])) - Our dying creep will be recreated at the coordinates "Creep_X", and "Creep_Y", which are offset from the Centre of the Entire map. We use the Entire map as a centre, simply because it includes areas outside the playable map area - areas that units cannot reach, and since we are using X and Y coordinates, using playable map area would not give us the exact offset point of the creep's original location. Notice that for array index value, we are using the custom value of the triggering unit - this is because the unit's custom value tells the variable what array value needs to be used.

So, is there anything more left to do?

Yes, there is - we need to set the custom value of the "last created unit" to the custom value of the "triggering unit" (the dead creep).

Why? So if that last created unit dies, the "Creep_X" and "Creep_Y" variables know which array values to refer to again.

So add in the following line:
Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))

You should have all of the following:
Revive Creeps 1 by 1 Events Unit - A unit Dies Conditions ((Owner of (Triggering unit)) Equal to Neutral Hostile) and (((Triggering unit) is Summoned) Not equal to True) Actions Wait 5.00 game-time seconds Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at ((Center of (Entire map)) offset by (Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))])) facing (Random angle) degrees Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))
[Leak-fix-link for the above trigger]


A quick summary:

> A creep dies, the creep's name is Bobble.

> Bobble has a custom value of 4.

> When Bobble died, a trigger fired.

> The trigger told itself that Bobble wasn't a summoned unit, and that Bobble belonged to Neutral Hostile (Bobble is a creep).

> In no time at all, or, after a few seconds, Bobble was "revived", at the coordinates, "Creep_X[4]", "Creep_Y[4]", which had told the trigger where Bobble's original starting point was.

> The new Bobble also had its custom value set to 4, so that when it dies again, the trigger knows what Creep X & Y array indexes to use.


---

Well, we've hit the end of the road and I hope you learned a thing or 2 :)

If you've got any comments, suggestions, please feel free to share them.

This tutorial also includes a demo map (enjoy, and I hope it helps):

Click here to comment on this tutorial.
 
 
Blizzard Entertainment, Inc.
Silkroad Online Forums
Team Griffonrawl Trains Muay Thai and MMA fighters in Ohio.
Apex Steel Pipe - Buys and sells Steel Pipe.