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

Code Optimization Hashtables

Level 6
Joined
Jul 2, 2013
Messages
153
Hello guys, thanks to your help, finally my HoT spell is done and working.
However, my question is,
1) does it need any more optimization then that? Does it look like it could be laggy? I plan to use it for most 10-20 units at a time. But I might need to duplicate it a few times for DoTs or other specific HoTs and use them all together.
2) Should I leave the timer to run ALWAYS, or turn it off if no unit needs healing etc.? Would it make any difference?

I did test already and looked fine, but on an empty map everything runs fine. Thanks !

  • HoT Group
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Inner Fire
    • Actions
      • Hashtable - Save 30 as 0 of (Key (Target unit of ability being cast)) in HotHash
      • Hashtable - Save ((Intelligence of (Casting unit) (Include bonuses)) x 4) as 1 of (Key (Target unit of ability being cast)) in HotHash
      • Unit Group - Add (Target unit of ability being cast) to HoTGroup
  • HoT Group Timer Copy
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HoTGroup and do (Actions)
        • Loop - Actions
          • Set HotAmount = (Load 1 of (Key (Picked unit)) from HotHash)
          • Set HoTRemainingTicks = (Load 0 of (Key (Picked unit)) from HotHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HoTRemainingTicks Greater than 0
            • Then - Actions
              • Game - Display to (All players) the text: (String(HoTRemainingTicks))
              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + (Real(HotAmount)))
              • Game - Display to (All players) the text: (String(HotAmount))
              • Hashtable - Save (HoTRemainingTicks - 1) as 0 of (Key (Picked unit)) in HotHash
            • Else - Actions
              • Game - Display to (All players) the text: Remove from group
              • Unit Group - Remove (Picked unit) from HoTGroup
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in HotHash
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
You could have 100's of these triggers running at once without any serious issues.

That being said, there's no reason to have HoT Group Timer Copy on when the Unit Group is empty. Toggling it on and off would help improve performance so if performance is a concern then you should definitely do it.

Also, I recommend tracking the number of units in the Unit Group yourself with a basic Integer rather than relying on the Count function which needs to enumerate over the entire Unit Group each time. So you would add 1 to the integer when adding a not-already-in-the-group unit to the unit group and subtract 1 on removing a unit from the unit group. If the integer is equal to 1 after increasing it then you can turn on the trigger and if it's equal to 0 after subtracting from it then you can turn off the trigger.

Also, a Unit Indexer would be perfect for this style of trigger and rid you the need of an an entire Hashtable dedicated to a simple spell. I prefer and recommend Unit Indexers over Hashtables whenever possible, I find them to be far more convenient and enjoyable to use. Just make sure you understand the few caveats that come with using them.
 
Last edited:
Level 6
Joined
Jul 2, 2013
Messages
153
Oh I see. I am not familiar with unit indexing, but I will read more and keep in mind it could be useful for these type of stuff. That's why I used hashtables now.

And Yeah - running 100 of those without issues is what I was hoping to hear :D, although I will mostly need just a few. I already did the turning off with integer and it works well. Looks good now.
 
Top