Sadly I can't find my original post.
I do not have Warcraft anymore, so I'll try to teach it with text rather then the actual triggers.
Basically the idea is to separate the whole thing into two parts.
- Part 1 registers units that should be effected by your spell.
- Part 2 does the actual stuff that effects all the registered units.
Now, say your spell (as in this case) needs to know two things: the caster, and the target.
For this you need these variables (you will see exactly why later on):
- Unit array
- Unit array
- Integer (initialize at 0)
- Timer
Now, lets create the first part, which registers units.
Create a new trigger with whatever events and conditions you want.
Now you basically want to add the caster and the target to your unit arrays, and tell the trigger "I have registered a new unit and target".
You will set the index equal to the integer in the arrays (I'll call that integer "Total" from now on), then you will raise the value of Total by 1.
For example:
-
Set Casters[Total] = Caster
-
Set Targets[Total] = Target
-
Set Total = Total + 1
And that's it. You have registered a new "instance" of the spell.
Notice that it is good practice to check how many instances are running - if there are zero, you can pause the timer, if they become more then zero, you can unpause the timer.
Now lets go over part 2, where you actually DO stuff with the data you have.
Create a second trigger, with the event of your timer going off.
Now, create a loop that will loop from 0 (arrays start at 0), to [Total - 1] - that will be the count of the "running" instances.
Inside this loop, you will need to do two things, and can do one optional thing:
1) Do your actions.
Since you are looping through all the instances, you can refer to each caster as Casters[Integer A] and each target as Targets[Integer A] (assuming you called your arrays Casters and Targets of course).
2) Remove unneeded instances.
Once you don't need an instance (the spell's time is up, for example), you need to remove that instance, or in other words "unregister it".
The easiest way to do that, is take the LAST instance (Total - 1, since arrays start at 0), now you set that data to the current instance (the one that is being deleted), you set Total to its value minus 1, and that's it.
An example:
-
Set Casters[Integer A] = Casters[Total - 1]
-
Set Targets[Integer A] = Targets[Total - 1]
-
Set Total = Total - 1
2b) This is recommended but not necessary - whenever you unregister an instance, you can check if Total is equal to 0, and if it is you can pause the timer.
If you got it until here, then congratulate yourself. You have just learned how to make easy MUI repeatable-type-of-triggers in GUI (works in Jass too of course).