• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Creep Respawn (GUI)

Level 16
Joined
Mar 26, 2004
Messages
569
Creep Respawn (GUI) - Difficulty: 3/10

-------------------------

Introduction
This tutorial explains how to make units owned by a certain player to respawn at their original position after a given amount of time.

The Tutorial
-------------------------
Setup
There are a few things you'll need to set up. Let's begin with the variables.

Variables
- Open your Trigger Editor and press CTRL+B to open the variable manager.
- While there press CTRL+N to create a new variable.
- Set "Variable Type" to Integer and set "Variable Name" to Temp_Integer. Then press OK.
- Press CTRL+N again to create another variable. Set this one's variable type to Point and name it Creep_Point. In this one, you'll also check the [ ] Array field for the variable. Then press OK.
- One last time, press CTRL+N to create a new variable. Set it's type to Real and name it Respawn_Time. Then press OK.

By now, you should have these 3 variables:

attachment.php


The Map
Now, to respawn units you'll need some units. So go ahead and place some units on your map. Set these unit's owner to Neutral Hostile.

-------------------------

Triggers
Initialization

We'll start off with the Map Initialization trigger, which are the triggers that are run when the map has finished loading.

  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Respawn_Time = 5.00
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
        • Loop - Actions
          • Set Temp_Integer = (Temp_Integer + 1)
          • Unit - Set the custom value of (Picked unit) to Temp_Integer
          • Set Creep_Point[Temp_Integer] = (Position of (Picked unit))
By doing this you stored the position for all units owned by Neutral Hostile into the variable you created which will be used to respawn the unit at that location.
Note: The amount you set for Respawn_Time is how long the next trigger will wait before respawning the unit.

The Respawn

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Custom Value of (Triggering unit)) Greater than 0
    • Actions
      • Custom script: local integer i = GetUnitTypeId(GetTriggerUnit())
      • Custom script: local integer ii = GetUnitUserData(GetTriggerUnit())
      • Wait Respawn_Time game-time seconds
      • Custom script: call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_Creep_Point[ii]),GetLocationY(udg_Creep_Point[ii]),270),ii)
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Custom Value of (Triggering unit)) Greater than 0
    • Actions
      • Wait Respawn_Time game-time seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Creep_Point[(Custom value of (Triggering unit))] facing Default building facing (270.0) degrees
      • Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))
Adding a creep to Respawn
To add creeps, that are spawned during the game's progress, to the "Respawn" trigger you'll have to make this trigger:

  • Add Creep to Respawn
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Set Temp_Integer = (Temp_Integer + 1)
      • Unit - Set the custom value of (Triggering unit) to Temp_Integer
      • Set Creep_Point[Temp_Integer] = (Position of (Triggering unit))
And that's that! All finished.
In conclusion: This will make a unit owned by Neutral Hostile that dies respawn at it's original position after a set amount of time.

Footnote
This system has only been tested in a small scale and I am totally unaware of leaks, so if anyone could point them out it would be appreciated.

Please comment and criticize the content and be picky about grammar and spelling errors, i don't want it to be faulty.

-------------------------

Hope it was useful! And hope it hasn't been done before! Over and out. ~SkriK
 

Attachments

  • Untitled-3.gif
    Untitled-3.gif
    1.6 KB · Views: 24,315
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
I'll review this tomorrow morning, assuming I don't forget, and assuming I have nothing to do in computer engineering (Otherwise, tomorrow afternoon).

EDIT: Here we go

  • Respawn_Time isn't really needed, just inline it.
  • (Triggering Unit) is generally more stable than (Dying Unit), especially after waits. I suggest you use that.
  • You should store the unit type and custom value of the dying unit in locals before the wait, so that if the respawn time is longer than the decay time it still works.
  • PolledWait should be used (Wait x Game-Time Seconds) as it factors in Pause Game.
  • Perhaps add a function to add a new unit to the list of ones that respawn? If you don't know Jass, here's one that would work;
    JASS:
    function AddUnitToRespawn takes unit whichUnit returns nothing
        set udg_Temp_Integer = udg_Temp_Integer + 1
        call SetUnitUserData(whichUnit,udg_Temp_Integer)
        set udg_Creep_Point[udg_Temp_Integer] = GetUnitLoc(whichUnit)
    endfunction
  • Neutral hostile units with Custom Value 0 (no respawn point) should not be attempted to revive (this will cause them to appear in the middle of the map).
 
