- Joined
- Apr 24, 2012
- Messages
- 5,113
JASS:
library TimedEffect /* v1.5
*************************************************************************************
*
* Allows one to create timed effects on 3d points or units.
*
*************************************************************************************
*
* API
*
* static method point takes string sfx, real x, real y, real z, real duration returns thistype
* - starts a timed effect on a 3d point
*
* static method target takes string sfx, widget target, string attach, real duration returns thistype
* - starts a timed effect on a unit
*
* method destroy takes nothing returns nothing
* - destroys an instance
*
* real time
* - the time remaining of the effect's life
* - use this if you want to adjust the time
*
*************************************************************************************
*
* Credits
*
* PurgeAndFire for the OTip trick.
* Bannar
*
**************************************************************************************/
globals
// Timeout of the effects
private constant real TIMEOUT = 0.03125
// Platform is used for creating special effects with z points
private constant integer PLATFORM = 'OTip'
endglobals
struct TimedEffect
private static constant timer t = CreateTimer()
private static effect tempEffect
private static destructable platform
private static thistype array next
private static thistype array prev
private effect effects
real time
method destroy takes nothing returns nothing
if effects != null then
call DestroyEffect(effects)
set effects = null
set time = 0
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
if next[this] == 0 then
call PauseTimer(t)
endif
endif
endmethod
private static method P takes nothing returns nothing
local thistype this = next[0]
loop
exitwhen 0 == this
set time = time - TIMEOUT
if 0 > time then
call destroy()
endif
set this = next[this]
endloop
endmethod
private method insert takes nothing returns nothing
set next[this] = 0
set prev[this] = prev[0]
set next[prev[0]] = this
set prev[0] = this
if prev[this] == 0 then
call TimerStart(t, TIMEOUT, true, function thistype.P)
endif
endmethod
static method point takes string sfx, real x, real y, real z, real duration returns thistype
local thistype this
if sfx != "" then
if 0 < z then
set platform = CreateDestructableZ(PLATFORM, x, y, z, 0, 1, 0)
endif
set tempEffect = AddSpecialEffect(sfx, x, y)
if null != platform then
call RemoveDestructable(platform)
set platform = null
endif
if duration < TIMEOUT then
call DestroyEffect(tempEffect)
set tempEffect = null
return 0
endif
set this = allocate()
set effects = tempEffect
set time = duration
set tempEffect = null
call insert()
return this
endif
return 0
endmethod
static method target takes string sfx, widget target, string attach, real duration returns thistype
local thistype this
if sfx != "" and target != null then
set tempEffect = AddSpecialEffectTarget(sfx, target, attach)
if duration < TIMEOUT then
call DestroyEffect(tempEffect)
set tempEffect = null
return 0
endif
set this = allocate()
set effects = tempEffect
set time = duration
set tempEffect = null
call insert()
return this
endif
return 0
endmethod
endstruct
endlibrary
Demo:
JASS:
struct Tester extends array
static timer tm = CreateTimer()
static integer i = 0
private static method looper takes nothing returns nothing
local real x = GetRandomReal(-1000, 1000)
local real y = GetRandomReal(-1000, 1000)
local real z = GetRandomReal(1, 500)
local real dur = 3
local TimedEffect te = TimedEffect.point( "units\\creeps\\NerubianQueen\\NerubianQueen.mdl", x, y, z, dur)
set i = i + 1
if i > 10 then
set te.time = 3
endif
endmethod
private static method onInit takes nothing returns nothing
call FogEnable(false)
call FogMaskEnable(false)
call TimerStart(tm, 0.1, true, function Tester.looper)
endmethod
endstruct
Last edited: