[Trigger] Unit - Remove the Ability

Level 7
Joined
Jun 1, 2009
Messages
125
Hi!
I'm trying to swap two abilities with another pair of abilities and vice-versa each time a Lightning tower: mode swap (customized "defend") ability got activated\deactivated.
The problem is that one default ability, the Lightning Barrage (customized "troll berserk") out of two is not removed by the first time "defend" got clicked (yet, the trigger adds another pair of abilities correctly). And for some reason, the trigger works fine on each next activation of "defend".

If the tower is a "standalone" - the trigger works fine.
If the tower is an upgrade of another tower - this glitch appears.
Storing the CD time in the variable does not help.

A temporary fix I've made - is a tower replacement with the same unit type, but since I've heard that the "replace unit" still does a memory leak, I hope to find a more elegant solution!

The trigger parts:

  • Unit is issued an order with no target
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Player number of (Owner of (Ordered unit))) Less than 9
    • Actions
      • Set VariableSet UO_Triggering = (Ordered unit)
      • -------- Towers --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Check Range for UO_Triggering) Greater than 0
        • Then - Actions
          • -------- Order: magicdefense --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(magicdefense))
            • Then - Actions
              • -------- Lightning Tower --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Lightning tower: mode swap for UO_Triggering) Greater than 0
                • Then - Actions
                  • Unit - Add Chain Lightning to UO_Triggering
                  • Unit - Add Magic Lightning to UO_Triggering
                  • Unit - For Unit UO_Triggering, start cooldown of ability Chain Lightning (Lightning Tower) " over "(Ability Cooldown Remaining of UO_Triggering for ability Lightning Barrage..) seconds.
                  • Unit - Remove Discharge from UO_Triggering
                  • Unit - Remove Lightning Barrage from UO_Triggering
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                • Else - Actions
          • -------- Order: magicundefense --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(magicundefense))
            • Then - Actions
              • -------- Lightning Tower --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Lightning tower: mode swap for UO_Triggering) Greater than 0
                • Then - Actions
                  • Unit - Add Lightning Barrage to UO_Triggering
                  • Unit - Add Discharge to UO_Triggering
                  • Unit - For Unit UO_Triggering, start cooldown of ability Lightning Barrage " over "(Ability Cooldown Remaining of UO_Triggering for ability Chain Lightning..) seconds.
                  • Unit - Remove Chain Lightning from UO_Triggering
                  • Unit - Remove Magic Lightning from UO_Triggering
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I doubt the Unit leak will ever cause any noticeable problems.

Anyway, it looks like you have two different Chain Lightning abilities, Chain Lightning (Lightning Tower) and Chain Lightning. Is that intended?

That aside, I would test out this restructured trigger to see if it solves the ability problem:
  • Events
    • Unit - A unit Is issued an order with no target
  • Conditions
    • (Player number of (Owner of (Ordered unit))) Less than 9
    • (Level of Lightning tower: mode swap for (Ordered unit)) Greater than 0
  • Actions
    • Set VariableSet UO_Triggering = (Ordered unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Issued order) Equal to (Order(magicdefense))
      • Then - Actions
        • Set Variable UO_Cooldown = (Ability Cooldown Remaining of UO_Triggering for ability Lightning Barrage)
        • Unit - Remove Discharge from UO_Triggering
        • Unit - Remove Lightning Barrage from UO_Triggering
        • Unit - Add Chain Lightning to UO_Triggering
        • Unit - Add Magic Lightning to UO_Triggering
        • Unit - For Unit UO_Triggering, start cooldown of ability Chain Lightning (Lightning Tower) over UO_Cooldown seconds
        • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen') at Index:1 to Value: True
        • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen') at Index:0 to Value: False
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Issued order) Equal to (Order(magicundefense))
          • Then - Actions
            • Set Variable UO_Cooldown = (Ability Cooldown Remaining of UO_Triggering for ability Chain Lightning)
            • Unit - Remove Chain Lightning from UO_Triggering
            • Unit - Remove Magic Lightning from UO_Triggering
            • Unit - Add Lightning Barrage to UO_Triggering
            • Unit - Add Discharge to UO_Triggering
            • Unit - For Unit UO_Triggering, start cooldown of ability Lightning Barrage over UO_Cooldown seconds
            • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen') at Index:0 to Value: True
            • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen') at Index:1 to Value: False
          • Else - Actions
  • I adjusted it so that the unwanted abilities are Removed first.
  • I stored the Remaining Cooldown prior to the removal to avoid losing access to it.
  • I took advantage of the Else - Actions so that you're no longer asking two mutually exclusive questions.
  • I made the trigger dedicated to the Lightning Tower as to help pinpoint the issue.

Also, ensure that you don't have other triggers interfering, mainly ones that run in response to issued orders.
 
Last edited:
Level 7
Joined
Jun 1, 2009
Messages
125
Thx for the reply!
I was not sure how bad this type of (possible) memory leak was.
I stored the Remaining Cooldown prior
Yup, I've already tried to use a real variable to store the cooldown, and remove the "trouble" ability first - it had no effect. The first click still made a mess, but after that, everything went fine.

