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

[Trigger] Hashtable Trigger that increases stacks, please help [REFORGED]

Status
Not open for further replies.
Level 12
Joined
Feb 5, 2018
Messages
521
INI Trigger

  • Might
    • Events
      • Game - PDD_damageEventTrigger becomes Equal to 1.00
    • Conditions
      • (Level of Might for PDD_target) Greater than 0
      • (PDD_target belongs to an enemy of (Owner of PDD_source).) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 33
    • Actions
      • Hashtable - Save Handle Of(Triggering unit) as 3 of (Key (Triggering unit).) in MightHash.
      • Set VariableSet MightStacksMax = ((Level of Might for (Load 3 of (Key (Triggering unit).) in MightHash.)) x 5)
      • Hashtable - Save MightStacksMax as 2 of (Key (Triggering unit).) in MightHash.
      • Game - Display to (All players) the text: ((String(MightStacks)) + ( / + (String(MightStacksMax))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Load 3 of (Key (Triggering unit).) in MightHash.) is in MightUG.) Equal to False
        • Then - Actions
          • Unit Group - Add (Load 3 of (Key (Triggering unit).) in MightHash.) to MightUG
          • Game - Display to (All players) the text: Unit Added To Group
          • Hashtable - Save 15.00 as 1 of (Key (Triggering unit).) in MightHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MightStacks Less than MightStacksMax
        • Then - Actions
          • Set VariableSet MightStacks = (MightStacks + 1)
          • Hashtable - Save MightStacks as 0 of (Key (Triggering unit).) in MightHash.
          • Hero - Modify Strength of (Load 3 of (Key (Triggering unit).) in MightHash.): Add 4.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MightStacks Equal to 1
        • Then - Actions
          • Trigger - Turn on Might Check <gen>
        • Else - Actions
The Hastable is created in map initialization trigger.

In the initial trigger I want to increase stacks of might for a unit, giving it 4 strength for 15 seconds. The max stacks for each level of might is 5.

Might Level 1: Max stacks 5
Might Level 2: Max stacks 10
And so on

In the loop trigger it reduces the stacks of the unit after 15 seconds have passed and subtracts it's strength by 4.

The current issue is that all units getting attacked share the same stacks. I had two units on the map, and the total count of bonus strength for the units were 20 in total.
Unit 1: Base strength 55 + 8 (This unit used 2 stacks of might)
Unit 2 Base Strength 55 + 12 (This unit used 3 stacks of might)

So the units shared the stacks making stack count 5/5 for both units.
Instead of having individual count.

I added the unit group check, because without it one unit were running on multiple stacks at the same time meaning it gained 4 strength for every stack, unlimited times.

This is my first hashtable trigger I made. I have used dynamic unit indexing for the loop triggers in the past, but someone told me to run things like this with hashtables so here I am trying.

I think i'm pretty close to making this work and if someone can help me make this work, I can make stack abilities with hashtables in the future and other hashtable things with loops. :)

LOOP Trigger

  • Might Check
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MightUG and do (Actions)
        • Loop - Actions
          • Set VariableSet MightTime = (Load 1 of (Key (Picked unit).) from MightHash.)
          • Set VariableSet MightTarget = (Load 3 of (Key (Picked unit).) in MightHash.)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MightTime Greater than 0.00
            • Then - Actions
              • Hashtable - Save (MightTime - 1.00) as 1 of (Key (Picked unit).) in MightHash.
              • Game - Display to (All players) the text: (String(MightTime))
            • Else - Actions
              • Hero - Modify Strength of (Picked unit): Subtract 4.
              • Set VariableSet MightStacks = (MightStacks - 1)
              • Hashtable - Save MightStacks as 0 of (Key (Picked unit).) in MightHash.
              • Game - Display to (All players) the text: End of Timer --- Re...
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MightStacks Equal to 0
            • Then - Actions
              • Game - Display to (All players) the text: ---END OF LOOP---
              • Hashtable - Clear all child hashtables of child (Key (Picked unit).) in MightHash.
              • Unit Group - Remove (Picked unit) from MightUG.
              • Trigger - Turn off (This trigger)
            • Else - Actions
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
You’re not saving MightStacks in the hashtable individually for each unit. You’re using one global variable for all instances of the spell so of course they all share it.

