• 🏆 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] Arrays to Hashtable. Am I doing it right?

Status
Not open for further replies.
Level 5
Joined
Jan 17, 2014
Messages
131
Hi everyone. So yeah, I'm trying to learn how to use hashtables and I was wondering if you could please look at my triggers and tell me if I'm actually succeeding in transforming them from arrays to a hashtabe. Thank you in advance.



  • Cast Array
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Life Transfer (ivo)
    • Actions
      • Set LT_Index = (LT_Index + 1)
      • Set LT_Caster[LT_Index] = (Triggering unit)
      • Set LT_Target[LT_Index] = (Target unit of ability being cast)
      • Set LT_Counter[LT_Index] = 0.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LT_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Loop Array <gen>
        • Else - Actions
  • Cast Hastable
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Life Transfer (ivo)
    • Actions
      • Hashtable - Save Handle Of(Target unit of ability being cast) as (Integer(target)) of (Key (Triggering unit)) in LT_Hashtable
      • Hashtable - Save 0.00 as (Integer(counter)) of (Key (Triggering unit)) in LT_Hashtable
      • Unit Group - Add (Triggering unit) to LT_Hashtable_Group
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Loop Hashtable <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Loop Hashtable <gen>
        • Else - Actions
          • Do nothing


  • Loop Array
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer LT_Loop) from 1 to LT_Index, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LT_Counter[LT_Loop] Less than 1.50
              • (LT_Target[LT_Loop] is alive) Equal to True
              • (Life of LT_Target[LT_Loop]) Greater than or equal to 50.00
            • Then - Actions
              • Unit - Set life of LT_Caster[LT_Loop] to ((Life of LT_Caster[LT_Loop]) + 50.00)
              • Unit - Cause LT_Caster[LT_Loop] to damage LT_Target[LT_Loop], dealing 50.00 damage of attack type Chaos and damage type Universal
              • Set LT_Counter[LT_Loop] = (LT_Counter[LT_Loop] + 0.50)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LT_Counter[LT_Loop] Less than 1.50
                  • (LT_Target[LT_Loop] is alive) Equal to True
                  • (Life of LT_Target[LT_Loop]) Less than 50.00
                • Then - Actions
                  • Unit - Set life of LT_Caster[LT_Loop] to ((Life of LT_Caster[LT_Loop]) + (Life of LT_Target[LT_Loop]))
                  • Unit - Cause LT_Caster[LT_Loop] to damage LT_Target[LT_Loop], dealing (Life of LT_Target[LT_Loop]) damage of attack type Chaos and damage type Universal
                  • Set LT_Counter[LT_Loop] = (LT_Counter[LT_Loop] + 0.50)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (LT_Target[LT_Loop] is alive) Equal to False
                          • LT_Counter[LT_Loop] Greater than or equal to 1.50
                    • Then - Actions
                      • Set LT_Caster[LT_Loop] = LT_Caster[LT_Index]
                      • Set LT_Target[LT_Loop] = LT_Target[LT_Index]
                      • Set LT_Counter[LT_Loop] = LT_Counter[LT_Index]
                      • Set LT_Index = (LT_Index - 1)
                      • Set LT_Loop = (LT_Loop - 1)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • LT_Index Equal to 0
                        • Then - Actions
                          • Trigger - Turn off (This trigger)
                        • Else - Actions
                    • Else - Actions
  • Loop Hashtable
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LT_Hashtable_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load (Integer(counter)) of (Key (Picked unit)) from LT_Hashtable) Less than 1.50
              • ((Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable) is alive) Equal to True
              • (Life of (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable)) Greater than or equal to 50.00
            • Then - Actions
              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 50.00)
              • Unit - Cause (Picked unit) to damage (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable), dealing 50.00 damage of attack type Chaos and damage type Universal
              • Hashtable - Save ((Load (Integer(counter)) of (Key (Picked unit)) from LT_Hashtable) + 0.50) as (Integer(counter)) of (Key (Picked unit)) in LT_Hashtable
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load (Integer(counter)) of (Key (Picked unit)) from LT_Hashtable) Less than 1.50
                  • ((Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable) is alive) Equal to True
                  • (Life of (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable)) Less than 50.00
                • Then - Actions
                  • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + (Life of (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable)))
                  • Unit - Cause (Picked unit) to damage (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable), dealing (Life of (Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable)) damage of attack type Chaos and damage type Universal
                  • Hashtable - Save ((Load (Integer(counter)) of (Key (Picked unit)) from LT_Hashtable) + 0.50) as (Integer(counter)) of (Key (Picked unit)) in LT_Hashtable
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Load (Integer(counter)) of (Key (Picked unit)) from LT_Hashtable) Greater than or equal to 1.50
                          • ((Load (Integer(target)) of (Key (Picked unit)) in LT_Hashtable) is alive) Equal to False
                    • Then - Actions
                      • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in LT_Hashtable
                      • Unit Group - Remove (Picked unit) from LT_Hashtable_Group
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (LT_Hashtable_Group is empty) Equal to True
                        • Then - Actions
                          • Trigger - Turn off (This trigger)
                        • Else - Actions
                          • Do nothing
                    • Else - Actions
                      • Do nothing


  • Cancel Array
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • (Ability being cast) Equal to Life Transfer (ivo)
    • Actions
      • For each (Integer LT_Loop) from 1 to LT_Index, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LT_Caster[LT_Loop] Equal to (Triggering unit)
            • Then - Actions
              • Set LT_Counter[LT_Loop] = 1.50
            • Else - Actions
  • Cancel Hashtable
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • (Ability being cast) Equal to Life Transfer (ivo)
    • Actions
      • Unit Group - Pick every unit in LT_Hashtable_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to (Picked unit)
            • Then - Actions
              • Hashtable - Save 1.50 as (Integer(counter)) of (Key (Picked unit)) in LT_Hashtable
            • Else - Actions
              • Do nothing

 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
Hashtable - Save Handle Of(Target unit of ability being cast) as (Integer(target)) of (Key (Triggering unit)) in LT_Hashtable
Hashtable - Save 0.00 as (Integer(counter)) of (Key (Triggering unit)) in LT_Hashtable

You can just use
Hashtable - Save Handle Of(Target unit of ability being cast) as 0 of ...
Hashtable - Save 0.00 as 1 of ..

Well you could use 0 for both since unit is of type handle and 0 is an integer so they would not overwrite. But don't worry about that.

Why would you transfer for arrays to hashtable? The array method is good. The only benefit you get from hashtables with this is not having to loop in the cancel trigger:
Hashtable - Save 1.50 as (Integer(counter)) of (Key (Triggering unit)) in LT_Hashtable

The array method also supports multiple instances for the caster running at the same time whereas the hashtable method only supports one per caster at the same time.
 
Level 5
Joined
Jan 17, 2014
Messages
131
I know the array method is good. I just wanted to know if I transformed it into a hashtable correctly. I'm still learning. Also, thank you for your response, I appreciate it. So, you're saying that I did it right?

You can just use
Hashtable - Save Handle Of(Target unit of ability being cast) as 0 of ...
Hashtable - Save 0.00 as 1 of ..

I just wanted to label them.

not having to loop in the cancel trigger:
Hashtable - Save 1.50 as (Integer(counter)) of (Key (Triggering unit)) in LT_Hashtable

Right. I guess that possibility skipped my mind.
 
Status
Not open for further replies.
Top