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
call DestroyEffect(AddSpecialEffect(....))How to use it?
Just add an effect as parameter and then you set its duration.
Example:
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
//***********************
//* Timed Effects *
//* by moyack. 2011 *
//***********************
//*
//* Requires Jass NewGen Pack and TimerUtils by Various coders
//*
//* 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]http://poc.it.cx[/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)
//* - 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.)
//*
//* You won't need anything else, the system will care of cleaning the effect properly
//* and recycle the values for you.
library_once 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
private function DestroyTimedEffect takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
call DestroyEffect(d.f)
call ReleaseTimer(d.t)
call d.destroy()
endfunction
function StartTimedEffect takes effect f, real dur returns nothing
local data d = data.create(f)
call TimerStart(d.t, dur, false, function DestroyTimedEffect)
endfunction
endlibraryThis library requires TimedLoop
//***********************
//* Timed Effects *
//* by moyack. 2011 *
//***********************
//*
//* Requires Jass NewGen Pack and TimedLoop by Vexorian
//*
//* 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]http://poc.it.cx[/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)
//* - 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.)
//*
//* You won't need anything else, the system will care of cleaning the effect properly
//* and recycle the values for you.
library_once TimedEffects requires TimedLoop
private struct data
effect f = null
real time = 0.
real dur
private method onTimedLoop takes nothing returns boolean
set .time = .time + TimedLoop_PERIOD
if .time > .dur then
call DestroyEffect(.f)
return TimedLoop_STOP
endif
return TimedLoop_CONTINUE
endmethod
implement TimedLoop
static method create takes effect f, real t returns thistype
local thistype dt = thistype.allocate()
set dt.dur = t
set dt.f = f
call dt.startTimedLoop()
return dt
endmethod
endstruct
function StartTimedEffect takes effect f, real dur returns nothing
local data d = data.create(f,dur)
endfunction
endlibraryChangelog
* 1/21/2009: First Release
* 3/08/2009: Now
StartTimedEffect returns the index of the TimedEffect object and added the StopTimedEffect function so you can stop it manually.* 3/20/2009: Simplified more to avoid the .execute call
* 6/10/2011: Added TimedLoop version