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

[Trigger] Proper working hashtables

Status
Not open for further replies.
Level 6
Joined
Jun 15, 2008
Messages
175
I am currently unaware of how to make a hashtable succesfully work besides the way wyrmlord demonstrated in his tutorial :(.
I am not sure where the problem lies, but I've tried several things, and can't seem to locate the problem.

I am trying to fix some leaks, but there are several of them, and I need to clean all of them, I thought a hashtable would be the solution to my problem.
Here's some of my work so far. I want it to store the id from each lightning effect - but I can't seem to manage, could anyone tell me how this works.
wyrmlord does not describe why he uses that specific key. As in load 0 key (Targeted Point of Ability Being Cast). Please explain, as I am baffled and I need of assistance :p

  • Craving Attention
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Craving Attention
    • Actions
      • Trigger - Turn on Ca Loop <gen>
      • Hashtable - Create a hashtable
      • Set CA_Hashtable = (Last created hashtable)
      • Set CA_CasterPosition = (Position of (Casting unit))
      • Set CA_Caster = (Casting unit)
      • Set CA_Duration = 1.00
      • Set CA_Heal = -50.00
      • Set Ca_Damage = 50.00
      • Set Ca_UnitGroup = (Units within 500.00 of CA_CasterPosition)
      • Set Ca_TempUnit = (Random unit from Ca_UnitGroup)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CA_Duration Greater than 0.00
        • Then - Actions
          • Unit Group - Pick every unit in Ca_UnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) belongs to an ally of (Owner of CA_Caster)) Equal to True
                • Then - Actions
                  • Lightning - Create a Healing Wave - Primary lightning effect from source (Position of CA_Caster) to target (Position of (Picked unit))
                  • Set CA_Handle = (Load 0 of (Key (Picked unit)) in CA_Hashtable)
                  • Unit - Cause CA_Caster to damage (Picked unit), dealing CA_Heal damage of attack type Spells and damage type Normal
                • Else - Actions
                  • Lightning - Create a Chain Lightning - Primary lightning effect from source (Position of CA_Caster) to target (Position of Ca_TempUnit)
                  • Unit - Cause CA_Caster to damage Ca_TempUnit, dealing Ca_Damage damage of attack type Spells and damage type Normal
        • Else - Actions
          • Lightning - Destroy (Load 0 of (Key (Picked unit)) in CA_Hashtable)
          • Trigger - Turn off Ca Loop <gen>
          • Custom script: set udg_Ca_TempUnit = null
 
Level 4
Joined
Apr 16, 2009
Messages
85
most importantly: you override the hashtable every time the spell is casted which defeats the whole purpose of hashtables - you should create it in a separate trigger that runs only on map initialization

the other thing is: i only see you loading values but never setting them - that doesn't really make sense
 
Level 6
Joined
Jun 15, 2008
Messages
175
Yep, you've got me, I am as confused as a bunch of caddle only living to be slaugtered... and there it was the uneitivable slaugther :p.
Enough joking around, I have no clue what I am doing you see, plus it's in the middle of night here in Denmark, and I need my sleep in order to think. But you could please tell me how to do then?
 
Level 9
Joined
May 28, 2007
Messages
365
You only need to create 1 hashtable for your map (in most cases). Go into the variable editor and create a variable of type hashtable.

Then in another SEPERATE trigger that has the event Map Initialization, use set YOURVARIABLE = CreateHashtable()

If you want to store all the lightning you create, use the hashtable like this. Use a tempInteger variable.

Each time you create lightning do this:
set tempinteger = tempInteger + 1
SaveLightningHandle - save lastcreatedlightning, in YOURHASHTABLE, parentkey is GetHandleId(yourunit), childkey is tempInteger)

At the end of your spell, if you want to remove all of them, make a loop like this
set tempInteger = tempInteger - 1
Action - Remove Lightning (getlightninghandle(YOURHASHTABLE, GetHandleId(yourunit), tempInteger)

This will create the lightning, add their handle to the hashtable, then remove the lightning afterwars.

At the end of it all be sure to flush your hashtable with the parent key GetHandleId(yourunit)
 
Level 4
Joined
Apr 16, 2009
Messages
85
Each time you create lightning do this:
set tempinteger = tempInteger + 1
SaveLightningHandle - save lastcreatedlightning, in YOURHASHTABLE, parentkey is GetHandleId(yourunit), childkey is tempInteger)

At the end of your spell, if you want to remove all of them, make a loop like this
set tempInteger = tempInteger - 1
Action - Remove Lightning (getlightninghandle(YOURHASHTABLE, GetHandleId(yourunit), tempInteger)

i agree but don't use that tempInteger thing use a constant as the parentkey (any number just make sure you don't use the same number in different spells) and GetHandleId(yourunit) as the child key later load that and remove the value (you'll need custom script for that)
 
Status
Not open for further replies.
Top