- Joined
- May 28, 2007
- Messages
- 365
Why is this trigger not working?
I'm trying to make a temp. AoE life drain. Everything works except the spell effects and lightning are being removed. Before you say "why did you call a function to cleanup, instead of doing it in the original function", it's because I already tried a TriggerSleepAction in the original function, and it didn't work.
I'm trying to make a temp. AoE life drain. Everything works except the spell effects and lightning are being removed. Before you say "why did you call a function to cleanup, instead of doing it in the original function", it's because I already tried a TriggerSleepAction in the original function, and it didn't work.
JASS:
function Trig_Life_Drain_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A007' ) ) then
return false
endif
return true
endfunction
function Cleanup takes effect e, effect et, lightning l, unit u returns nothing
call TriggerSleepAction(1)
call PauseUnit(u, false)
call DestroyEffect(e)
call DestroyEffect(et)
call DestroyLightning(l)
endfunction
function DrainLife takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit t = GetEnumUnit()
local location l = GetUnitLoc(u)
local location lt = GetUnitLoc(t)
local integer i = GetUnitAbilityLevel(u, 'A007')
local real life = GetUnitState(u, UNIT_STATE_LIFE) + ( (I2R(i)*20)+20 )
local real dam = I2R(i)*20+20
local lightning light = AddLightningEx("DRAL", true, GetLocationX(l), GetLocationY(l), 10, GetLocationX(lt), GetLocationY(lt), 10)
local effect e = AddSpecialEffectTarget("Abilities\\Spells\\Other\\Drain\\DrainTarget.mdl", t, "head")
local effect et = AddSpecialEffectTarget("Abilities\\Spells\\Other\\Drain\\DrainCaster.mdl", u, "head")
call PauseUnit(t, true)
call UnitDamageTarget(u, t, dam, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call SetUnitState(u, UNIT_STATE_LIFE, life)
call Cleanup(e, et, light, t)
endfunction
function CheckEnemyA takes nothing returns boolean
return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == TRUE )
endfunction
function CheckEnemyB takes nothing returns boolean
return ( ( GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 ) == TRUE )
endfunction
function CheckEnemy takes nothing returns boolean
return GetBooleanAnd(CheckEnemyA(), CheckEnemyB())
endfunction
function Trig_Life_Drain_Actions takes nothing returns nothing
local group g = GetUnitsInRangeOfLocMatching(400, GetUnitLoc(GetTriggerUnit()), Condition(function CheckEnemy))
call ForGroup(g, function DrainLife)
call DestroyGroup(g)
endfunction
//===========================================================================
function InitTrig_Life_Drain takes nothing returns nothing
set gg_trg_Life_Drain = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Life_Drain, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Life_Drain, Condition( function Trig_Life_Drain_Conditions ) )
call TriggerAddAction( gg_trg_Life_Drain, function Trig_Life_Drain_Actions )
endfunction