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

Cancelling wait action

Status
Not open for further replies.
Level 2
Joined
Feb 12, 2023
Messages
11
Is there any way to cancel wait action?
I want to make a spell - A pact that would work as follows: After turning on the Pact ability - an unit will have 60 seconds to kill any unit on the map. If it does - heals the triggering unit to 100% health, if it doesnt - it gets killed. But I have two problems (im kind of a noobie in it)

1) How do I set it so it's not "Conditions - Unit Type of killing unit Equal to Hell Overseer", because it will work for any Hell Overseer on the map. I want this to be set to the player that casts the Pact

2) Turning off the Pact Conditions trigger doesn't cancel the wait unit lol so.. it does heal the Overseer but still kills him after 60 seconds
  • Pact Cast
    • Events
      • Unit - A unit starts the effect of an Ability
    • Conditions
      • (Ability being cast) Equal to Pact of the Devil
    • Actions
      • Trigger - Turn on Pact Conditions <gen>
  • Pact Conditions
    • Events
      • Unit - A unit finishes the effect an Ability
    • Conditions
      • (Ability being cast) Equal to Pact of the Devil
    • Actions
      • Trigger - Turn on Killing Conditions <gen>
      • Wait 60.00 seconds
      • Unit - Kill (Triggering unit)
  • Killing Conditions
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Killing unit)) Equal to Hell Overseer
    • Actions
      • Trigger - Turn off Pact Conditions <gen>
      • Unit - Set life of (Killing unit) to 100.00%
 
Level 25
Joined
Sep 26, 2009
Messages
2,373
Turning trigger off just means that the even if a unit casts the Pact of the Devil, it will not start the trigger. But it does not interrupt already running triggers which is your case.
Your current implementation will not work correctly for multiple Overseers because each cast of Pact of the Devil will overwrite the previous cast (even if the previous cast is still active).
You would need to completely rewrite the triggers to support multiple instances (casts) of the spell at the same time. Depending on whether there can be only 1 Hell Overseer per player or multiple of them per player, you will need to rewrite the triggers to support MPI or MUI respectively.

My approach to this would be to use dynamic indexing (see Visualize: Dynamic Indexing). In your case, the only data you need to keep track of is the reference to the caster (overseer) and remaining time for given caster before he is killed.
  1. Make trigger that fires when overseer starts casting Pact of the Devil. In this trigger use the indexing technique to store the caster and remaining time into unit array and integer array. Finally, if current index is 1, then turn on a loop trigger (described below)
  2. Make a trigger that is initially off. This trigger should have a periodic event (like every 0.2 seconds). In this trigger loop over each caster in the unit array and decrease their remaining time in the integer array. If remaining time in the integer array is zero, then kill caster and deindex him.
  3. Finally, make third trigger that fires when any unit dies. In this trigger check if the killer is any unit from the unit array. If yes, then it is one of the Overseers that casted the Pact spell, so you just need to deindex the unit from the array.
  4. Don't forget to check if index is 0 after you deindex any unit from the array. If it is 0, then turn the loop trigger off
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
Nichilus's solution will work fine, but there are other approaches. Something simpler would be to use an ability like Roar that can bestow a buff to the caster which will last 60s. When a unit casts this ability, add it to a unit group. When a unit with this buff kills another unit: heal the killer, remove the buff, and remove it from the group. Every second, loop over the units in the group and check to see if any no longer have the buff, and if so that unit should be immediately killed because it means the buff expired without getting a kill. If there are purge/buff-removal/buff-stealing effects in your map this will be slightly wonky but it requires much less thought overall:
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to Pact of the Devil
  • Actions
    • Unit Group - Add (Triggering Unit) to PactGroup
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Killing unit) has buff Pact of the Devil) equal to True //this is a boolean comparison
  • Actions
    • Unit - Set life of (Killing unit) to 100.00%
    • Unit Group - Remove (Killing unit) from PactGroup
    • Unit - Remove Pact of the Devil buff from (Killing unit)
  • Events
    • Time - Every 0.50 seconds of game-time //could be faster or slower, should not affect performance
  • Conditions
  • Actions
    • Unit Group - Pick every unit in PactGroup and do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • ((Picked Unit) has buff Pact of the Devil) equal to False
          • Then - Actions
            • Unit - Kill (Picked unit)
            • Unit - Remove (Picked unit) from PactGroup
          • Else - Actions
 
Level 2
Joined
Feb 12, 2023
Messages
11
This trigger runs flawless! Didn't think about using unit groups for this one, thanks for that!
Also I'll read about dynamic indexing anyways because it will surely help me making something more advanced in the future. Thank you guys!
 
Status
Not open for further replies.
Top