- Joined
- Dec 15, 2011
- Messages
- 1,423
Extension for Nestharus' Dummy that addresses quite a few annoying issues.
Thanks to Geries and BPower for their help in improving this snippet.
Demo #1: Scaling an effect that must be attached.
Demo #2: Playing the death animation of an effect
Thanks to Geries and BPower for their help in improving this snippet.
JASS:
library DelayedDummyRecycler /* v1.0.0.7
*************************************************************************************
*
* Delay dummy recycling for a Dummy. This is created as an extension for Nestharus' Dummy
* library since it does not have a feature that scales special effects' death animation.
*
* All delayed effects will be resolved before the dummy is recycled.
*
*************************************************************************************
*
* Credits
*
* Nestharus
* -----------------------
*
* Dummy, Alloc
*
* Vexorian
* -----------------------
*
* TimerUtils
*
* Jesus4Lyf & PurgeandFire
* -----------------------
*
* Stack Safety
*
*
*************************************************************************************
*
* Function
* -----------------------
*
* function RecycleDummyDelayed takes Dummy dummy, real timeout, effect fx, boolean fxDead returns nothing
*
* Description
* -----------------------
*
* Delay the recycling of a Dummy.
* Use this function instead of Dummy.destroy()
*
* Takes
* -----------------------
*
* Dummy dummy
* - The target Dummy
*
* real timeout
* - The delay time before recycling is executed
*
* effect fx
* - The effect currently attached to the dummy
*
* boolean fxDead
* - Set to true if you want to play the death animation of the effect
*
*************************************************************************************
*
* Function
* -----------------------
*
* function RecycleDummyDelayedEx takes unit dummy, real timeout, effect fx, boolean fxDead returns nothing
*
* Description
* -----------------------
*
* Delay the recycling of a Dummy.
* For those who prefer to work with units.
* Use this function instead of Dummy.destroy()
*
* Takes
* -----------------------
*
* unit dummy
* - The target dummy unit
*
* real timeout
* - The delay time before recycling is executed
*
* effect fx
* - The effect currently attached to the dummy
*
* boolean fxDead
* - Set to true if you want to play the death animation of the effect
*
*************************************************************************************
*
* */ uses /*
*
* */ Alloc /* hiveworkshop.com/forums/jass-resources-412/snippet-alloc-alternative-221493/
* */ Dummy /* hiveworkshop.com/forums/jass-resources-412/system-dummy-213908/
* */ TimerUtils /* wc3c.net/showthread.php?t=101322
*
************************************************************************************/
globals
private integer array stackLevel
endglobals
private struct DelayedDummyRecycler extends array
implement Alloc
private Dummy dum
private effect sfx
private static method onExpire takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
call SetUnitScale(this.dum.unit, 1., 0, 0)
call SetUnitVertexColor(this.dum.unit, 255, 255, 255, 255)
call SetUnitFlyHeight(this.dum.unit, 0., 0.)
call SetUnitTimeScale(this.dum.unit, 1.)
if this.sfx != null then
call DestroyEffect(this.sfx)
set this.sfx = null
endif
set stackLevel[this.dum] = stackLevel[this.dum] - 1
if stackLevel[this.dum] == 0 then
call this.dum.destroy()
endif
call ReleaseTimer(t)
call this.deallocate()
set t = null
endmethod
static method create takes Dummy dummy, real timeout, effect fx, boolean fxDead returns thistype
local thistype this = thistype.allocate()
local timer t = NewTimer()
set this.dum = dummy
set this.sfx = fx
if fxDead then
call DestroyEffect(this.sfx)
set this.sfx = null
endif
set stackLevel[this.dum] = stackLevel[this.dum] + 1
call SetTimerData(t, this)
call TimerStart(t, timeout, false, function thistype.onExpire)
set t = null
return this
endmethod
endstruct
function RecycleDummyDelayed takes Dummy dummy, real timeout, effect fx, boolean fxDead returns nothing
call DelayedDummyRecycler.create(dummy, timeout, fx, fxDead)
endfunction
function RecycleDummyDelayedEx takes unit dummy, real timeout, effect fx, boolean fxDead returns nothing
call DelayedDummyRecycler.create(Dummy[dummy], timeout, fx, fxDead)
endfunction
endlibrary
Demo #1: Scaling an effect that must be attached.
JASS:
struct Test extends array
static method onEsc takes nothing returns nothing
local unit v
local integer i = 0
loop
exitwhen i == 12
set v = Dummy.create(GetRandomReal(100, 300)*Cos(GetRandomReal(-bj_PI, bj_PI)), GetRandomReal(100, 300)*Sin(GetRandomReal(-bj_PI, bj_PI)), 270).unit
call SetUnitScale(v, 3., 0, 0)
call SetUnitFlyHeight(v, 100, 0)
call RecycleDummyDelayedEx(v, 4, AddSpecialEffectTarget("war3mapImported\\EMPBomb.mdx", v, "origin"))
set v = null
set i = i + 1
endloop
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(t, function thistype.onEsc)
set t = null
endmethod
endstruct
Demo #2: Playing the death animation of an effect
JASS:
struct TestEx extends array
static method onEsc takes nothing returns nothing
local unit v
local integer i = 0
loop
exitwhen i == 12
set v = Dummy.create(GetRandomReal(100, 300)*Cos(GetRandomReal(-bj_PI, bj_PI)), GetRandomReal(100, 300)*Sin(GetRandomReal(-bj_PI, bj_PI)), 270).unit
call SetUnitScale(v, 3., 0, 0)
call SetUnitFlyHeight(v, 100, 0)
call RecycleDummyDelayedEx(v, 7, AddSpecialEffectTarget("Abilities\\Weapons\\RocketMissile\\RocketMissile.mdl", v, "origin"), true)
set v = null
set i = i + 1
endloop
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerKeyEventBJ(t, Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP)
call TriggerAddAction(t, function thistype.onEsc)
set t = null
endmethod
endstruct
Attachments
Last edited: