Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[General] Unit being removed event

Discussion in 'World Editor Help Zone' started by HerlySQR, Oct 24, 2020.

  1. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    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?
     
  2. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,393
    Resources:
    0
    Resources:
    0
    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: Oct 24, 2020
  3. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    @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?
     
  4. biridius

    biridius

    Joined:
    Apr 3, 2018
    Messages:
    197
    Resources:
    4
    Maps:
    4
    Resources:
    4
    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.
     
  5. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    Ok, but I never used a spellbook, how can I do that?
     
  6. biridius

    biridius

    Joined:
    Apr 3, 2018
    Messages:
    197
    Resources:
    4
    Maps:
    4
    Resources:
    4
    The mysteries of the Spellbook
    I'm not sure if the defend glitch would occur with the ability inside the spellbook though.
    But you don't have to do all that if you go with the array timer and typeid=0 approach.
     
  7. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    Ok thank you all
     
  8. Dat-C3

    Dat-C3

    Joined:
    Mar 15, 2012
    Messages:
    2,567
    Resources:
    10
    Models:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    1
    Resources:
    10
  9. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,393
    Resources:
    0
    Resources:
    0
    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: Oct 24, 2020
  10. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    It worked, it crashes if I use it to auras or every passive idk, but it won't be a problem.
    Ok, I will try.
     
  11. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,393
    Resources:
    0
    Resources:
    0
    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.
     

    Attached Files:

    Last edited: Oct 24, 2020
  12. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    574
    Resources:
    0
    Resources:
    0
    @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.
     
    Last edited: Nov 10, 2020
  13. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    2,393
    Resources:
    0
    Resources:
    0
    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: Nov 10, 2020