it looks like you have two different Chain Lightning abilities
Sry, I've just shortened this trigger to make it readable somehow and deleted the other towers, editor suffixes, and so on. That confusing (Lightning Tower) thing was just the suffix I've missed. Ofc. It's the same spell.
The shorter the trigger is, the more chance that people would actually read it...

ensure that you don't have other triggers interfering
Yup, that's why I've put everything with "A unit Is issued an order with no target" event into a single trigger.

The thing I still can't understand - is why it works fine if I build the tower, and it messes up the first click if I get this tower by upgrading the another one.

If it can help - I'll copy-paste "as is" the whole thing without any text edits, but it could be quite TL\DR, and these editor suffixes and color codes make it harder to read, I think.

  • Unit is issued an order with no target
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Player number of (Owner of (Ordered unit))) Less than 9
    • Actions
      • Set VariableSet UO_Triggering = (Ordered unit)
      • -------- Towers --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Check Range for UO_Triggering) Greater than 0
        • Then - Actions
          • -------- Order: magicdefense --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(magicdefense))
            • Then - Actions
              • -------- Piercing towers: Hammer Mode --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Piercing tower: mode swap for UO_Triggering) Greater than 0
                • Then - Actions
                  • Custom script: set udg_HID_UO = GetUnitTypeId(udg_UO_Triggering)
                  • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Piercing.)
                  • Unit - Remove PiercingTower_ArrowCritAbType[TEI_UO] from UO_Triggering
                  • Unit - Add PiercingTower_HammerAbType[TEI_UO] to UO_Triggering
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                  • Set VariableSet UO_PID = (Player number of (Owner of UO_Triggering))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Hammer_Bool[UO_PID] Equal to False
                    • Then - Actions
                      • Set VariableSet Hammer_Bool[UO_PID] = True
                      • Countdown Timer - Start Hammer_Timer[UO_PID] as a One-shot timer that will expire in 0.00 seconds
                    • Else - Actions
                • Else - Actions
                  • -------- Lightning Tower --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Lightning tower: mode swap (Lightning Tower) for UO_Triggering) Greater than 0
                    • Then - Actions
                      • Unit - Add |cffffcc00C|r|cff00ffffhain Lightning|r (Lightning Tower) to UO_Triggering
                      • Unit - Add Magic Lightning (Magic Generator) to UO_Triggering
                      • Unit - For Unit UO_Triggering, start cooldown of ability |cffffcc00C|r|cff00ffffhain Lightning|r (Lightning Tower) " over "(Ability Cooldown Remaining of UO_Triggering for ability |cff00ffffLightning |cffffcc00B|r|cff00ffffarrage|r ..) seconds.
                      • Unit - Remove Discharge from UO_Triggering
                      • Unit - Remove |cff00ffffLightning |cffffcc00B|r|cff00ffffarrage|r from UO_Triggering
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                    • Else - Actions
                      • -------- Miniguns --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Level of High-Velocity Projectiles for UO_Triggering) Greater than 0
                        • Then - Actions
                          • Unit - Set level of RF: ON (Automatic Cannon) for UO_Triggering to 2
                        • Else - Actions
                          • -------- Rocket launchers: Cluster Missiles Mode --------
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Rocket launcher: mode swap for UO_Triggering) Greater than 0
                            • Then - Actions
                              • Custom script: set udg_HID_UO = GetUnitTypeId(udg_UO_Triggering)
                              • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Rocket.)
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                              • Unit - Remove RocketLauncher_DummyAbType[TEI_UO] from UO_Triggering
                              • Unit - Remove RocketLauncher_HeavyAbType[TEI_UO] from UO_Triggering
                              • Unit - Add RocketLauncher_ClusterAbType[TEI_UO] to UO_Triggering
                            • Else - Actions
              • Skip remaining actions
            • Else - Actions
          • -------- Order: magicundefense --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(magicundefense))
            • Then - Actions
              • -------- Piercing towers: Arrows Mode --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Piercing tower: mode swap for UO_Triggering) Greater than 0
                • Then - Actions
                  • Custom script: set udg_HID_UO = GetUnitTypeId(udg_UO_Triggering)
                  • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Piercing.)
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                  • Unit - Remove PiercingTower_HammerAbType[TEI_UO] from UO_Triggering
                  • Unit - Add PiercingTower_ArrowCritAbType[TEI_UO] to UO_Triggering
                  • Set VariableSet UO_PID = (Player number of (Owner of UO_Triggering))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Hammer_Bool[UO_PID] Equal to False
                    • Then - Actions
                      • Set VariableSet Hammer_Bool[UO_PID] = True
                      • Countdown Timer - Start Hammer_Timer[UO_PID] as a One-shot timer that will expire in 0.00 seconds
                    • Else - Actions
                • Else - Actions
                  • -------- Lightning Tower --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Lightning tower: mode swap (Lightning Tower) for UO_Triggering) Greater than 0
                    • Then - Actions
                      • Unit - Add |cff00ffffLightning |cffffcc00B|r|cff00ffffarrage|r to UO_Triggering
                      • Unit - Add Discharge to UO_Triggering
                      • Unit - For Unit UO_Triggering, start cooldown of ability |cff00ffffLightning |cffffcc00B|r|cff00ffffarrage|r " over "(Ability Cooldown Remaining of UO_Triggering for ability |cffffcc00C|r|cff00ffffhain Lightning|r (Lightning Tower)..) seconds.
                      • Unit - Remove |cffffcc00C|r|cff00ffffhain Lightning|r (Lightning Tower) from UO_Triggering
                      • Unit - Remove Magic Lightning (Magic Generator) from UO_Triggering
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                    • Else - Actions
                      • -------- Miniguns --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Level of High-Velocity Projectiles for UO_Triggering) Greater than 0
                        • Then - Actions
                          • Unit - Set level of RF: ON (Automatic Cannon) for UO_Triggering to 1
                        • Else - Actions
                          • -------- Rocket launchers: Heavy Rockets Mode --------
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Rocket launcher: mode swap for UO_Triggering) Greater than 0
                            • Then - Actions
                              • Custom script: set udg_HID_UO = GetUnitTypeId(udg_UO_Triggering)
                              • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Rocket.)
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                              • Unit - Remove RocketLauncher_ClusterAbType[TEI_UO] from UO_Triggering
                              • Unit - Add RocketLauncher_DummyAbType[TEI_UO] to UO_Triggering
                              • Unit - Add RocketLauncher_HeavyAbType[TEI_UO] to UO_Triggering
                            • Else - Actions
              • Skip remaining actions
            • Else - Actions
          • -------- Order: defend --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(defend))
            • Then - Actions
              • -------- All Towers --------
              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
              • -------- Change Color --------
              • Animation - Change UO_Triggering's vertex coloring to (20.00%, 20.00%, 20.00%) with 20.00% transparency
              • Skip remaining actions
            • Else - Actions
          • -------- Order: undefend --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(undefend))
            • Then - Actions
              • Custom script: set udg_HID_UO = GetUnitTypeId(udg_UO_Triggering)
              • -------- Piercing Towers --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Piercing tower: mode swap for UO_Triggering) Greater than 0
                • Then - Actions
                  • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Piercing.)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of PiercingTower_ArrowCritAbType[TEI_UO] for UO_Triggering) Greater than 0
                    • Then - Actions
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                    • Else - Actions
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                      • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                • Else - Actions
                  • -------- Lightning Tower --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Lightning tower: mode swap (Lightning Tower) for UO_Triggering) Greater than 0
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Level of |cff00ffffLightning |cffffcc00B|r|cff00ffffarrage|r for UO_Triggering) Greater than 0
                        • Then - Actions
                          • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                          • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                        • Else - Actions
                          • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                          • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                    • Else - Actions
                      • -------- Rocket launchers --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Level of Rocket launcher: mode swap for UO_Triggering) Greater than 0
                        • Then - Actions
                          • Set VariableSet TEI_UO = (Load 0 of HID_UO from Hash_UO_Rocket.)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of RocketLauncher_DummyAbType[TEI_UO] for UO_Triggering) Greater than 0
                            • Then - Actions
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: False
                            • Else - Actions
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: False
                              • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                        • Else - Actions
                          • -------- All Towers --------
                          • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:0 to Value: True
              • -------- Miniguns --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of High-Velocity Projectiles for UO_Triggering) Greater than 0
                • Then - Actions
                  • Unit - Set Unit: UO_Triggering's Weapon Boolean Field: Attacks Enabled ('uaen')at Index:1 to Value: True
                • Else - Actions
              • -------- Change Color --------
              • Set VariableSet UO_TowerColorBlue = (Load 0 of HID_UO from Hash_UO_TCB.)
              • Set VariableSet UO_TowerColorGreen = (Load 0 of HID_UO from Hash_UO_TCG.)
              • Set VariableSet UO_TowerColorRed = (Load 0 of HID_UO from Hash_UO_TCR.)
              • Animation - Change UO_Triggering's vertex coloring to (UO_TowerColorRed%, UO_TowerColorGreen%, UO_TowerColorBlue%) with 0.00% transparency
              • Skip remaining actions
            • Else - Actions
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Did you test out what I suggested? It shouldn't be difficult to make a back-up of the original trigger and test out my approach.

Otherwise, I'd have to have a demo map to mess around with to figure out what's going on.
 
Last edited:
Level 7
Joined
Jun 1, 2009
Messages
125
Did you test out what I suggested?
Exactly!
The demo version is ready, where should I upload it?
  • The test map and involved triggers were re-created in the latest version of WorldEditor.
  • The tower has the exact abilities list as in the original map.
  • All abilities are the same copies the original map has (But I've kept their vanilla icons for easier recognition).
  • The unwanted abilities are removed first (Berserk, Feedback)
  • The Remaining Cooldown is stored by the UO_Real variable.
  • "Else - Actions" method applied, instead of "Skip remaining actions"
Still, the bug remains...
 
Last edited:
Top