Trying to Improve These Triggers

Level 21
Joined
Mar 16, 2008
Messages
955
There are 4 items that create portals to "old god" boss rooms. The portals are added to the array'ed unit group so all portals to that boss room can be destroyed after the boss dies, which is done in a separate trigger not posted here.

1) Don't want it to leak
2) I want to keep the 3 sec pause between using the item and activating the portal so the construction animation can play

Any suggestions on using these?

  • Rune Portals Pt 1
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: C'thuun
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: Yogg-saron
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: N'zoth
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: Melbu
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: C'thuun
        • Then - Actions
          • Set VariableSet Rune_Portal = (Units owned by (Owner of (Hero manipulating item)) of type Portal to C'thuun's Prison)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: Yogg-saron
        • Then - Actions
          • Set VariableSet Rune_Portal = (Units owned by (Owner of (Hero manipulating item)) of type Portal to Yogg-Saron's Prison)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: N'zoth
        • Then - Actions
          • Set VariableSet Rune_Portal = (Units owned by (Owner of (Hero manipulating item)) of type Portal to N'zoth's Prison)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Old God Rune: Melbu
        • Then - Actions
          • Set VariableSet Rune_Portal = (Units owned by (Owner of (Hero manipulating item)) of type Portal to Melbu's Prison)
        • Else - Actions
      • Countdown Timer - Start old_god_port_timer as a One-shot timer that will expire in 3.00 seconds

  • Rune Portals Pt 2
    • Events
      • Time - old_god_port_timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Rune_Portal and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Portal to C'thuun's Prison
            • Then - Actions
              • Unit Group - Remove (Picked unit) from Rune_Portal.
              • Unit Group - Add (Picked unit) to Rune_Portals_Unt_Grp[1]
              • Neutral Building - Set (Picked unit) destination to (old_god_entry_pt_var[1] offset by (0.00, 0.00))
              • Neutral Building - Enable (Picked unit)
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Portal to Yogg-Saron's Prison
            • Then - Actions
              • Unit Group - Remove (Picked unit) from Rune_Portal.
              • Unit Group - Add (Picked unit) to Rune_Portals_Unt_Grp[2]
              • Neutral Building - Set (Picked unit) destination to (old_god_entry_pt_var[2] offset by (0.00, 0.00))
              • Neutral Building - Enable (Picked unit)
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Portal to N'zoth's Prison
            • Then - Actions
              • Unit Group - Remove (Picked unit) from Rune_Portal.
              • Unit Group - Add (Picked unit) to Rune_Portals_Unt_Grp[3]
              • Neutral Building - Set (Picked unit) destination to (old_god_entry_pt_var[3] offset by (0.00, 0.00))
              • Neutral Building - Enable (Picked unit)
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Portal to Melbu's Prison
            • Then - Actions
              • Unit Group - Remove (Picked unit) from Rune_Portal.
              • Unit Group - Add (Picked unit) to Rune_Portals_Unt_Grp[4]
              • Neutral Building - Set (Picked unit) destination to (old_god_entry_pt_var[4] offset by (0.00, 0.00))
              • Neutral Building - Enable (Picked unit)
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
            • Else - Actions
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
  • You are already partially indexing 1-4 so might as well continue that. You could make a unit-type array 1-4 of the 4 portal unit types and then condense both triggers to just setting an integer in the if-blocks and then doing the same actions after. What you have is fine but that's a 'better' way.
  • There's no reason to repeat so much in the second trigger; do the same as you have done in the first trigger and only separate out the lines with differences.
  • You are leaking numerous points for no reason by using SomePoint Offset by (0,0). That's literally the exact same position as the point it's offset from, but it is a new object that must be deleted or cause a memory leak. (Think about what offsetting a point by 0 in both x and y directions means!)
  • You must destroy the unit group in Trigger 2 after you're done using it, since it's assigned a new (fresh object) group in Trigger 1 each time it runs.
If a second portal is placed within 3s of a first portal (and they go to different locations), the first will never activate. The second time trigger 1 runs it overwrites the group stored in Rune_Portal (but overwrites it with a group containing both portals if they were both to the same location). If such a thing is logically not possible then you don't need to worry, but if it can occur I think a simple option is to simply prevent the second portal from working and refund the used item. I would do that by placing all of the current actions of trigger 1 with another if block, and then doing this:
  • Actions
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • PortalInProgress equal to False
      • Then - Actions
        • Set PortalInProgress = True
        • ------ everything you already have goes here --------
      • Else - Actions
        • Hero - Create (Item type of (Item being manipulated)) and give it to (Triggering unit) //this is a hero action not item action
  • -------- at end of trigger 2 --------
  • Set PortalInProgress = False
Another maybe better solution is to change the trigger 1 logic to add the portals found by the groups search to the existing unit group instead of simply overwriting what's already there. Then instead of destroying the group in Trigger 2 you would clear that group (to reuse it) while always destroying the temporary 'search' group used in Trigger 1 (that you currently write to the Rune_Portal variable).
 
Last edited:
Top