• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[GUI] Hashtable Creep Respawn System Using X, Y

Level 14
Joined
Jan 5, 2009
Messages
1,127
Note: This method may be inefficient but will possibly work.

Creep Respawn System Using Hashtable and X, Y

By Crazed_seal

How this Works

This Works by saving all the creeps co-ordinates(X, Y) into a hashtable.

Using X, Y co-ordinates is better than locations, as they do not leak and are faster.

They do not use as much memory as a location.

HashTable Init


First Create a Hashtable Variable and call it CRSHash.

Now Create a Point Variable and call that Temp_CRSPoint

The Hashtable will be used to store the X, Y. And the point will get us the X, Y of the units.

Trigger One


Ok.

Here is the trigger that will get us the X, Y.
  • Save
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • -------- Cleans some Group Leaks. Very Useful for temporary Groups. --------
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Actions)
        • Loop - Actions
          • Set Temp_CRSPoint = (Position of (Picked unit))
          • -------- Gets the Point of the Unit --------
          • Hashtable - Save (X of Temp_CRSPoint) as (Key (Picked unit)) of 0 in CRSHash
          • -------- Saves the X of the Unit --------
          • Hashtable - Save (Y of Temp_CRSPoint) as (Key (Picked unit)) of 1 in CRSHash
          • -------- Saves the Y of the Unit --------
          • Custom script: call RemoveLocation(udg_Temp_CRSPoint)
          • -------- Removes the Location to stop leaks. --------
The Trigger saves the X and Y of the Unit into the Hashtable under the units HandleID.

Revival

Time to make the revival Trigger.
  • Revival
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Wait 15.00 seconds
      • -------- Don't want them to instantly revive. --------
      • Set Temp_CRSPoint = (Point((Load (Key (Triggering unit)) of 0 from CRSHash), (Load (Key (Triggering unit)) of 1 from CRSHash)))
      • -------- Converts XY to Point --------
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at Temp_CRSPoint facing (Random angle) degrees
      • -------- Creates Replacement Unit at XY --------
      • Custom script: call RemoveLocation(udg_Temp_CRSPoint)
      • -------- Removes Point --------
      • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in CRSHash
      • -------- Clears Old Values of old unit. --------
      • Set Temp_CRSPoint = (Position of (Last created unit))
      • -------- Saves the units point --------
      • Hashtable - Save (X of Temp_CRSPoint) as (Key (Last created unit)) of 0 in CRSHash
      • -------- Grabs the X of units point --------
      • Hashtable - Save (Y of Temp_CRSPoint) as (Key (Last created unit)) of 1 in CRSHash
      • -------- Grabs the Y of units point --------
      • Custom script: call RemoveLocation(udg_Temp_CRSPoint)
      • -------- Removes the Point only leaving the XY Values stored in the Hashtable --------
Huzzah. This trigger actually doesn't revive the unit but creates a replacement.
The Old values of the unit are cleared.
And the new ones stored!

End

Hopefully you like this tutorial!
I have added a test Map. I made it myself.

~Crazed_seal
Your friendly Crazed Seal! :ogre_haosis:

 

Attachments

  • Test Map.w3x
    22 KB · Views: 123
Level 31
Joined
Jul 10, 2007
Messages
6,306
Actually, there are pluses and minuses between using coordinates and using locations. For general resources, it's typically good to use locations if those locations are passed in so that they may be modified by any other script w/o having to work specifically with your script. Using coordinates are good if they are only being changed within the system or by the mapper.


Also, coordinates are rather limited. If you used positions (either a widget or a location), you can use coordinates relative to the handle (for example, respawn at this unit). Respawning at units rather than coordinates makes it easier to handle camps and can also be useful for even general spawning.
 
Actually, there are pluses and minuses between using coordinates and using locations. For general resources, it's typically good to use locations if those locations are passed in so that they may be modified by any other script w/o having to work specifically with your script. Using coordinates are good if they are only being changed within the system or by the mapper.


Also, coordinates are rather limited. If you used positions (either a widget or a location), you can use coordinates relative to the handle (for example, respawn at this unit). Respawning at units rather than coordinates makes it easier to handle camps and can also be useful for even general spawning.

Saving handles in hashtables increases the handle count, unless I am testing it wrong. I think that alone may make reals more desirable to use. ;)

@Crazed_Seal: Don't forget to support unit facing! ;D
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
You can reuse the location here:

  • Revival
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Wait 15.00 seconds
      • -------- Don't want them to instantly revive. --------
      • Set Temp_CRSPoint = (Point((Load (Key (Triggering unit)) of 0 from CRSHash), (Load (Key (Triggering unit)) of 1 from CRSHash)))
      • -------- Converts XY to Point --------
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at Temp_CRSPoint facing (Random angle) degrees
      • -------- Creates Replacement Unit at XY --------
      • Hashtable - Save (X of Temp_CRSPoint) as (Key (Last created unit)) of 0 in CRSHash
      • -------- Grabs the X of units point --------
      • Hashtable - Save (Y of Temp_CRSPoint) as (Key (Last created unit)) of 1 in CRSHash
      • -------- Grabs the Y of units point --------
      • Custom script: call RemoveLocation(udg_Temp_CRSPoint)
      • -------- Removes the Point only leaving the XY Values stored in the Hashtable --------
      • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in CRSHash
      • -------- Clears Old Values of old unit. --------
This also won't work if the respawn time is longer than the decay time. The triggering unit won't exist after it has decayed and therefore trying to get it's unit type will return null and no unit is created.
 
Top