- Joined
- Apr 5, 2011
- Messages
- 245
Here is library used:
There are SeekUnitBegin and SeekUnitEnd
Here is the main code:
Take a look at onAttack
Exactly same thing written manually works properly, but implemented (right below) does not.
(Both compilated)
(Problem with return? Wrong module use?)
JASS:
//===============
//=== Indexed ===
//=== v0.900 ====
library Indexed requires Indexer
//Timers
module ObtainTimerIndex
set Assist.workInteger = 0
loop
exitwhen t[Assist.workInteger] == Assist.workTimer
set Assist.workInteger = Assist.workInteger + 1
endloop
endmodule
module ObtainLargeTimerIndex
set Assist.workInteger = 0
loop
exitwhen T[Assist.workInteger] == Assist.workTimer
set Assist.workInteger = Assist.workInteger + 1
endloop
endmodule
//Units
module ObtainUnitIndex
set Assist.workInteger = 0
loop
exitwhen u[Assist.workInteger] == Assist.workUnit
set Assist.workInteger = Assist.workInteger + 1
endloop
endmodule
module SeekUnitBegin
set Assist.workInteger = 0
loop
exitwhen Assist.workInteger == IndexCount(indexer)
if u[Assist.workInteger] == Assist.workUnit then
endmodule
module SeekUnitEnd
return
endif
set Assist.workInteger = Assist.workInteger + 1
endloop
endmodule
endlibrary
Here is the main code:
JASS:
//===================
//=== AttackDelay ===
//===== v1.000 ======
library AttackDelay requires Assist, Indexed, Orders
//=== Settings ===
globals
private constant integer ABILCODE = 'X211'
private constant string ORDER = "magicleash"
private constant string SFX = "AttackDelay.mdl"
private constant string SFX_ATTACH_POINT = "origin"
//----------------
private constant real COOLDOWN = 1.7
endglobals
//================
function UnitApplyAttackDelay takes unit u, real delay, real duration returns nothing
call AttackDelay.apply(u, delay, duration)
endfunction
struct AttackDelay extends array
private static integer indexer
private static unit array u
private static real array delay
private static boolean array slow
private static timer array T
private static timer array t
private static unit array caster
private static method onInit takes nothing returns nothing
set indexer = CreateIndexer()
endmethod
private static method end takes nothing returns nothing
set Assist.workTimer = GetExpiredTimer()
implement ObtainLargeTimerIndex
call Deindex(indexer, Assist.workInteger)
set u[Assist.workInteger] = null
set caster[Assist.workInteger] = null
call BJDebugMsg("END " + I2S(Assist.workInteger))
call PauseTimer(t[Assist.workInteger])
endmethod
static method apply takes unit u, real delay, real duration returns nothing
set Assist.workInteger = Index(indexer)
set thistype.u[Assist.workInteger] = u
set thistype.delay[Assist.workInteger] = delay
set slow[Assist.workInteger] = true
if T[Assist.workInteger] == null then
set T[Assist.workInteger] = CreateTimer()
set t[Assist.workInteger] = CreateTimer()
endif
call BJDebugMsg("APPLY " + I2S(Assist.workInteger))
call TimerStart(T[Assist.workInteger], duration, false, function thistype.end)
endmethod
static method onUnitIssuedOrder takes nothing returns nothing
set Assist.workUnit = GetTriggerUnit()
implement SeekUnitBegin
if GetIssuedOrderId() != ORDER_ATTACK + ORDERS_OFFSET and caster[Assist.workInteger] != null then
call BJDebugMsg("FREE " + I2S(Assist.workInteger))
call RemoveUnit(caster[Assist.workInteger])
set caster[Assist.workInteger] = null
endif
implement SeekUnitEnd
endmethod
private static method cooldown takes nothing returns nothing
set Assist.workTimer = GetExpiredTimer()
implement ObtainTimerIndex
set slow[Assist.workInteger] = true
endmethod
static method onAttack takes nothing returns nothing
set Assist.workUnit = GetAttacker()
set Assist.workInteger = 0
loop
exitwhen Assist.workInteger == IndexCount(indexer)
if u[Assist.workInteger] == Assist.workUnit then
if slow[Assist.workInteger] then
set slow[Assist.workInteger] = false
call BJDebugMsg("ATTACK " + I2S(Assist.workInteger))
call DestroyEffect(AddSpecialEffectTarget(SFX, Assist.workUnit, SFX_ATTACH_POINT))
call TimerStart(t[Assist.workInteger], COOLDOWN, false, function thistype.cooldown)
set caster[Assist.workInteger] = CastUnit(u[Assist.workInteger], u[Assist.workInteger], delay[Assist.workInteger], ABILCODE, 1, ORDER)
endif
return
endif
set Assist.workInteger = Assist.workInteger + 1
endloop
/*implement SeekUnitBegin
if slow[Assist.workInteger] then
set slow[Assist.workInteger] = false
call BJDebugMsg("ATTACK " + I2S(Assist.workInteger))
call DestroyEffect(AddSpecialEffectTarget(SFX, Assist.workUnit, SFX_ATTACH_POINT))
call TimerStart(t[Assist.workInteger], COOLDOWN, false, function thistype.cooldown)
set caster[Assist.workInteger] = CastUnit(u[Assist.workInteger], u[Assist.workInteger], delay[Assist.workInteger], ABILCODE, 1, ORDER)
endif
implement SeekUnitEnd*/
endmethod
endstruct
endlibrary
Exactly same thing written manually works properly, but implemented (right below) does not.
(Both compilated)
(Problem with return? Wrong module use?)