Tutorial How to remove a Special Effect later

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)
 

Azlier

Old World Ghost
Reaction score
461
I don't see why you need a second trigger. Furthermore, your local effect leaks. Local handles must be nulled.
 

lindenkron

You can change this now in User CP
Reaction score
102
I don't see why you need a second trigger. Furthermore, your local effect leaks. Local handles must be nulled.

Explain how to null it and it will be added :)
The second trigger is so it's easyer to destroy effects in many spells.
You just call Trigger Run that trigger, instead of having to do it in each other trigger :)
Thanks
-Lindenkron
 

Azlier

Old World Ghost
Reaction score
461
JASS:
set tempEffect = null


EDIT:
You must destroy the effect before nulling it.

Oops. Nevermind. I see you are setting the global to it and then destroying the global! I hate the complications of GUI :p.
 

Romek

Super Moderator
Reaction score
963
Code:
Custom script: local effect tempEffect
Custom script: set tempEffect = udg_SpecialEffect
local effect tempEffect = udg_SpecialEffect

Code:
Custom script: set udg_SpecialEffect = tempEffect
Custom script: set tempEffect = null
Special Effect - Destroy SpecialEffect
call DestroyEffect(tempEffect)
set tempEffect = null

Anyway, this is far too specific and obvious to be made into a tutorial. Especially of that length. This can be summed up in about a paragraph.

Also, why the hell is this a [Snippet] and not a [Tutorial]? o_O
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
FWIW, the global isn't needed, and you could pass the wait time as parameter:
JASS:
function RemoveEffect takes real t returns nothing
    local effect e = bj_lastCreatedEffect
    call TriggerSleepAction(t)
    call DestroyEffect(e)
    set e = null
endfunction


A simple "Custom script: call RemoveEffect(10.0)" will do.


Still, ever tried this with, for example
For each Integer A from 1 to 10
... effect here

How long did it take that loop to finish?

Or something like "Pick every unit in ..."?


> why the hell is this a [Snippet] and not a [Tutorial]?

I don't really think this 4 liner here qualifies as tutorial... :p
 

Romek

Super Moderator
Reaction score
963
> I don't really think this 4 liner here qualifies as tutorial...
Well, the code itself is 4 lines, but the amount of explanation that he's used would make it more of a tutorial I think.

> How long did it take that loop to finish?
Doesn't running triggers start a new thread?
So that would take the usual amount of time to finish. (Assuming the above is correct)
Also, if that is the case. It'd mean the current solution is more suitable than your snippet.
 

Romek

Super Moderator
Reaction score
963
Run Trigger (TriggerExecute()) does indeed create a new thread.

If the user has Newgen, they could use call RemoveEffect.execute(time) with your solution. Another option would be to execute a trigger from within the RemoveEffect function. But as it currently stands, the "Run Trigger" solution is more suitable.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top