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

[General] How to remove ability of unit after X time?

Level 21
Joined
Dec 3, 2020
Messages
520
So I have in my map a unit that, when he casts an ability (death coil), a fake storm hammers ability is added to the target of the ability being cast.
But I want that ability to be removed 2 seconds after it is added to the target.

The player can have dozens of units of the same type that have the death coil ability, so the following trigger will not work(?):

  • Events - Unit starts effect of an ability
  • Conditions - Ability being cast equal to Death Coil
  • Actions -
  • Add Storm Hammers to target of ability being cast
  • Wait 2 seconds
  • Remove Storm Hammers from target of ability being cast
So how do I make it work? Using an event such as "every 2 seconds of game time" won't work for me since imagine the Storm Hammers is added to the unit, then the event fires 0.5 seconds after that.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,019
Could avoid a timer by using a unit indexer, an integer array to keep track of instances of the death coil ability that have been cast on units, and a locally-shadowed global variable to retain the targeted unit after the wait.
  • Events
    • Unit - A unit dies
  • Conditions
  • Actions
    • Set UnitID = (The index of the dying unit however you would get that based on the indexing system you use)
    • Set SH_Count[UnitID] = 0 //to prevent reused unit IDs from having incorrect counts if a unit dies while it has the storm hammers ability
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to Death Coil
  • Actions
    • Custom script: local unit udg_TempUnitVar //must match the variable name including capitalization and keep the udg_ prefix
    • Set TempUnitVar = (Target unit of ability being cast)
    • Set UnitID = (The index of the targeted unit however you would get that based on the indexing system you use)
    • Set SH_Count[UnitID] = (SH_Count[UnitID] + 1)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • SH_Count greater than 0
        • -------- because the unit is stored in a local variable, that variable will not be visible inside of these condition functions because of how GUI nests them. Don't need that functionality here, just a note. --------
      • Then - Actions
        • Unit - Add Storm Hammers to TempUnitVar //adding it when it already has the ability does nothing so no need to worry
        • -------- If these targeted units can morph/transform in any way, this ability will be lost prematurely upon transformation --------
        • -------- That can be avoided with a custom script like this: --------
        • Set TempAbil = Storm Hammers
        • Custom script: call UnitMakeAbilityPermanent(udg_TempUnitVar, udg_TempAbil, true)
      • Else - Actions
    • Wait 2.00 game-time seconds
    • Set SH_Count[UnitID] = (SH_Count[UnitID] - 1)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • SH_Count less than or equal to 0
      • Then - Actions
        • Unit - Remove Storm Hammers From TempUnitVar
      • Else - Actions
    • Set TempUnitVar = (No unit) //because this is acting as a local it must be nulled before the end of the trigger
 
Top