- Joined
- May 26, 2009
- Messages
- 1,829
Introduction
Creating delayed spell effects that are MUI without the use of waits is fairly
simple. It just requires two variables and one periodic trigger. The first variable
is an integer that represents the current spell instance, whereas the second variable
is an integer that represents the total number of spell instances.
Avoiding Waits
This is an example of a spell that uses a Wait action in order to create a delayed effect:
This spell is not MUI and will give an inaccurate delay. In order to fix this, we
need to split this spell into two triggers. The first trigger will execute when the
spell is cast, and it will store spell data such as the caster, the level, the owner
of the caster, etc... The second trigger is going to have a periodic event. Let's make
it run every 1 second for simplicity as opposed to the 0.03 seconds used by most spell
makers. If you're going to make a timed spell, use 0.03. What we're going to do is add
one spell instance when the spell is cast, and iterate over all the spell instances in
the periodic trigger. It's basic indexing, and it looks like this:
There we go, this is our spell. 100% MUI and functional.
Using a Counter
This spell will wait 1 second, not 2. This is a problem that can
be addressed by using a counter.
In the caster trigger, we're going to set our counter to 0, and
in the periodic trigger, we're going to increment our counter by 1.
If the counter reaches our desired value, we execute the remaining
code and end the spell instance.
This is what our final product would look like:
Overview
This is a small explanation concerning what will actually happen during the
execution of the spell to clear things up for you if you didn't get it yet.
Wrap-up
If you still find it hard to understand, feel free to PM me any time.
Thank you for reading.
~Tank-Commander
Creating delayed spell effects that are MUI without the use of waits is fairly
simple. It just requires two variables and one periodic trigger. The first variable
is an integer that represents the current spell instance, whereas the second variable
is an integer that represents the total number of spell instances.
Avoiding Waits
This is an example of a spell that uses a Wait action in order to create a delayed effect:
-
Example
-
Events
- Unit - A unit Starts the effect of an ability
-
Conditions
- (Ability being cast) Equal to Example
-
Actions
- Set TempUnit = (Triggering unit)
- Set TempPoint = (Target point of ability being cast)
- Wait 2.00 seconds
- Set TempGroup = (Units within 300.00 of TempPoint)
-
Unit Group - Pick every unit in TempGroup and do (Actions)
-
Loop - Actions
- Unit - Cause TempUnit to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
-
Loop - Actions
- Custom script: call DestroyGroup(udg_TempGroup)
- Custom script: call RemoveLocation(udg_TempPoint)
-
Events
need to split this spell into two triggers. The first trigger will execute when the
spell is cast, and it will store spell data such as the caster, the level, the owner
of the caster, etc... The second trigger is going to have a periodic event. Let's make
it run every 1 second for simplicity as opposed to the 0.03 seconds used by most spell
makers. If you're going to make a timed spell, use 0.03. What we're going to do is add
one spell instance when the spell is cast, and iterate over all the spell instances in
the periodic trigger. It's basic indexing, and it looks like this:
-
Cast
-
Events
- Unit - A unit Starts the effect of an ability
-
Conditions
- (Ability being cast) Equal to Animate Dead
-
Actions
- Set MaxIndex = (MaxIndex + 1)
- -------- Here's the bit we had in the first place before the wait --------
- Set TempUnit[MaxIndex] = (Triggering unit)
- Set TempPoint[MaxIndex] = (Position of TempUnit[MaxIndex])
- -------- ----------------- --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- MaxIndex Equal to 1
-
Then - Actions
- Trigger - Turn on Loop <gen>
- Else - Actions
-
If - Conditions
-
Events
-
Loop
-
Events
- Time - Every 1.00 seconds of game time
- Conditions
-
Actions
-
For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
-
Loop - Actions
- -------- Here's the bit we had in the first place after the wait --------
- Set TempGroup = (Units within 200.00 of TempPoint[CurrentIndex])
-
Unit Group - Pick every unit in TempGroup and do (Actions)
-
Loop - Actions
- Unit - Cause TempUnit[CurrentIndex] to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
-
Loop - Actions
- Custom script: call DestroyGroup(udg_TempGroup)
- -------- This is recycling. It's unimportant in terms of spell effects, but it is important in terms of MU-Instancability --------
- Custom script: call RemoveLocation(udg_TempPoint[udg_CurrentIndex])
- Set TempPoint[CurrentIndex] = TempPoint[MaxIndex]
- Set TempUnit[CurrentIndex] = TempUnit[MaxIndex]
- Set MaxIndex = (MaxIndex - 1)
- Set CurrentIndex = (CurrentIndex - 1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- MaxIndex Equal to 0
-
Then - Actions
- Trigger - Turn off (This trigger)
- Else - Actions
-
If - Conditions
-
Loop - Actions
-
For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
-
Events
Using a Counter
This spell will wait 1 second, not 2. This is a problem that can
be addressed by using a counter.
In the caster trigger, we're going to set our counter to 0, and
in the periodic trigger, we're going to increment our counter by 1.
If the counter reaches our desired value, we execute the remaining
code and end the spell instance.
This is what our final product would look like:
-
Cast
-
Events
- Unit - A unit Starts the effect of an ability
-
Conditions
- (Ability being cast) Equal to Animate Dead
-
Actions
- Set MaxIndex = (MaxIndex + 1)
- -------- Here's the bit we had in the first place before the wait --------
- Set TempUnit[MaxIndex] = (Triggering unit)
- Set TempPoint[MaxIndex] = (Position of TempUnit[MaxIndex])
- Set Counter[MaxIndex] = 0
- -------- ----------------- --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- MaxIndex Equal to 1
-
Then - Actions
- Trigger - Turn on Loop <gen>
- Else - Actions
-
If - Conditions
-
Events
-
Loop
-
Events
- Time - Every 1.00 seconds of game time
- Conditions
-
Actions
-
For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
-
Loop - Actions
- Set Counter[CurrentIndex] = (Counter[CurrentIndex] + 1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- Counter[CurrentIndex] Equal to 2
-
Then - Actions
- -------- Here's the bit we had in the first place after the wait --------
- Set TempGroup = (Units within 200.00 of TempPoint[CurrentIndex])
-
Unit Group - Pick every unit in TempGroup and do (Actions)
-
Loop - Actions
- Unit - Cause TempUnit[CurrentIndex] to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
-
Loop - Actions
- Custom script: call DestroyGroup(udg_TempGroup)
- -------- Recycling --------
- Custom script: call RemoveLocation(udg_TempPoint[udg_CurrentIndex])
- Set TempPoint[CurrentIndex] = TempPoint[MaxIndex]
- Set TempUnit[CurrentIndex] = TempUnit[MaxIndex]
- Set Counter[CurrentIndex] = Counter[MaxIndex]
- Set MaxIndex = (MaxIndex - 1)
- Set CurrentIndex = (CurrentIndex - 1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- MaxIndex Equal to 0
-
Then - Actions
- Trigger - Turn off (This trigger)
- Else - Actions
-
If - Conditions
- Else - Actions
-
If - Conditions
-
Loop - Actions
-
For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
-
Events
This is a small explanation concerning what will actually happen during the
execution of the spell to clear things up for you if you didn't get it yet.
Let MaxCounter = 2.
1) The spell has been cast.
2) After 1 second:
3) After 2 seconds:
This spell is now MUI and works for our desired delay duration.
1) The spell has been cast.
2) After 1 second:
- Counter is initially 0.
- Counter = Counter + 1
- Counter is now 1.
- Counter < MaxCounter
- Nothing happens.
3) After 2 seconds:
- Counter is initially 1.
- Counter = Counter + 1
- Counter is now 2.
- Counter == MaxCounter
- Actions execute.
- Spell instance recycled.
This spell is now MUI and works for our desired delay duration.
Wrap-up
If you still find it hard to understand, feel free to PM me any time.
Thank you for reading.
~Tank-Commander