• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[General] Unit being removed event

Status
Not open for further replies.
Level 25
Joined
Jun 26, 2020
Messages
1,971
How can I action a trigger when a unit its removed? I tried with "Unit leaves Playable Map Area" and "Entire map" and it didn't work, Maybe you will tell me that I can detect using "Units in region" but it doesn't detect hidden units, the other functions of unit group limit the conditions, can you suggest me something?
 
The "defend" ability has a bug that makes it fire an "undefend" order when a unit dies, gets removed or gets revived. So you can detect when a unit is removed this way or even when a unit dies with Reincarnation active.

So to take advantage of this you'd want to add a hidden/unusable defend ability to all of your units that you want to detect the "removal" of.
 
Last edited:
There's no direct event for it, implementation depends on what you need this for.
You could put all units in an array and check if their typeid becomes 0 with a timer when it's removed.
And put any other relevant data of that unit (that would otherwise get removed with the unit) in other arrays with the same index.

Also you can actually hide abilities on 1.26, just put them in a spellbook (it's an item ability) and then make the spellbook unavailable for every player. Then add the spellbook instead of the ability and the icon won't be visible.
 
There's no direct event for it, implementation depends on what you need this for.
You could put all units in an array and check if their typeid becomes 0 with a timer when it's removed.
And put any other relevant data of that unit (that would otherwise get removed with the unit) in other arrays with the same index.

Also you can actually hide abilities on 1.26, just put them in a spellbook (it's an item ability) and then make the spellbook unavailable for every player. Then add the spellbook instead of the ability and the icon won't be visible.
Ok, but I never used a spellbook, how can I do that?
 
@Uncle Like what, I mean I can't hide it because I'm in the 1.26 and How can I difference between the unit dies and its removed?
You give them the defend ability, then make a trigger like:
"A unit is issued an order targeting no unit" -> "If issued order equal to "undefend" -> Unit was removed.

Also, if you already use the Defend ability in your map (say for a Footman) you'd want to take that into consideration.
 
Last edited:
It worked, it crashes if I use it to auras or every passive idk, but it won't be a problem.
You give them the defend ability, then make a trigger like:
"A unit is issued an order targeting no unit" -> "If issued order equal to "undefend" -> Unit was removed.

If you already use the Defend ability in your map (say for a Footman) you'd want to take that into consideration. I imagine you can check if the Undefend Ordered unit is Dead or if it's life is < the death threshold, so you don't screw with your Footies.
Ok, I will try.
 
After testing it on the latest patch I noticed that the unit was issuing the Undefend order twice after it was killed or removed. Not sure if this happens on 1.26 but here's a simple solution:
  • a unit undefends
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(undefend))
      • IssuedUndefend[(Custom value of (Triggering unit))] Equal to False
      • ((Triggering unit) is hidden) Equal to True
    • Actions
      • Set VariableSet IssuedUndefend[(Custom value of (Triggering unit))] = True
      • Wait 0.01 seconds
      • Set VariableSet IssuedUndefend[(Custom value of (Triggering unit))] = False
Using a Unit Indexer I prevent the trigger from running twice for the same unit.

Edit: Also, you want to add the Condition "Is hidden = True".

This is because Removed units are hidden when killed. This way the trigger doesn't run when a unit dies the normal way.
 

Attachments

Last edited:
@Uncle Question, How can I make sure the defend ability doesn't do anything?
After testing it on the latest patch I noticed that the unit was issuing the Undefend order twice after it was killed or removed. Not sure if this happens on 1.26 but here's a simple solution:
  • a unit undefends
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(undefend))
      • IssuedUndefend[(Custom value of (Triggering unit))] Equal to False
      • ((Triggering unit) is hidden) Equal to True
    • Actions
      • Set VariableSet IssuedUndefend[(Custom value of (Triggering unit))] = True
      • Wait 0.01 seconds
      • Set VariableSet IssuedUndefend[(Custom value of (Triggering unit))] = False
Using a Unit Indexer I prevent the trigger from running twice for the same unit.

Edit: Also, you want to add the Condition "Is hidden = True".

This is because Removed units are hidden when killed. This way the trigger doesn't run when a unit dies the normal way.
And that bug only happens if the unit is removed, and I think this is a practical way to avoid that.
  • Set Remover_count = (Remover_count + 1)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Remover_count Equal to 2
    • Then - Acions
      • Set Remover_count = 0
      • Skip remaining actions
    • Else - Actions
The problem, this only work if the event never count when the unit dies, but it can happen, do you know a way to improve that, or I just use your solution, but I don't wanna use a unit indexer, I use the custom value of units in some things.
 
Last edited:
@Uncle Question, How can I make sure the defend ability doesn't do anything?

And that bug only happens if the unit is removed, and I think this is a practical way to avoid that.
  • Set Remover_count = (Remover_count + 1)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Remover_count Equal to 2
    • Then - Acions
      • Set Remover_count = 0
      • Skip remaining actions
    • Else - Actions
The problem, this only work if the event never count when the unit dies, but it can happen, do you know a way to improve that, or I just use your solution, but I don't wanna use a unit indexer, I use the custom value of units in some things.
A Unit Indexer enables you to use the unit's custom value for as many things as you could possibly want, so your issue is really just a matter of updating those triggers that use Custom Value to instead use Variables + Unit Indexing. But if you don't want to do that then you could use a Hashtable as well.
 
Last edited:
Status
Not open for further replies.
Back
Top