//***********************
//* Timed Effects *
//* by moyack. 2009 *
//***********************
//*
//* Requires Jass NewGen Pack and TimerUtils
//*
//* Introduction
//* ============
//*
//* 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 ([url]www.pocr.tk)[/url], 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
//* call DestroyEffect(AddSpecialEffect(....))
//*
//* How to use it?
//* ==============
//* - Create a trigger with a convenient name (like Timed Effects :P)
//* - Convert the trigger to custom text
//* - Copy and paste this code and save your map.
//*
//* With all this done, you just have to call the function StartTimedEffect(), and as parameters
//* an effect and a real value which will be the effect duration.
//*
//* Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)
//*
//* This function will return an integer which will represent the timed effect index, this value
//* can be used when, for example, you need to end the effect before the duration time.
//*
//* To stop it, you just call the function StopTimedEffect():
//*
//* Example: call StopTimedEffect(1) // will stop the timed effect with that index.
//*
//* You won't need anything else, the system will care of cleaning the effect properly
//* and recycle the values for you.
library TimedEffects requires TimerUtils
private struct data
effect f = null
timer t
static method create takes effect f returns data
local data dt = data.allocate()
set dt.t = NewTimer()
set dt.f = f
call SetTimerData(dt.t, integer(dt))
return dt
endmethod
endstruct
function StopTimedEffect takes integer index returns nothing
call DestroyEffect(data(index).f)
call ReleaseTimer(data(index).t)
call data(index).destroy()
endfunction
private function DestroyTimedEffect takes nothing returns nothing
call StopTimedEffect(GetTimerData(GetExpiredTimer()))
endfunction
function StartTimedEffect takes effect f, real dur returns integer
local data d = data.create(f)
call TimerStart(d.t, dur, false, function DestroyTimedEffect)
return integer(d)
endfunction
endlibrary