function DifferanceBetweenAngles takes real alpha, real beta returns real
if alpha > beta then
return alpha - beta
endif
return beta-alpha
endfunction
function Trig_Damage_Event_Conditions takes nothing returns boolean
return GetEventDamageSource() == GetHandleUnit(GetTriggeringTrigger(), "Attacker")
endfunction
function Trig_Damage_Event takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
call UnitDamageTarget(GetEventDamageSource(), GetTriggerUnit(), GetEventDamage()/2, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
call FlushHandleLocals(t)
call DestroyTrigger(t)
set t = null
endfunction
function Trig_Damage_Conditions takes nothing returns boolean
return DifferanceBetweenAngles(GetUnitFacing(GetAttacker()), GetUnitFacing(GetTriggerUnit())) < 45
endfunction
function Trig_Damage_Actions takes nothing returns nothing
local trigger t = CreateTrigger()
call SetHandleHandle(t, "Attacker", GetAttacker())
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
call TriggerAddCondition(t, Condition( function Trig_Damage_Event_Conditions))
call TriggerAddAction( t, function Trig_Damage_Event )
call TriggerSleepAction(1)
call FlushHandleLocals(t)
call DestroyTrigger(t)
set t = null
endfunction
//====================================================================
function InitTrig_Damage takes nothing returns nothing
set gg_trg_Damage = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Damage, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Damage , Condition( function Trig_Damage_Conditions))
call TriggerAddAction( gg_trg_Damage, function Trig_Damage_Actions )
endfunction