Last edited:
Level 16
Joined
Mar 26, 2004
Messages
569
I'll review this tomorrow morning, assuming I don't forget, and assuming I have nothing to do in computer engineering (Otherwise, tomorrow afternoon).

EDIT: Here we go

  • [1]Respawn_Time isn't really needed, just inline it.
    [2](Triggering Unit) is generally more stable than (Dying Unit), especially after waits. I suggest you use that.
    [3]You should store the unit type and custom value of the dying unit in locals before the wait, so that if the respawn time is longer than the decay time it still works.
    [4]PolledWait should be used (Wait x Game-Time Seconds) as it factors in Pause Game.
    [5]Perhaps add a function to add a new unit to the list of ones that respawn? If you don't know Jass, here's one that would work;
    JASS:
    function AddUnitToRespawn takes unit whichUnit returns nothing
        set udg_Temp_Integer = udg_Temp_Integer + 1
        call SetUnitUserData(whichUnit,udg_Temp_Integer)
        set udg_Creep_Point[udg_Temp_Integer] = GetUnitLoc(whichUnit)
    endfunction
    [6]Neutral hostile units with Custom Value 0 (no respawn point) should not be attempted to revive (this will cause them to appear in the middle of the map).
1: Sorry, but what does "Inline" mean? (Triggerwise)
2: Fixed
3: Locals? Is that variables that are cleared using custom text after being used?
4: Fixed
5: Done:
  • Unit - Create 1 Footman for Neutral Hostile at (The Point You Selected)) facing Default building facing (270.0) degrees
  • Set Temp_Integer = (Temp_Integer + 1)
  • Unit - Set the custom value of (Last created unit) to Temp_Integer
  • Set Creep_Point[Temp_Integer] = (Position of (Last created unit))
6: It is set to 1 before storing the first unit.

Will add triggers to the tut once you confirm they're correct.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
1: Sorry, but what does "Inline" mean? (Triggerwise)
Get rid of the constant and sub in its value wherever it is used (since this is only used in one, easily accessible place).

3: Locals? Is that variables that are cleared using custom text after being used?
Jass only (though you can accomplish them via "Custom Script"), they are variables which pertain only to a specific instance of a specific function.

There is even a trick to make them usable in GUI.

Basically, while this will require Custom scripts for the trigger, it will fix the potential mentioned bug. You would change your death trigger to (This form also fixes said bug):

I added comments to explain what's going on

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Custom Value of (Triggering Unit)) Greater than 0
    • Actions
      • Custom script: local integer i = GetUnitTypeId(GetTriggerUnit())
      • -------- The previous line declares a new local integer, i, which is equal to the type of the dying unit --------
      • Custom script: local integer ii = GetUnitUserData(GetTriggerUnit())
      • -------- The previous line declares a new local integer, ii, which is equal to the custom value of the dying unit --------
      • Wait Respawn_Time seconds
      • Custom script: call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_Creep_Point[ii]),GetLocationY(udg_Creep_Point[ii]),270),ii)
      • -------- The previous line creates a new unit for neutral hostile at the old respawn point of the old type, and sets its custom value to the value of the old unit --------
6: It is set to 1 before storing the first unit.
But some (that aren't initialized with this sytem) won't have it and will bug, which would be fixed by a simple condition.
 
Level 9
Joined
May 30, 2008
Messages
430
thank you for the great trigger +rep for the good work:grin: i found a problem why maximum wait time in all trigger of this type can be around 60-100 seconds when i add wait 320 seconds trigger even don't run why this happen??
 
Last edited:
Level 2
Joined
Aug 17, 2008
Messages
11
Well, i did what i was supposed to do in your tutorial but when i tested it out the the spawn doubled. Ex: 1,2,4,8 etc.

nvm i got it fixed i found out what i did wrong
 
Last edited by a moderator:
Level 3
Joined
Jul 18, 2008
Messages
53
a little problem here, i made everything like in tutorial and ingame the respawn time is something like Unit - A unit Dies, Action - Immediatelly Respawn :| and i made every thing like in the tut
 
Level 2
Joined
Jan 26, 2009
Messages
8
Hey, im having problems with the condition:

(Custom Value of (Triggering unit)) Greater than 0

So please anyone help? :)
 
