I try to make a Divine Shield which absorb all damage taken on target unit, but target still takes damage from the first damage that inflicted it. I don't know what part in my code is bugged.
Thanks for your help
Thanks for your help
Code:
function Divine_Shield_Con takes nothing returns boolean
return GetSpellAbilityId() == 'A00R'
endfunction
function Divine_Shield takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local unit c = GetTriggerUnit()
local real dmg = GetEventDamage()
function Divine_Shield takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local unit c = GetTriggerUnit()
local real dmg = GetEventDamage()
if UnitHasBuffBJ(c, 'BHds') == false then
call DisableTrigger(t)
call DestroyTrigger(t)
elseif dmg > 0 then
call SetUnitState(c, UNIT_STATE_LIFE, GetUnitState(c, UNIT_STATE_LIFE) + dmg)
endif
endfunction
endfunction
function Divine_Shield_Act takes nothing returns nothing
local trigger t
local unit c = GetSpellTargetUnit()
call UnitRemoveBuffs(c, false, true)
if UnitHasBuffBJ(c, 'BHds') == false then [COLOR="#008000"]//======= Prevent Trigger Overlaps[/COLOR]
set t = CreateTrigger()
call TriggerRegisterUnitEvent( t, c, EVENT_UNIT_DAMAGED )
call TriggerAddAction( t, function Divine_Shield )
endif
endfunction
//===========================================================================
function InitTrig_Divine_Shield takes nothing returns nothing
set gg_trg_Divine_Shield = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Divine_Shield, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Divine_Shield, Condition( function Divine_Shield_Con ) )
call TriggerAddAction( gg_trg_Divine_Shield, function Divine_Shield_Act )
endfunction