Hashtable trigger not working as intented

Level 11
Joined
Feb 5, 2018
Messages
485
  • Lightning Link
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Lightning Link
    • Actions
      • Set VariableSet LL_Index = (LL_Index + 1)
      • Unit Group - Add LL_Caster to LL_CastGroup
      • Set VariableSet LL_Caster = (Triggering unit)
      • Hashtable - Save Handle OfLL_Caster as 0 of (Key (Triggering unit).) in LL_Hash.
      • Set VariableSet LL_Loc1 = (Position of LL_Caster)
      • Hashtable - Save Handle OfLL_Loc1 as 1 of (Key (Triggering unit).) in LL_Hash.
      • Set VariableSet LL_Time = 100.00
      • Hashtable - Save LL_Time as 2 of (Key (Triggering unit).) in LL_Hash.
      • Set VariableSet LL_Damage = (Real((Level of Lightning Link for LL_Caster)))
      • Hashtable - Save LL_Damage as 3 of (Key (Triggering unit).) in LL_Hash.
      • Set VariableSet LL_UG = (Units within 625.00 of LL_Loc1 matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of LL_Caster).) Equal to True)).)
      • Unit Group - Pick every unit in LL_UG and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to False
              • ((Picked unit) is Mechanical) Equal to False
              • ((Picked unit) is Magic Immune) Equal to False
              • ((Picked unit) is dead) Equal to False
            • Then - Actions
              • Hashtable - Save Handle OfLL_UG as 4 of (Key (Triggering unit).) in LL_Hash.
              • Set VariableSet LL_Target = (Picked unit)
              • Hashtable - Save Handle OfLL_Target as 5 of (Key (Triggering unit).) in LL_Hash.
              • Set VariableSet LL_Loc2 = (Position of LL_Target)
              • Hashtable - Save Handle OfLL_Loc2 as 6 of (Key (Triggering unit).) in LL_Hash.
              • Custom script: set udg_LL_Lightning = AddLightningEx("FORK", true , GetLocationX(udg_LL_Loc1), GetLocationY(udg_LL_Loc1), GetLocationZ(udg_LL_Loc1) + 70, GetLocationX(udg_LL_Loc2), GetLocationY(udg_LL_Loc2), GetLocationZ(udg_LL_Loc2) + 70)
              • Set VariableSet LL_Lightning = (Last created lightning effect)
              • Set VariableSet LL_Distance = (Distance between LL_Loc1 and LL_Loc2)
              • Hashtable - Save LL_Distance as 8 of (Key (Triggering unit).) in LL_Hash.
              • Hashtable - Save Handle OfLL_Lightning as 7 of (Key (Triggering unit).) in LL_Hash.
              • Lightning - Change color of LL_Lightning to (0.75 0.75 0.00) with 0.66 alpha
              • Custom script: call DestroyLightning (udg_LL_Lightning)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LL_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on LL Loop <gen>
        • Else - Actions
  • LL Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LL_CastGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet LL_Time = (Load 2 of (Key (Picked unit).) from LL_Hash.)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LL_Time Greater than 0.00
            • Then - Actions
              • Hashtable - Save (LL_Time - 1.00) as 2 of (Key (Picked unit).) in LL_Hash.
              • Set VariableSet LL_Caster = (Load 0 of (Key (Picked unit).) in LL_Hash.)
              • Set VariableSet LL_Target = (Load 5 of (Key (Picked unit).) in LL_Hash.)
              • Set VariableSet LL_UG = (Load 4 of (Key (Picked unit).) in LL_Hash.)
              • Set VariableSet LL_Loc1 = (Load 1 of (Key (Picked unit).) in LL_Hash.)
              • Set VariableSet LL_Loc2 = (Load 6 of (Key (Picked unit).) in LL_Hash.)
              • Set VariableSet LL_Distance = (Load 8 of (Key (Picked unit).) from LL_Hash.)
              • Set VariableSet LL_Damage = (Load 3 of (Key (Picked unit).) from LL_Hash.)
              • Set VariableSet LL_Lightning = (Load 7 of (Key (Picked unit).) in LL_Hash.)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LL_Distance Greater than 625.00
                • Then - Actions
                  • Unit Group - Remove LL_Target from LL_UG.
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (LL_Caster is dead) Equal to True
                • Then - Actions
                  • Set VariableSet LL_Index = (LL_Index - 1)
                  • Custom script: call DestroyLightning (udg_LL_Lightning)
                  • Custom script: call DestroyGroup (udg_LL_UG)
                  • Custom script: call RemoveLocation (udg_LL_Loc2)
                  • Custom script: call RemoveLocation (udg_LL_Loc1)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (LL_Target is dead) Equal to True
                • Then - Actions
                  • Unit Group - Remove LL_Target from LL_UG.
                  • Game - Display to (All players) the text: (String((Number of units in LL_UG)))
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in LL_UG) Equal to 0
                • Then - Actions
                  • Set VariableSet LL_Index = (LL_Index - 1)
                  • Custom script: call DestroyGroup (udg_LL_UG)
                  • Custom script: call DestroyLightning (udg_LL_Lightning)
                  • Custom script: call RemoveLocation (udg_LL_Loc1)
                  • Custom script: call RemoveLocation (udg_LL_Loc2)
                • Else - Actions
              • Unit Group - Pick every unit in LL_UG and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is A structure) Equal to False
                      • ((Picked unit) is Mechanical) Equal to False
                      • ((Picked unit) is Magic Immune) Equal to False
                      • ((Picked unit) is dead) Equal to False
                    • Then - Actions
                      • Set VariableSet LL_Loc1 = (Position of LL_Caster)
                      • Set VariableSet LL_Target = (Picked unit)
                      • Set VariableSet LL_Loc2 = (Position of LL_Target)
                      • Unit - Cause LL_Caster to damage LL_Target, dealing LL_Damage damage of attack type Spells and damage type Magic
                      • Custom script: set udg_LL_Lightning = AddLightningEx("FORK", true , GetLocationX(udg_LL_Loc1), GetLocationY(udg_LL_Loc1), GetLocationZ(udg_LL_Loc1) + 70, GetLocationX(udg_LL_Loc2), GetLocationY(udg_LL_Loc2), GetLocationZ(udg_LL_Loc2) + 70)
                      • Set VariableSet LL_Lightning = (Last created lightning effect)
                      • Lightning - Change color of LL_Lightning to (0.75 0.75 0.00) with 0.66 alpha
                      • Custom script: call MoveLightningEx(udg_LL_Lightning , true, GetLocationX(udg_LL_Loc1), GetLocationY(udg_LL_Loc1), GetLocationZ(udg_LL_Loc1) + 70, GetLocationX(udg_LL_Loc2), GetLocationY(udg_LL_Loc2), GetLocationZ(udg_LL_Loc2) + 70)
                      • Set VariableSet LL_Distance = (Distance between LL_Loc1 and LL_Loc2)
                    • Else - Actions
            • Else - Actions
              • Custom script: call DestroyGroup (udg_LL_UG)
              • Custom script: call RemoveLocation (udg_LL_Loc1)
              • Custom script: call RemoveLocation (udg_LL_Loc2)
              • Custom script: call DestroyLightning (udg_LL_Lightning)
              • Set VariableSet LL_Index = (LL_Index - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LL_Index Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
So I am trying to make an ability that links the enemy units within 625 AoE to caster using lightning effect , if the distance becomes more than 625 the link is broken.

I'm just gonna put my whole map here since it's in the very early days of progress.
 

Attachments

  • HeroSurvival.w3m
    208.5 KB · Views: 13

Uncle

Warcraft Moderator
Level 42
Joined
Aug 10, 2018
Messages
4,189
1) You're adding LL_Caster to LL_CastGroup before setting it. This makes the first cast bug out since it can't find LL_Caster.

