Code:
function Trig_Spirit_Call_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A003'
endfunction
function SpiritCallEnd takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local unit caster = GetHandleUnit(t,"caster")
local unit summoned = GetHandleUnit(t,"summoned")
local integer i = 1
local integer j = 6
call DisplayTextToForce(GetPlayersAll(),"Summoned has died.")
call PauseUnitBJ(false,caster)
call SelectUnitForPlayerSingle( caster, GetOwningPlayer(caster) )
call SetHeroXP( caster, GetHeroXP(summoned), false )
loop
exitwhen i > j
call UnitAddItemByIdSwapped( GetItemTypeId(UnitItemInSlotBJ(summoned, i)), caster )
set i = i + 1
endloop
call DisplayTextToForce(GetPlayersAll(),"Items transferred back.")
set caster = null
set summoned = null
endfunction
function Trig_Spirit_Call_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location targetpt = GetSpellTargetLoc()
local integer level = GetUnitAbilityLevel(caster,'A003')
local unit summoned
local trigger t
local integer i = 1
local integer j = 6
local real facing = GetUnitFacing(caster)
call PauseUnitBJ(true,caster)
if level==1 then
call CreateNUnitsAtLoc(1,'H002',GetOwningPlayer(caster),targetpt,facing)
elseif level==2 then
call CreateNUnitsAtLoc(1,'H003',GetOwningPlayer(caster),targetpt,facing)
elseif level==3 then
call CreateNUnitsAtLoc(1,'H001',GetOwningPlayer(caster),targetpt,facing)
endif
set summoned = GetLastCreatedUnit()
call DisplayTextToForce(GetPlayersAll(),"Summoned has been created.")
call SelectUnitForPlayerSingle( summoned, GetOwningPlayer(caster) )
call UnitApplyTimedLifeBJ( 18, 'BTLF', summoned )
call SetHeroXP( summoned, GetHeroXP(caster), false )
loop
exitwhen i > j
call UnitAddItemByIdSwapped( GetItemTypeId(UnitItemInSlotBJ(caster, i)), summoned )
set i = i + 1
endloop
call DisplayTextToForce(GetPlayersAll(),"Items transferred.")
call TriggerRegisterUnitEvent(t,summoned,EVENT_UNIT_DEATH)
call TriggerAddAction(t,function SpiritCallEnd)
call SetHandleHandle(t, "caster",caster)
call SetHandleHandle(t, "summoned", summoned)
call PolledWait(18.)
call DisplayTextToForce(GetPlayersAll(),"Summoned has died (supposedly).")
call ShowUnit(summoned,false)
call SpiritCallEnd()
call RemoveUnit(summoned)
call FlushHandleLocals(t)
call DestroyTrigger(t)
set caster = null
call RemoveLocation(targetpt)
set summoned = null
call DisplayTextToForce(GetPlayersAll(),"Done.")
endfunction
//===========================================================================
function InitTrig_Spirit_Call takes nothing returns nothing
set gg_trg_Spirit_Call = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Spirit_Call, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Spirit_Call, Condition( function Trig_Spirit_Call_Conditions ) )
call TriggerAddAction( gg_trg_Spirit_Call, function Trig_Spirit_Call_Actions )
endfunction
Now, I have no idea why the event of the trigger t does not fire. I am using Handle Vars, am I doing something wrong there? Also, my code might not be very efficient or 100% leak free, so please correct me if you notice any such errors. Thanks.