EDIT: It appears to be working with the code I have posted currently; however, the spell cast seems to have a delay to it. Is there any way to fix this?
So, I am attempting to make a library for using dummy casters for my map, however I seem to have run into an issue.
I have units that spawn on timers, and they are successfully removed; however, they never cast their spells. I haven't really worked much with dummy casters before, and don't really know what I'm doing wrong. Any help would be greatly appreciated.
So, I am attempting to make a library for using dummy casters for my map, however I seem to have run into an issue.
I have units that spawn on timers, and they are successfully removed; however, they never cast their spells. I haven't really worked much with dummy casters before, and don't really know what I'm doing wrong. Any help would be greatly appreciated.
JASS:
library DummyCasters initializer init
globals
private constant real DUMMY_DURATION = 5.0
private constant real DUMMY_TIMER_INTERVAL = 0.25
private DummyCaster array DummyCasters
private integer ActiveDummyCasters
private timer DummyCasterTimer
private integer index = 0
endglobals
private function DummyCaster_Timer takes nothing returns nothing
local DummyCaster dc
set index = 0
loop
// loop through all dummy casters
exitwhen (index >= ActiveDummyCasters)
// retrieve the dummy information
set dc = DummyCasters[index]
// decrement the caster duration
call dc.decrement()
// if the life has expired
if (dc.duration <= 0) then
call dc.destroy()
endif
set index = index + 1
endloop
// pause timer if no active casters exist
if (ActiveDummyCasters == 0) then
call PauseTimer(DummyCasterTimer)
endif
endfunction
struct DummyCaster
unit dummy
real duration
// initialize the struct
static method create takes nothing returns DummyCaster
local DummyCaster dc = DummyCaster.allocate()
// initialize vars
set dc.dummy = CreateUnit(Player(11), 'h002', 0, 0, bj_UNIT_FACING)
set dc.duration = DUMMY_DURATION
// start the timer if paused
if (ActiveDummyCasters == 0) then
call TimerStart(DummyCasterTimer, DUMMY_TIMER_INTERVAL, true, function DummyCaster_Timer)
endif
// add to the array
set DummyCasters[ActiveDummyCasters] = dc
set ActiveDummyCasters = ActiveDummyCasters + 1
call BJDebugMsg("DC.create()")
return dc
endmethod
method cast takes unit caster, unit target, integer abilityId, integer abilityLevel, string order returns nothing
// move the dummy to the source caster
call SetUnitPosition(.dummy, GetUnitX(caster), GetUnitY(caster))
// add the ability
call UnitAddAbility(.dummy, abilityId)
// level up the ability
if (abilityLevel > 0) then
call SetUnitAbilityLevel(.dummy, abilityId, abilityLevel)
endif
// issue the spell cast order
call IssueTargetOrder(.dummy, order, target)
endmethod
method decrement takes nothing returns nothing
set .duration = .duration - DUMMY_TIMER_INTERVAL
endmethod
method onDestroy takes nothing returns nothing
set DummyCasters[index] = DummyCasters[ActiveDummyCasters - 1]
set ActiveDummyCasters = ActiveDummyCasters - 1
// garbage collect
call RemoveUnit(.dummy)
set .dummy = null
call BJDebugMsg("dc.onDestroy()")
endmethod
endstruct
//===========================================================================
function init takes nothing returns nothing
set ActiveDummyCasters = 0
set DummyCasterTimer = CreateTimer()
endfunction
endlibrary