If i call the following method more than once from the same object it doesn't work anymore
The first time it banishes the target but the second(and third, fourth,..) time the method runs but the dummy isn't created , i completely don't understand why.
.targets(.index) is changed properly , if i create special effect on .targets(.index) then it shows up on the correct unit in game.
I'm getting quite desperate, already testing this for a full hour.
EDIT:
JASS:
method Banish2 takes nothing returns nothing
local unit dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), bj_UNIT_FACING)
call UnitAddAbility(dummy, BANISHID)
call IssueTargetOrder(dummy, "banish", .targets[.index])
set dummy = null
endmethod
The first time it banishes the target but the second(and third, fourth,..) time the method runs but the dummy isn't created , i completely don't understand why.
.targets(.index) is changed properly , if i create special effect on .targets(.index) then it shows up on the correct unit in game.
I'm getting quite desperate, already testing this for a full hour.
EDIT:
JASS:
scope ChainBanish initializer Init
globals
private constant integer SPELLID = 'A01O'
private constant integer BANISHID = 'A00P'
private constant integer TARGETS = 7
private constant integer DUMMY = 'h009'
private constant real PERIOD = 1.40
private constant real BOUNCERANGE = 700.00
endglobals
//=============================================================================
globals
private boolexpr be
endglobals
private function isUnitAlly takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
endfunction
private struct Chain
unit array targets[TARGETS]
integer index
static method create takes unit u1 returns Chain
local Chain chain = Chain.allocate()
set chain.targets[0] = u1
set chain.index = 0
return chain
endmethod
method Banish2 takes nothing returns nothing
local unit dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), bj_UNIT_FACING)
call UnitAddAbility(dummy, BANISHID)
call IssueTargetOrder(dummy, "banish", .targets[.index])
set dummy = null
endmethod
method SetNextUnit takes nothing returns boolean
local group units = CreateGroup()
local integer i = 0
if .index == (TARGETS - 1) then
call DestroyGroup(units)
set units = null
debug call BJDebugMsg("targets full")
return false
endif
call GroupEnumUnitsInRange(units, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), BOUNCERANGE, be)
set .index = .index + 1
loop
exitwhen i == .index
if .targets[i] == FirstOfGroup(units) then
call GroupRemoveUnit( units, FirstOfGroup(units))
set i = -1
endif
set i = i + 1
endloop
set .targets[.index] = FirstOfGroup(units)
call DestroyGroup(units)
set units = null
if .targets[.index] != null then
debug call BJDebugMsg("unit found")
call .Banish2()
return true
else
debug call BJDebugMsg("unit not found")
return false
endif
endmethod
endstruct
private function Banish takes nothing returns nothing
local Chain chain = GetTimerData(GetExpiredTimer())
local unit dummy = null
if chain.SetNextUnit() != true then
call chain.destroy()
call ReleaseTimer(GetExpiredTimer())
else
set dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(chain.targets[chain.index - 1]), GetUnitY(chain.targets[chain.index - 1]), bj_UNIT_FACING)
call UnitAddAbility(dummy, SPELLID)
call IssueTargetOrder(dummy, "chainlightning", chain.targets[chain.index])
set dummy = null
endif
endfunction
private function Actions takes nothing returns nothing
local Chain chain = Chain.create(GetSpellTargetUnit())
local timer t = NewTimer()
call chain.Banish2()
call SetTimerData( t, chain)
call TimerStart( t, PERIOD, true, function Banish)
set t = null
endfunction
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) and (GetSpellAbilityId() == SPELLID)
endfunction
private function Init takes nothing returns nothing
local trigger gg_trg_Chain_Banish = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Chain_Banish, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Chain_Banish, Condition( function Conditions ) )
call TriggerAddAction( gg_trg_Chain_Banish, function Actions )
set be = Condition(function isUnitAlly)
endfunction
endscope
Last edited: