How to: Create a Creep Revival System

Tinki3

Special Member
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.



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:



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

waaaks!

Zinctified
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...
 

undeadorcjerk

The Ulitimate TheHelper.net Lurker
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.
 

Oninuva

You can change this now in User CP.
Made one of these a while back. But this has better trigger explanations.
 

MaaxeEvid

New Member
nice, last week im trying to develop this, i do, but many people cant ^^ i will + rep, but i dont have more to give :(
 
M

MikeTheGuy

Guest
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
 

Prometheus

Everything is mutable; nothing is sacred
Staff member
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.
 

Prometheus

Everything is mutable; nothing is sacred
Staff member
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.
 
0

026sasuke026

Guest
Wow Awesome

:)

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


Good Job..........
 
A

AK-47Pirates

Guest
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) ??
 

Tinki3

Special Member
>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?
 

Icyculyr

I'm a Mac
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.
  • Varine Varine:
    They aren't cutting my responsibilities or interjecting in my management abilities or anything, it's just stupid shit that comes up. And they don't exactly have people lining up for my job, there's not that many people applying for the positions I hire
  • Varine Varine:
    Eh, whatever. Thanks for listening guys
  • jonas jonas:
    Sure :) Let us know how it ends
  • Varine Varine:
    All of these things will end happily, they're just stressful. And I still lack many good friends that I can go to, and the ones I can are preoccupied with similar things. Thus general chit chat, cuz for some reason TH and Ghan and Tom all actively keep it up.
  • Varine Varine:
    Just gotta keep Miss Mazie up through the week until her shock wears off and she realizes that she still has family all around her, and bossman will do whatever he's going to do and I'll respond appropriately when it happens. Thank you all for the support, I do very much appreciate everyone being here for me through the years
    +3
  • vypur85 vypur85:
    Best of luck Varine!
  • vypur85 vypur85:
    I just gotten myself an offer to work in China. The pay quadruples my current one. Damn.... Not really ready to start a new life there in China.
  • The Helper The Helper:
    I have heard that they pay pretty good to English teachers in China - you would be an expat
  • jonas jonas:
    Cool, what kind of job?
  • Accname Accname:
    I would be careful with jobs in China. They can be hit and miss depending on where in China you go. Places like hong kong / Shengzen / Beijing can be neat. Other places not so much.
  • Accname Accname:
    I would recommend searching for some first person experiences for the city you got the offer in. Especially now when the political situation in China is deteriorating.
  • jonas jonas:
    Accname, long time no see
  • jonas jonas:
    What have you been up to
  • tom_mai78101 tom_mai78101:
    Hey Accname, welcome back.
  • Accname Accname:
    Not much. Working in the Renewable Energy Sector as an IT Consultant. Its okay, but I think I preferred working at the university. It was more relaxed and you met all kinds of crazy people there.
  • vypur85 vypur85:
    I gotten a teaching position for Biology in a college in Wuhan (yes, there)... I suppose it should be fine there (I hope). Many of my ex colleagues are teaching in China as well currently (none in Wuhan though)
  • vypur85 vypur85:
    And I signed the contract already. I guess there's no turning back....
  • jonas jonas:
    @Accname how many hours do you work? I heard in some sectors IT consultants rack up insane hours
  • jonas jonas:
    @vypur85 sounds nice, have fun : )
  • Accname Accname:
    I am supposed to work 40 hrs a week, but I can work more if I like and I will be paid for those hours (as long as I don't go too far, there are laws and company policies, etc)
  • Accname Accname:
    In practice its basically work as much as you like, as long as the job gets done in time.
  • jonas jonas:
    Haha, my job is like that as well... that usually means I have a few 70-80 hours weeks a year, and lots of 20 hours weeks...
  • jonas jonas:
    a few weeks ago, one of my friends basically said "jonas, I received an invitation to submit something to conference X but I'm too lazy to do it and also the conference isn't advanced enough for my high level of research*, why don't you write something? Oh by the way, the deadline is in two weeks. Enjoy!" so I got two 80 hour weeks out of that kind offer. (*of course he didn't say those parts, but it's a better story this way)
  • jonas jonas:
    now I'll have next week off to make up for overtime :p and I'll play some good old gothic 2
  • The Helper The Helper:
    Hope you are enjoying that gothic 2~

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome
    Top