Turning off the periodic when mightstacks = 0 will not work here because other instances might still be active. Check if the unit group is empty. Same logic in the cast trigger for when to turn on the periodic.
 
Level 12
Joined
Feb 5, 2018
Messages
521
Yea I figured, I just had no idea how to do that. I tried so search all the forums for abilities with stacks, made with hashtables. But unfortunately didn't find anything, that could help me.

I kinda gave up on hashtables :( for now

I'm doing it with locals. Do you mind if I post that here? :D It adds and subtracts the strength for multiple units. There is just one initialization problem.

This is my second or third day with this same ability. Never give up :)
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
You're massively overthinking it. You are already storing information about a particular instance of the ability properly. In the same way you save MightStacksMax for a given instance, also just save the current value of MightStacks for that instance. Add +1 to it and re-save it in your periodic trigger.
 
Level 12
Joined
Feb 5, 2018
Messages
521
I'm sorry I just don't understand. I am looking at the trigger and I save the stacks? I tried many variations and nothing didn't work.

I added a test map :)

EDIT: Made the test map correct
 

Attachments

  • MightTest.w3m
    19.8 KB · Views: 37
Last edited:
Level 12
Joined
Feb 5, 2018
Messages
521
  • Might
    • Events
      • Game - PDD_damageEventTrigger becomes Equal to 0.00
    • Conditions
      • (Level of Might (Completed) for PDD_target) Greater than 0
      • (PDD_target belongs to an enemy of (Owner of PDD_source).) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 33
    • Actions
      • Hashtable - Save Handle Of(Triggering unit) as 3 of (Key (Triggering unit).) in MightHash.
      • Set VariableSet MightStacksMax = ((Level of Might (Completed) for (Load 3 of (Key (Triggering unit).) in MightHash.)) x 5)
      • Hashtable - Save MightStacksMax as 2 of (Key (Triggering unit).) in MightHash.
      • Game - Display to (All players) the text: ((String(MightStacks)) + ( / + (String(MightStacksMax))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Load 3 of (Key (Triggering unit).) in MightHash.) is in MightUG.) Equal to False
        • Then - Actions
          • Unit Group - Add (Load 3 of (Key (Triggering unit).) in MightHash.) to MightUG
          • Game - Display to (All players) the text: Unit Added To Group
          • Hashtable - Save 15.00 as 1 of (Key (Load 3 of (Key (Triggering unit).) in MightHash.).) in MightHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MightStacks Less than MightStacksMax
        • Then - Actions
          • Hashtable - Save (MightStacks + 1) as 0 of (Key (Load 3 of (Key (Triggering unit).) in MightHash.).) in MightHash.
          • Hero - Modify Strength of (Load 3 of (Key (Triggering unit).) in MightHash.): Add 4.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in MightUG) Equal to 1
        • Then - Actions
          • Trigger - Turn on Might Check <gen>
        • Else - Actions
  • Might Check
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MightUG and do (Actions)
        • Loop - Actions
          • Set VariableSet MightTime = (Load 1 of (Key (Picked unit).) from MightHash.)
          • Set VariableSet MightStacks = (Load 0 of (Key (Picked unit).) from MightHash.)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MightTime Greater than 0.00
            • Then - Actions
              • Hashtable - Save (MightTime - 1.00) as 1 of (Key (Picked unit).) in MightHash.
              • Game - Display to (All players) the text: (String(MightTime))
            • Else - Actions
              • Hero - Modify Strength of (Picked unit): Subtract 4.
              • Hashtable - Save (MightStacks - 1) as 0 of (Key (Load 3 of (Key (Picked unit).) in MightHash.).) in MightHash.
              • Game - Display to (All players) the text: End of Timer --- Re...
I took a couple of days off thinking this trigger. Here is how it is now. Still not working and needs to have an end condition in the loop trigger.
 
Status
Not open for further replies.
Top