14 years
edited 8 years
Timed Effects
by moyack. 2009-2011
Introductionby moyack. 2009-2011
So... have you been needing a simple way (or function) to create an effect temporally and don't worry about destroying it? or you're needing that an effect with different animations (birth, stand, death) will show all of them?? if your answer is yes to any of those questions, then you're in the right place.
This script is used in my project Power of Corruption, as you'll see, it's simple as hell.
Just to point out: this library is very useful with effects that have different animations, so using this library with single animation effect will do the same as
1 call DestroyEffect(AddSpecialEffect(....))
How to use it?
Just add an effect as parameter and then you set its duration.
Example:
1 call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)
You won't need anything else, the system will care of cleaning the effect properly and recycle the values for you.
The code.
Here we have two flavors, acccording to the timer libraries you could have in your map. Select your best option.
This library requires TimerUtils
1 //***********************2 //* Timed Effects *3 //* by moyack. 2011 *4 //***********************5 //*6 //* Requires Jass NewGen Pack and TimerUtils by Various coders7 //* 8 //* Introduction9 //* ============10 //*11 //* So... have you been needing a simple way (or function) to create an effect temporally12 //* and don't worry about destroying it? or you're needing that an effect with different 13 //* animations (birth, stand, death) will show all of them?? if your answer is yes to any14 //* of those questions, then you're in the right place.15 //*16 //* This script is used in my project Power of Corruption ([url]http://poc.it.cx[/url]), as you'll see, 17 //* it's simple as hell.18 //*19 //* Just to point out: this library is very useful with effects that have different 20 //* animations, so using this library with single animation effect will do the same as 21 //* call DestroyEffect(AddSpecialEffect(....))22 //*23 //* How to use it?24 //* ==============25 //* - Create a trigger with a convenient name (like Timed Effects)26 //* - Convert the trigger to custom text27 //* - Copy and paste this code and save your map.28 //*29 //* With all this done, you just have to call the function StartTimedEffect(), and as parameters30 //* an effect and a real value which will be the effect duration.31 //*32 //* Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)33 //*34 //* You won't need anything else, the system will care of cleaning the effect properly 35 //* and recycle the values for you.36 37 library_once TimedEffects requires TimerUtils
38 39 private struct data
40 effect f = null
41 timer t
42 static method create takes effect f returns data
43 local data dt = data.allocate()
44 set dt.t = NewTimer()
45 set dt.f = f
46 call SetTimerData(dt.t, integer(dt))
47 return dt48 endmethod49 endstruct50 51 private function DestroyTimedEffect takes nothing returns nothing
52 local data d = data(GetTimerData(GetExpiredTimer()))
53 call DestroyEffect(d.f)
54 call ReleaseTimer(d.t)
55 call d.destroy()
56 endfunction57 58 function StartTimedEffect takes effect f, real dur returns nothing
59 local data d = data.create(f)
60 call TimerStart(d.t, dur, false, function DestroyTimedEffect)
61 endfunction62 63 endlibrary
This library requires TimedLoop
1 //***********************2 //* Timed Effects *3 //* by moyack. 2011 *4 //***********************5 //*6 //* Requires Jass NewGen Pack and TimedLoop by Vexorian7 //* 8 //* Introduction9 //* ============10 //*11 //* So... have you been needing a simple way (or function) to create an effect temporally12 //* and don't worry about destroying it? or you're needing that an effect with different 13 //* animations (birth, stand, death) will show all of them?? if your answer is yes to any14 //* of those questions, then you're in the right place.15 //*16 //* This script is used in my project Power of Corruption ([url]http://poc.it.cx[/url]), as you'll see, 17 //* it's simple as hell.18 //*19 //* Just to point out: this library is very useful with effects that have different 20 //* animations, so using this library with single animation effect will do the same as 21 //* call DestroyEffect(AddSpecialEffect(....))22 //*23 //* How to use it?24 //* ==============25 //* - Create a trigger with a convenient name (like Timed Effects)26 //* - Convert the trigger to custom text27 //* - Copy and paste this code and save your map.28 //*29 //* With all this done, you just have to call the function StartTimedEffect(), and as parameters30 //* an effect and a real value which will be the effect duration.31 //*32 //* Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)33 //*34 //* You won't need anything else, the system will care of cleaning the effect properly 35 //* and recycle the values for you.36 37 library_once TimedEffects requires TimedLoop
38 39 private struct data
40 effect f = null
41 real time = 0.
42 real dur
43
44 private method onTimedLoop takes nothing returns boolean
45 set .time = .time + TimedLoop_PERIOD
46 if .time > .dur then
47 call DestroyEffect(.f)
48 return TimedLoop_STOP49 endif50 return TimedLoop_CONTINUE51 endmethod52
53 implement TimedLoop54
55 static method create takes effect f, real t returns thistype
56 local thistype dt = thistype.allocate()
57 set dt.dur = t
58 set dt.f = f
59 call dt.startTimedLoop()
60 return dt61 endmethod62 endstruct63 64 function StartTimedEffect takes effect f, real dur returns nothing
65 local data d = data.create(f,dur)
66 endfunction67 68 endlibrary
Changelog
* 1/21/2009: First Release
* 3/08/2009: Now
1 StartTimedEffect
returns the index of the TimedEffect object and added the 1 StopTimedEffect
function so you can stop it manually.* 3/20/2009: Simplified more to avoid the .execute call
* 6/10/2011: Added TimedLoop version