• 🏆 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] Unit being removed event

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
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?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
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:
Level 23
Joined
Apr 3, 2018
Messages
460
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.
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
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

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
@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:
Level 24
Joined
Jun 26, 2020
Messages
1,852
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.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
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

  • Killed or Removed Check.w3m
    17.8 KB · Views: 44
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
@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

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
@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.
Top