• 🏆 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!

[Trigger] Variable[Key(Unit Handle)] Problems

Status
Not open for further replies.
Level 14
Joined
Aug 31, 2009
Messages
775
Hey everyone, I'm learning some HashTable functions and also the Key conversion tools.

Is it possible for me to do something like:
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • --Doesn't Matter--
  • Actions
    • Unit - Create 1 Footman for (Owner of (Triggering Unit)) at (blah blah blah blah.....)
    • Unit Group - Add (Last created unit) to UnitGroup[Key(Triggering Unit)]
And then later
  • Events
    • Unit - A unit dies
  • Conditions
    • ---Doesn't Matter---
  • Actions
    • Unit Group - Pick Every unit in UnitGroup[Key(Triggering Unit)] and do (Actions)
      • Unit - Kill (Picked Unit)
      • Unit Group - Remove (Picked Unit) from UnitGroup[Key(Triggering Unit)]

What I'm doing is a spell that summons units, but I want it so that when the caster dies, all the units summoned by that specific caster die.

I've tried a very basic set up as shown above, but it refuses to work.
What am I doing wrong here?


EDIT: I think I know the issue. By using a debug trigger to get the Key of units, it turns out the keys are usually around 7 digits long, and the Array of the Unit Group cannot take a number that big.

So how do I go about solving this problem?
 
Last edited:
Maybe store Unit Groups instead of units?
  • Untitled Trigger 002
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set tempGroup = (Load (Key "SummonedUnits") of (Key (Triggering Unit)) in HashTable)
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to tempGroup
      • Hashtable - Save Handle OftempGroup as (Key "SummonedUnits") of (Key (Triggering Unit)) in HashTable
      • Custom script: call DestroyGroup( udg_tempGroup )
 
I always thought you would "store" the things (as being copied) onto the hashtable instead of "attaching". So ya DestroyGroup would also destroy the group that is in the hashtable.

Ok after some testings I couldn't get it to work at all (using Hashtables and make it MUI). So i am as clueless as you are Damage, sorry =P

Edit
Another idea: Everytime you cast the skill and it summons monster you can save the handle id of the caster onto the summoned unit. Also add the summoned unit to a unit group. Now if someone dies you loop through the summoned unit group and load their "Master's" Handle Id from the summoned unit, if they match with the unit that died, remove them.
Don't know if it works, just a thought.
Edit2
Above idea is tested and works.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
(GetHandleId() - GetHandleId(null or was it the first handle in the map)) gives you a small number size which people use in linked arrays to do exactly what you sujested. It is faster than hashtables but will bug if there is any form of leak or if your map is too large so that it exceeds the size of the linked arrays. The speed boost is atmost twice as fast (takes half the time) so really it is not too much better.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • Untitled Trigger 049
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • (Level of Holy Light for (Triggering unit)) Equal to 1
    • Actions
      • Set Temp_Group = (Units within 1.00 of (Position of (Triggering unit)) matching (((Matching unit) is A structure) Equal to True)) // this is just something to create an empty group
      • Hashtable - Save Handle OfTempGroup as (Key group) of (Key (Triggering unit)) in Ability_Hash
  • Untitled Trigger 046
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Ability being cast equal to ...
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to (Load (Key group) of (Key (Triggering unit)) in Ability_Hash)
  • Untitled Trigger 047
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set TempGroup = (Load (Key group) of (Key (Triggering unit)) in Ability_Hash)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Unit Group - Remove (Picked unit) from TempGroup
          • Unit - Kill (Picked unit)
Every time the unit casts Holy Light, a footman is created. When the unit dies, all footmans spawned by Holy Light will die. These triggers leak locations.

You also may need to destroy the unit group and clear child hashtable if the unit is not revived.
 
Level 14
Joined
Aug 31, 2009
Messages
775
Maker is ... woah.

Nearly every single topic I've made in the last few days regarding any issue he just comes along and annihilates the problem with some awesome triggering.

Also, Dragoon Zombie I kind of like your method also.

+REP to everyone who chipped in on this, it was of great help.

EDIT: Though I can't give it to Maker yet as I already gave him some about half an hour ago for an earlier problem :p
 
Status
Not open for further replies.
Top