• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Need a leaks check for simple triggers.

Status
Not open for further replies.
Level 3
Joined
Apr 1, 2017
Messages
47
So here is a simple Divine Shield spell not for caster but for friendly unit (Based on Rejuvenation)

  • Hand of Protection Start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Hand of Protection
    • Actions
      • Set triggeringHoProt = (Triggering unit)
      • Set IntegerHoProt = (Level of Hand of Protection for triggeringHoProt)
      • Set TargetHoProt = (Target unit of ability being cast)
      • Custom script: set udg_HoProtHashKey = GetHandleId(udg_TargetHoProt)
      • Unit - Make TargetHoProt Invulnerable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IntegerHoProt Equal to 1
        • Then - Actions
          • Hashtable - Save 15 as 0 of HoProtHashKey in ZHandOfProt
          • Unit Group - Add TargetHoProt to HandOfProtGroup
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerHoProt Equal to 2
            • Then - Actions
              • Hashtable - Save 30 as 0 of HoProtHashKey in ZHandOfProt
              • Unit Group - Add TargetHoProt to HandOfProtGroup
            • Else - Actions
              • Hashtable - Save 45 as 0 of HoProtHashKey in ZHandOfProt
              • Unit Group - Add TargetHoProt to HandOfProtGroup

  • Hand Of Protection
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HandOfProtGroup and do (Actions)
        • Loop - Actions
          • Set PickedHoProt = (Picked unit)
          • Custom script: set udg_HoProtHashKey1 = GetHandleId(udg_PickedHoProt)
          • Set HandOfProtTimer = (Load 0 of HoProtHashKey1 from ZHandOfProt)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HandOfProtTimer Greater than 0
            • Then - Actions
              • Game - Display to (All players) the text: (String(HandOfProtTimer))
              • Hashtable - Save (HandOfProtTimer - 1) as 0 of HoProtHashKey1 in ZHandOfProt
            • Else - Actions
              • Unit - Make PickedHoProt Vulnerable
              • Unit Group - Remove PickedHoProt from HandOfProtGroup
              • Hashtable - Clear all child hashtables of child HoProtHashKey1 in ZHandOfProt

Also for some reason this ability can be casted on enemies despite of allowed targets Friend, Ground, Not self, Organic, Vulnerable.
 
Level 3
Joined
Apr 1, 2017
Messages
47
Disable the loop trigger on init, and when adding a unit to the group check if number of units in group is equal to 0, if true enable the trigger.
And then reverse when removing the unit, the idea is to prevent the timer loop from running when the group is empty.
Oh each, forgot about that. So I guess I should turn off second trigger in the editor and then add "turn on Hand of Protection" to the first trigger and add if the amount of units in HandofProtGroup = 0 turn off this trigger to the second trigger?
 
Wait, why is turning on a trigger that is already on a bad thing?
It won't change result, but an integer comparison is for sure faster. But it doesn't really matter for you, you can also turn it always on.

Also, the check in GUI, if a group is empty, is pretty slow and also very inefficient in comparison to a simple integer comparison, because it loops through the whole unit group each time. But it's also not really critical, just some performance optimization. One could also then say directly to use arrays to replace unit group loop completly, etc, but just keep it simple for you to maintain.

I can't see leaks.
  • Unit Group - Add TargetHoProt to HandOfProtGroup
^You do this in any case, so it might be moved out of the if-statement to be always last operation in the trigger.
 
Level 3
Joined
Apr 1, 2017
Messages
47
Also, the check in GUI, if a group is empty, is pretty slow and also very inefficient in comparison to a simple integer comparison, because it loops through the whole unit group each time. But it's also not really critical, just some performance optimization. One could also then say directly to use arrays to replace unit group loop completly, etc, but just keep it simple for you to maintain.
Interesting. Is there a tutorial for that?
 
Status
Not open for further replies.
Top