//*************************************************************************** //* //* TimedHandles - By TriggerHappy187 //* //*************************************************************************** //* //* Installation //* Simply copy this script into your map, as well as TimerUtils. //* //*************************************************************************** //* //* Documentation //* //* All this script does it associates a handle to a //* timer and then destroys the handle upon the timer's expiration. //* //*************************************************************************** //* //* The Public Functions //* //* $DESTROY$Timed - Starts the handle and it's timer, once it expires //* the handle will be destroyed. //* //*************************************************************************** //* //* Examples //* //* call DestroyEffectTimed(AddSpecialEffect("MODELNAME", X, X), 2) //* call DestroyEffectTimed(AddSpecialEffectTarget("MODELNAME", unit, "attachment-point"), 2) //* //*************************************************************************** library TimedHandles requires TimerUtils //! textmacro TIMEDHANDLES takes HANDLE,DESTROY struct $HANDLE$timed $HANDLE$ $HANDLE$_var private static method remove takes nothing returns nothing local timer t = GetExpiredTimer() local $HANDLE$timed d = GetTimerData(t) call $DESTROY$(d.$HANDLE$_var) call ReleaseTimer(t) call d.destroy() endmethod static method create takes $HANDLE$ h, real timeout returns $HANDLE$timed local $HANDLE$timed t = $HANDLE$timed.allocate() local timer ti = NewTimer() set t.$HANDLE$_var = h call SetTimerData(ti, t) call TimerStart(ti, timeout, false, function $HANDLE$timed.remove) return t endmethod endstruct function $DESTROY$Timed takes $HANDLE$ h, real duration returns nothing call $HANDLE$timed.create(h, duration) endfunction //! endtextmacro //! runtextmacro TIMEDHANDLES("effect","DestroyEffect") //! runtextmacro TIMEDHANDLES("lightning","DestroyLightning") //! runtextmacro TIMEDHANDLES("weathereffect","RemoveWeatherEffect") //! runtextmacro TIMEDHANDLES("item","RemoveItem") //! runtextmacro TIMEDHANDLES("ubersplat","DestroyUbersplat") endlibrary