lindenkron
You can change this now in User CP
- Reaction score
- 102
How to remove a Special Effect later
Notification
First of all I'd like to state that I do not know if there has been made a tutorial / snippet or any other thread regarding this issue, but it seems that alot of people are having issues with destroying effects at a later time.
If any moderator feel that this thread is unnessesary or unneed feel free to move it instantly to the graveyard. But I would just like to have a place to referer people to when they ask about animations etc.
Intro
In fast terms this snippet is just a simple demonstration of how you could create an effect and destroy it after an X amount of seconds. Will cover what triggers needs to be added in your actual spell, and in the additional trigger we will be making.
Basic explanation - Birth animation destroy
In your spell, when ever you are creating an effect that cannot be destroyed instantly, due to the fact that it is not being showed on its birth animation
If you create a spell, for example Animate Dead
Trigger:
- Actions
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
calling a Destroy right after would be enough to make sure the Special Effect does not leave a leak. Like this:
Trigger:
- Actions
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
- Special Effect - Destroy (Last created special effect)
That would let the Animate dead play it's birth animation and then be destroyed leaving no leaks.
______________
Your Spell - The Triggers
How-ever. If you wish to create an animation at a point, and wait a specific amount of seconds before removing it, you'll need to set the Special Effect in a Variable and use some Custom Scripts.
This animation could for example be Item Attack Frost Bonus. Abilities\Spells\Items\AIob\AIobTarget.mdl.
First off:
Create a Variable of the type Special Effect
Then, we need to create our effect
Trigger:
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Items\AIob\AIobTarget.mdl
Then we need to set our variable
Trigger:
- Set SpecialEffect = (Last created special effect)
Then we will run a secondary trigger, which will be explained further down.
Trigger:
- Trigger - Run DestroyEffect <gen> (ignoring conditions)
Your spell trigger should now look something like this at your effect:
Trigger:
- Actions
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Items\AIob\AIobTarget.mdl
- Set SpecialEffect = (Last created special effect)
- Trigger - Run DestroyEffect <gen> (ignoring conditions)
KEEP IN MIND THAT (Center of (Playable map area)) IS A POINT, AND WILL LEAK IF NOT SET IN A VARIABLE AND DESTROYED AS WELL.
______________
The DestroyEffect - Triggers
Lets say that we want to destroy our new effect after 10 seconds. This is where we got to pull out all of those Custom Scripts.
To save each specific special effect, we will need to use locals to avoid them overwriting eachother. To use locals we need to use custom scripts.
First of, we need to create the local. This will create a local of the type effect, called tempEffect (For storing our Special Effect)
Trigger:
- Custom script: local effect tempEffect
Then we will set this local we have just created above, to be equal to our actual effect. (The one we stored in the SpecialEffect variable in the first trigger.) Remember the "udg_". This tells JASS (Custom script) that it's a "User Defined Global" (don't ask me what it means.).
Trigger:
- Custom script: set tempEffect = udg_SpecialEffect
After that, you can add your wait. Due to the fact that we have our special effect saved in a local, we can still get a hold of it later, even though there has been a wait.
Trigger:
- Wait 10.00 seconds
Now that the time is over, we need to get a hold of that specific special effect. This is done by setting our local to be our Special Effect variable. Once again, remember the "udg_".
Trigger:
- Custom script: set udg_SpecialEffect = tempEffect
Also all locals need to be nulled to avoid leaks. (By Azlier)
Trigger:
- Custom script: set tempEffect = null
After that, simple call the destroy on your variable "SpecialEffect" and that specific effect will be destroyed.
Trigger:
- Special Effect - Destroy SpecialEffect
Your triggers should now look something like this:
Trigger:
- Actions
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Items\AIob\AIobTarget.mdl
- Set SpecialEffect = (Last created special effect)
- Trigger - Run DestroyEffect <gen> (ignoring conditions)
Trigger:
- DestroyEffect
- Events
- Conditions
- Actions
- Custom script: local effect tempEffect
- Custom script: set tempEffect = udg_SpecialEffect
- Wait 10.00 seconds
- Custom script: set udg_SpecialEffect = tempEffect
- Custom script: set tempEffect = null
- Special Effect - Destroy SpecialEffect
-------- NOTE --------
You can also make individual waits on each time you run it, just by setting a variable to the wait, instead of "10 seconds". Like this:
Trigger:
- Actions
- Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Items\AIob\AIobTarget.mdl
- Set SpecialEffect = (Last created special effect)
- Set SFXWait = 6.00
- Trigger - Run DestroyEffect <gen> (ignoring conditions)
Trigger:
- DestroyEffect
- Events
- Conditions
- Actions
- Custom script: local effect tempEffect
- Custom script: set tempEffect = udg_SpecialEffect
- Wait SFXWait seconds
- Custom script: set udg_SpecialEffect = tempEffect
- Custom script: set tempEffect = null
- Special Effect - Destroy SpecialEffect
Code:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X Feel free to come with constructed criticism X
X grammatical errors & corrections X
X [B]Any help will be appreciated[/B] X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Hope this helps atleast some people :thup:
-Lindenkron
Fix log:
22 feb 09 Fixed null leak on local effect 'tempEffect' - (Thanks Azlier)