Level 2
Joined
Jan 28, 2009
Messages
15
Thanks for this respawn trigger, mine respawned where the creep died(not good if its pulled XD )
+rep :)

1question, what exactly is "custom value"? is that like a predefined variable all units have that is defaulted to 0?
 
Level 12
Joined
Jan 6, 2009
Messages
848
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
      • (Custom Value of (Triggering Unit)) Greater than 0
    • Actions
      • Custom script: local integer i = GetUnitTypeId(GetTriggerUnit())
      • -------- The previous line declares a new local integer, i, which is equal to the type of the dying unit --------
      • Custom script: local integer ii = GetUnitUserData(GetTriggerUnit())
      • -------- The previous line declares a new local integer, ii, which is equal to the custom value of the dying unit --------
      • Wait Respawn_Time seconds
      • Custom script: call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_Creep_Point[ii]),GetLocationY(udg_Creep_Point[ii]),270),ii)
      • -------- The previous line creates a new unit for neutral hostile at the old respawn point of the old type, and sets its custom value to the value of the old unit --------
But some (that aren't initialized with this sytem) won't have it and will bug, which would be fixed by a simple condition.


But isn't only possible to set 1 local in every trigger in GUI?
 
Level 8
Joined
Apr 8, 2009
Messages
499
Good job!

Thanx for the first post for the respawn system SkriK, really helped me out with my orpg map. :thumbs_up:

just a question:
is it possible to make them respawn facing the same angle as when they were placed? :confused:


ifso please post the triggers :mwahaha:


ofc +Rep is given! :cute:
 
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

First: Ofc +rep =)

Second: But i got a problem with:
JASS:
Custom script:   call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_Creep_Point[ii]),GetLocationY(udg_Creep_Point[ii]),270,ii)

Always shown up a syntax Error from Jass Helper. I looked over it some times, but I cant find any mistake. Are I'm blind or can I ignore this - because the trigger doesn't turn off.
 
Level 18
Joined
Oct 25, 2006
Messages
1,175
Tip: for those who want to improve the respawning system :
Just add another variable "Creep_Facing" (Real, Array on).

Groupe unité - Pick every unit in (Units in (Playable map area) owned by Neutre Hostile) and do (Actions)
Boucle - Actions
-->
Set Creep_Face[Temp_Integer] = (Facing of (Picked unit))

Then change the trigger when the unit dies.
Unité - Create 1 (Unit-type of (Triggering unit)) for Neutre Hostile at Creep_Point[(Custom value of (Triggering unit))] facing Creep_Face[(Custom value of (Triggering unit))] degrees
 
Level 4
Joined
May 20, 2009
Messages
96
Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)

there no way to do that

you cant add the "owned by neautral hostile" i dont see a way to do that

(Owner of (Triggering unit)) Equal to Neutral Hostile
(Custom Value of (Triggering unit)) Greater than 0


i suck at conditions can u tell me where to find those?

(Owner of (Triggering unit)) Equal to Neutral Hostile
(Custom Value of (Triggering unit)) Greater than 0


can you tell me how to get to those?

[email protected]

Custom script: call SetUnitUserData(CreateUnit(Player(12),i,GetLocationX(udg_Creep_Point[ii]),GetLocationY(udg_Creep_Point[ii]),270),ii)


forget about those other comments i needed help on i figured them out because im smart...but that custom script up there -----^ isnt letting me enable my trigger any help?

and it didnt work for me anyone :[
 
Last edited by a moderator:
Level 2
Joined
Jun 6, 2009
Messages
14
hey how i get the things i write to the other menu ???? i have testad evrything please help!

how i get the variables to triggers plese help :)
 
Last edited by a moderator:
Top