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

Loop and pause

Status
Not open for further replies.
Level 11
Joined
Nov 25, 2014
Messages
526
I need some help. I have been hibernating from Warcraft III for more than a year and I pretty much forgot a lot of triggering stuffs. So please don't lash at me.

Basically it is a 'spell'. When a Hero casts it, it summons 5 obelisks around it and they attack the Hero for 10 seconds. During this summoning, the Hero is paused and plays the channel animation. After 10 seconds, the obelisks expire and the Hero should be unpaused and resets his animation to default.

But it doesn't work. Why?

  • Ritual
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Marked
    • Actions
      • Set temppoint[100] = (Position of (Casting unit))
      • For each (Integer A) from 101 to 105, do (Actions)
        • Loop - Actions
          • Set temppoint[(Integer A)] = ((temppoint[100] offset by 0.00 towards 0.00 degrees) offset by 256.00 towards (72.00 x (Real((Integer A)))) degrees)
          • Unit - Pause (Casting unit)
          • Animation - Play (Casting unit)'s channel animation
          • Unit - Create 1 Monk for Player 12 (Brown) at temppoint[(Integer A)] facing Default building facing degrees
          • Set createdunit[(Integer A)] = (Last created unit)
          • Unit - Add a 10.00 second Generic expiration timer to createdunit[(Integer A)]
          • Unit - Order createdunit[(Integer A)] to Attack (Casting unit)
      • Wait 10.00 seconds
      • Unit - Unpause (Casting unit)
      • Animation - Reset (Casting unit)'s animation
      • Custom script: call RemoveLocation(udg_temppoint[100])
      • Custom script: call RemoveLocation(udg_temppoint[101])
      • Custom script: call RemoveLocation(udg_temppoint[102])
      • Custom script: call RemoveLocation(udg_temppoint[103])
      • Custom script: call RemoveLocation(udg_temppoint[104])
      • Custom script: call RemoveLocation(udg_temppoint[105])
 
Level 13
Joined
May 10, 2009
Messages
868
Use "Triggering Unit" instead of "Casting Unit" because the latter acts like a global variable. So if another unit casts any spell, Casting Unit gets overwritten.
You don't need to pause a unit and play anim 5 times in a row, move them out of the loop.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
"it doesn't work" could mean 50 different things. What happens? what doesn't happen?

Either way, why is the loop from 101 to 105 and not 1 to 5?

If you want to fix the leaks, you can remove the locations right after you create the units in the loop itself, you don't need a location array for this, nor is a location array a solution for cases where multiple units can cast this.
The location of the casting unit should be removed before the wait as well (read below why).

Why do you set the last created unit to an array index in the loop? you don't really need a variable in the first place, since it's not much better than using the last created unit, but then it's only worse because on top of that it's an array. By worse in this context I mean it's messy and makes everything looks complex when it shouldn't be.

And just to re-iterate the comments above...

Why are you pausing and playing the animation 5 times in a row?

And indeed always use Triggering Unit when possible (or a local variable when not possible) when using waits, as Casting Unit and many other such functions are indeed global, making any trigger with a wait unpredictable.
That is, after the 10 seconds wait, Casting Unit could have changed many times since the trigger began, while Triggering Unit will always be the same for this specific instance of the trigger running.
Saving Casting Unit to a variable before the wait isn't a good solution either, because the trigger then doesn't support being casted by multiple units in this 10 seconds period of time, unless it is a local variable which would emulate how Triggering Unit works.
This is also true for the locations you store, since they are stored in global variables. If any unit casts this spell in the 10 seconds window, they will be overwritten, and the original ones are forever leaked.
 
Last edited:
Level 21
Joined
Mar 29, 2020
Messages
1,237
During this summoning, the Hero is paused and plays the channel animation

you don't need to trigger this part. this part can be done with the settings of the channel spell. I don't remeber exactly what the settings are called, but I think just set "follow through time" to 10 seconds, and make it uninteruptable (I don't have the editor open and don't remember what the field is called).
 
Status
Not open for further replies.
Top