• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Special effect during casting time

Status
Not open for further replies.
Level 4
Joined
Sep 2, 2016
Messages
48
How do I define a special effect played (just one time) while the unit is casting the spell (during the casting time).
I mean special effect, not unit animation.

How to edit "channel" ability to have it?

I tried with triggers to <create a special effect> at the casting unit and at its location. It works only if I don't <destroy last created special effect>. But if I don't destroy it, I get leaks, right? And I don't want them.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,585
Set the sfx to a variable and create a new trigger. In this trigger destroy the sfx/clean up the leak. Use the Event "A unit stops casting an ability" so the trigger runs when you're done casting. It won't be MUI though (although that's easy to fix).

For Channel i'm pretty sure it only loops the Art - Target unless I'm mistaken.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,585
Here's a neat little system that will give you greater control over Special Effects. It allows you to Create a Special Effect, Set a Duration, and then run the system. After the duration has finished the special effect will be destroyed. It's leakless and MUI.
  • Delayed Destroy Effect
    • Events
    • Conditions
    • Actions
      • Custom script: local effect udg_Delayed_Sfx = GetLastCreatedEffectBJ()
      • Wait Delayed_Duration seconds
      • Special Effect - Destroy Delayed_Sfx
      • Custom script: set udg_Delayed_Sfx = null
Here's how you use the system. This is also how you could do it for your spell:
  • Example DDE
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • Special Effect - Create a special effect attached to the chest of (Triggering unit) using Abilities\Spells\Human\DivineShield\DivineShieldTarget.mdl
      • Set VariableSet Delayed_Duration = 1.00
      • Trigger - Run Delayed Destroy Effect <gen> (ignoring conditions)
 

Attachments

  • Delayed Destroy Effect.w3m
    16.7 KB · Views: 19
Level 4
Joined
Sep 2, 2016
Messages
48
Ok. I am not sure it is 100% leakless.
1. Unit begins casting.
2. I create special effect (Delayed_Sfx = SE_1)
3. Delayed_Duration = 1.00
4. It (1) begins waiting (1.00 left)
5. The unit is interrupted (with a ministun 0.01s.) in 0.6 sec of casting time.
6. The unit begins to cast the spell again in 0.61 (after the stun).
7. I create another special effect (Delayed_Sfx = SE_2)
!!!---SE_1 has just LEAKED---!!!
8. Delayed_Duration = 1.00
9. It (2) begins waiting (1.00 left)
(1 - 0.39 left)
10. After 0.39 s. it destroyes SE_2
11. Then after 0.61 it tries to destroy SE_2 again, but it is already destroyed.

Am I wrong?

But the system would be good if you add the Special effect to a group of special effects and after the time you destroy them all. Not after "Wait" but after "Timer expires.". Which would not expire too fast if refreshed after every cast.

In all of this I was hoping for some not trigger solution. Edited in GUI.
Thanks for the triggers.
 
Last edited:
Level 4
Joined
Sep 2, 2016
Messages
48
Is there a possibility to pass a variable to the ran trigger?
Something like:
function(local x)
{
-if(x>0)
-{
--Message: x;
--x--;
}
For function(3) should show:
3
2
1

I mean some kind of cumulative periodic event.

Hey ... Wouldn't it be enough if I make the same thing just more "waits"? Like in a loop?
In my case that should be:
x = 3
for(1-3)
{
-Message x
-x--
-wait 3s
}

Oh... I can't use local variable in for. I have to copy-paste the effect x times, right?

And also shouldn't we use <Wait game-time seconds>?
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Waits are renowned for creating issues, especially when using global variables. But not always though.

The best practices for passing variables to callback functions are usually tables (but in GUI and Jass it is not really easy. This said hashtables can help you because they allow you to use agents handle ids as keys when arrays just let you use integers) It's even easier in Lua because Lua Tables can take anything as a key.

Using hashtables can be done with GUI, and what you need to do is define parent and child keys to save your variables, in order to retrieve them inside your callback function using the same parent and child keys. For example, for a timer, you would use the timer's handle id as parent key, because you can get it back with the event response - expired timer that will allow you to obtain the parent key again. Then the child keys can be arbitrary, like 1 for a unit, 2 for an sfx etc... to your convenience.

I would not give you any practical example in GUI because I haven't touched it for such a long time, but if you follow the principle I have just mentioned, you should be able to do what you are trying to without ever needing a wait inside your triggers. Timers can do a wonderful job in this context !
 
Status
Not open for further replies.
Top