How to: Create a Creep Revival System

Tinki3

Special Member
Reaction score
418
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.

creepsystemimage1variabgi7.jpg


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:
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
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:
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:
Code:
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:
Code:
Unit - Create 1 [COLOR="Red"](Unit-type of (Triggering unit))[/COLOR] for [COLOR="red"]Neutral Hostile[/COLOR] at [COLOR="red"]((Center of (Entire map))[/COLOR] [COLOR="red"]offset[/COLOR] by [COLOR="red"](Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))]))[/COLOR] 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:

creepsystemimage2step1de9.jpg


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:
Code:
Unit - Set the custom value of [COLOR="Red"](Last created unit)[/COLOR] to (Custom value of (Triggering unit))

You should have all of the following:
Code:
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):
 

Attachments

  • Creep Revival System.w3x
    30.4 KB · Views: 1,937
nice tutorial, for GUI triggers Revival System, this is only the time i found GUI revive system, well theres some JASS or custom scripts, but i can understand a lot of that cause im studying JASS already....+rep Tinki3 ^^ hey i cant add..ohh shocks...
 
Good job on the tut. My rpg went out hte window along with the rest of my stuff when my computer crashed so i probably wont be getting around to using this, but other people certainly have been asking for this.
 
Made one of these a while back. But this has better trigger explanations.
 
Hey mind if i Mention yo in my tutorial?
I made a tutoral on this in JASS.
 
nice, last week im trying to develop this, i do, but many people cant ^^ i will + rep, but i dont have more to give :(
 
If the air unit was owned by Neutral Hostile and was not summoned, then it fits the conditions and it would have been revived. Somebody correct me if I'm wrong, but as far as I know you don't need to specify wether or not it was an air unit.

Anyway, great tutorial, once I get finished laying out all the heroes for my map, I'll probably be using this. I never knew you could do it like this. +rep Tinki3
 
JASS:
function Trig_Unit_Revive_Conditions takes nothing returns boolean
    return (IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false) and (IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == false)
endfunction

function Trig_Unit_Revive_Actions takes nothing returns nothing
	local integer idu = GetUnitTypeId(GetTriggerUnit())
	local real rezx = GetUnitX(GetTriggerUnit())
	local real rezy = GetUnitY(GetTriggerUnit())
	local real face = GetUnitFacing(GetTriggerUnit())
	call CreateUnit(GetOwningPlayer(GetTriggerUnit()), idu, rezx, rezy, face)
endfunction

//===========================================================================
function InitTrig_Unit_Revive takes nothing returns nothing
    set gg_trg_Unit_Revive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Revive, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Unit_Revive, Condition( function Trig_Unit_Revive_Conditions ) )
    call TriggerAddAction( gg_trg_Unit_Revive, function Trig_Unit_Revive_Actions )
endfunction


Isn't this a lot easier, maybe not the summoned unit thing but it revives the creeps just fine. Though it doesn't revive at their starting location.
Just stick this in your map and your good to go.
 
Just re-read this.
If you only gave the global an array of one, why can you use it so many more times?
Also, I would think to use Point(X, Y) instead of an offset.
 
Wow Awesome

:)

What can I say it's all there is......


Good Job..........
 
I used this and its great, before I had it just: a unit dies - replace dead one with a new one at last ones corpse, which alows for leading them to fountain and going afk then come back with tons of xp, TY

Question:

I have a hero with Cannibalism, When he eats the corpses, the don't respawn, because it gets rid of the corpse, and they stay dead. How can i fix this, (So creeps respawn even w/o corpse) ??
 
>How can i fix this

Hmm.
You'd have to get a bit tricky here.

You could "fake" the cannibalism by just having you click on the corpse, and having the hero play the animation, but just don't have the corpse eaten by the hero.

What I mean by this, is that you'd have to trigger the healing process for the caster. Is that possible for you?
 
Does this not leak?

Code:
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) degree


Unit - Create 1 (Unit-Type of (Triggering unit)) for Neutral Hostile at (Center of (Entire map)).

That creates 1 leak, you should edit your post :p

Cheers
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/
  • The Helper The Helper:
    Happy Thursday!
  • Ghan Ghan:
    I'm not so sure, there's still a lot of Thursday left for it to become unhappy.
    +3
  • The Helper The Helper:
    still a few hours
  • The Helper The Helper:
    Its Friday!!!!
    +1
  • Ghan Ghan:
    Thursday 7/10 would Thursday again
    +3
  • The Helper The Helper:
    New forum coming soon going to be for my friend Saylor who is blind and he is doing motivational speaking and has an internet radio show and podcast. I am going to put a forum to promote him and other inspirational speaker stuff going to have some good stuff in it.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top