2) You're leaking Unit Groups, Points, and Lightning.

3) You're re-creating the Lightning AND trying to move the old Lightning. You only need to create 1 Lightning per unit and then move it.

4) You don't need to save/load a lot of these variables. The Distance for example, you'll need to re-calculate it anyway so there's no point in saving it.

That being said, I was messing around with Lightning and I think Reforged is bugged as the Forked Lightning effect fades away on it's own. It also only creates lightning around some units instead of all of them. Normally the lightning is supposed to stay there forever until you destroy it yourself. Not sure why any of this is happening, it's really weird.

Anyway, I attached an edited version of your map. I was trying to get the Hashtable to work and I realized that it's way overkill and extra work. You don't need a Hashtable for this type of trigger. Instead I used Dynamic Indexing.
Visualize: Dynamic Indexing

Since I couldn't get the Lightning to work properly I instead create the lightning over and over again. You were already doing this so it looks exactly the same. Ideally, you would want to create the lightning once at the start for each picked unit, store it to it's respective picked unit, and then remove it accordingly.

Also, I think your Unit Indexer is out of date and doesn't support more than 12 players. You should update it to the latest version. Also, you don't need to create your Hashtables in the Unit Indexer trigger. The Unit Indexer provides an Event for this:
  • Map Initialization
    • Events
      • Game - UnitIndexEvent becomes Equal to 3.00
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet MightHash = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet LL_Hash = (Last created hashtable)
 

Attachments

  • HeroSurvival U2.w3m
    208.1 KB · Views: 22
Last edited:
Level 11
Joined
Feb 5, 2018
Messages
485
Yeah I noticed that the lightning died, when it was created, so that is why I used to create it again.

I was using hashtables, because I really need to make them work, for a lot of other things and just can't figure them out. (So I tried)

I have read the Visualize: Dymanic Indexing, probably 10 times. :D Thanks anyway for linking it.

Haha, I didn't know I was leaking so many things.

Thank you very much for your help :), the trigger runs fine and smooth.
 
Top