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

Hashtable Trigger Question? How to:

Status
Not open for further replies.
Level 15
Joined
Nov 26, 2005
Messages
1,151
Ok, so I want to create a spell that gives a chance to add 1 strength to my hero on attack. Str lasts for 5 seconds.

Here are my triggers:


  • Power of Darkness Store
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) has buff Power Of Darkness ) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 25
        • Then - Actions
          • Set PoD_Caster = (Attacked unit)
          • Special Effect - Create a special effect attached to the origin of PoD_Caster using Abilities\Spells\Other\Charm\CharmTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Hero - Modify Strength of PoD_Caster: Add 1
          • Hashtable - Save Handle Of(Attacked unit) as 0 of (Key (Attacked unit)) in PoD_Hash
          • Hashtable - Save 5 as 1 of (Key (Attacked unit)) in PoD_Hash
          • Unit Group - Add PoD_Caster to PoD_Group
        • Else - Actions



  • Power of Darkness Loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set PoD_Caster = (Load 0 of (Key (Picked unit)) in PoD_Hash)
          • Set PoD_Time = (Load 1 of (Key (Picked unit)) from PoD_Hash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • PoD_Time Greater than 0
            • Then - Actions
              • Hashtable - Save (PoD_Time - 1) as 1 of (Key (Picked unit)) in PoD_Hash
            • Else - Actions
              • Hero - Modify Strength of PoD_Caster: Subtract 1
              • Special Effect - Create a special effect attached to the origin of PoD_Caster using Abilities\Spells\Orc\AncestralSpirit\AncestralSpiritCaster.mdl
              • Special Effect - Destroy (Last created special effect)
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in PoD_Hash
              • Unit Group - Remove PoD_Caster from PoD_Group


So my question is, how can I make this possible to cast multiple times on one unit ? (For now only the last 1 strength will be removed when the 5 seconds are over)

Please, any ideas ? (+Rep for helpful answers)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • Untitled Trigger 010
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Hero - Modify Strength of (Triggering unit): Add 1
      • Set Temp_Integer_1 = (Load (Key str_bonus) of (Key (Triggering unit)) from Str_Hash)
      • Hashtable - Save 5 as (Key time) of (Key (Triggering unit)) in Str_Hash
      • Hashtable - Save (Temp_Integer_1 + 1) as (Key str_bonus) of (Key (Triggering unit)) in Str_Hash
      • Unit Group - Add (Triggering unit) to Str_Group
      • Trigger - Turn on Untitled Trigger 011 <gen>
  • Untitled Trigger 011
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Str_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Integer_2 = (Load (Key str_bonus) of (Key (Picked unit)) from Str_Hash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer_2 Greater than 0
            • Then - Actions
              • Set Temp_Integer_1 = (Load (Key time) of (Key (Picked unit)) from Str_Hash)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Temp_Integer_1 Greater than 0
                • Then - Actions
                  • Hashtable - Save (Temp_Integer_1 - 1) as (Key time) of (Key (Picked unit)) in Str_Hash
                • Else - Actions
                  • Hero - Modify Strength of (Picked unit): Subtract 1
                  • Hashtable - Save (Temp_Integer_2 - 1) as (Key str_bonus) of (Key (Picked unit)) in Str_Hash
                  • Hashtable - Save 5 as (Key time) of (Key (Picked unit)) in Str_Hash
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Str_Hash
              • Unit Group - Remove (Picked unit) from Str_Group
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Str_Group is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
 
Level 4
Joined
Nov 7, 2009
Messages
83
I will just suggest you add a counter to your code. When you add strength to the unit, increase that counter, when you remove the strength, read that counter, set it to zero and remove the amount of strength tha was stored in the counter.
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
It tries to load it, but if it can't find it, it returns 0, and it works correctly.

Yes yes, I noticed, it says "if not returns 0"

But can u explain a little bit more about the whole idea of the integer usage ?
I mean, how do u put every ... single thing (every piece of strength bonus, every remaining time, every caster) where they belong?
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
In the first trigger I check if the unit already has str buff, and how big it is by loading the value into the variable. Then I save the time that it takes for the buff to decrease by one str and the str bonus.

In the second trigger I first check if the str bonus is >0. If it isn't then the buff ends and the unit is removed from the group. If it isn't, I check if the timer is 0 so that the buff should decrease by one level. If it is zero, I check if the str bonus is greater than zero and apply the timer again if it is.

BTW, you might want to add some check there to limit the str increase to some value.
 
Level 4
Joined
Jul 28, 2009
Messages
64
I actually created a spell with a similar effect, but instead of using hashtables I used the hero stat increase ability, and set the option to not visible.

Seems like a simpler alternative.

Then when the unit is attacked, it increases the level of this invisible ability (which increases the stat bonus by 1).

I know its not exactly what you asked for help with, but there is a copy of it in my map (linked below). The ability is called "battle hardened", in the abilities folder.
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
I found a problem. Lets say the str bonus is added +1 and in 1 second another +1. When the first bonus drops, the ext one will wait the whole 5 secs, not just the 1 second, it has left ... which is not good :?

How should we fix that ?
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Alright, I thought the timer should reset each time the unit is hit. Anyway, every +1 str bonus now has it's own timer, and the str bonus can easily be capped by setting the maximum number of the loop:

  • Str bonus system 1
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set Temp_Integer_1 = (Load (Key str_bonus) of (Key (Triggering unit)) from StrHash)
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load (Integer A) of (Key (Triggering unit)) from Str_Hash) Equal to 0
            • Then - Actions
              • Hashtable - Save (Temp_Integer_1 + 1) as (Key str_bonus) of (Key (Triggering unit)) in Str_Hash
              • Hero - Modify Strength of (Triggering unit): Add 1
              • Hashtable - Save 5 as (Integer A) of (Key (Triggering unit)) in Str_Hash
              • Unit Group - Add (Triggering unit) to Str_Group
              • Trigger - Turn on Str bonus system 2 <gen>
              • Skip remaining actions
            • Else - Actions
  • Str bonus system 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Str_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Integer_2 = (Load (Key str_bonus) of (Key (Picked unit)) from Str_Hash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer_2 Greater than 0
            • Then - Actions
              • For each (Integer A) from 1 to 10, do (Actions)
                • Loop - Actions
                  • Set Temp_Integer_1 = (Load (Integer A) of (Key (Picked unit)) from Str_Hash)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Integer_1 Greater than 0
                    • Then - Actions
                      • Hashtable - Save (Temp_Integer_1 - 1) as (Integer A) of (Key (Picked unit)) in Str_Hash
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Temp_Integer_1 - 1) Equal to 0
                        • Then - Actions
                          • Hero - Modify Strength of (Picked unit): Subtract 1
                          • Hashtable - Save (Temp_Integer_2 - 1) as (Key str_bonus) of (Key (Picked unit)) in Str_Hash
                        • Else - Actions
                    • Else - Actions
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Str_Hash
              • Unit Group - Remove (Picked unit) from Str_Group
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Str_Group is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
Oh yeah
smoker.gif
 
Status
Not open for further replies.
Top