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
964
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
964
> 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
964
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top