function Dmg_Reset takes nothing returns nothing
call UnitRemoveAbility(udg_Dmg_Target, 'AIl2')//+300 Hp Greater Life Bonus
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life)
set udg_Dmg_Taken = 0.00//Set Dmg Taken to 0 so the trigger knows that unit got healed already
endfunction
function DmgEvent_Actions takes nothing returns nothing
if udg_Dmg_Taken != 0.00 then//If timer did not run yet the unit will be healed
call UnitRemoveAbility(udg_Dmg_Target, 'AIl2')
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life)
endif
set udg_Dmg_Target = GetTriggerUnit()
set udg_Dmg_Source = GetEventDamageSource()
set udg_Dmg_Taken = GetEventDamage()
set udg_Dmg_Life = GetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE)
call UnitAddAbility(udg_Dmg_Target, 'AIl2')
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life+300.00)
call TimerStart(udg_Dmg_Timer, 0.00, false, function Dmg_Reset)//Start timer to heal
endfunction
//Might be even better with a condition to check if the timer and ability is really necessary
//And there might be a bug but I didn't test yet:
//1. Unit is healed before timer is over
//2. Unit takes damage again
//3. Unit is healed again
//If this is possible to happen it would only matter for x times damage absorption and could be prevented with another if anyway
//However the advantage of all this stuff is that one does not need a hashtable to check things
//Create events (only leaks once per unit, if you got enough units to notice the leak you got bigger problems)
function AddEnter_Actions takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_DmgEvent, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
endfunction
function DmgEvent_Add takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_DmgEvent, GetEnumUnit(), EVENT_UNIT_DAMAGED)
endfunction
function InitTrig_DmgEvent takes nothing returns nothing
local trigger AddEnter = CreateTrigger()
set gg_trg_DmgEvent = CreateTrigger()
call TriggerAddAction(AddEnter, function AddEnter_Actions)
call TriggerAddAction(gg_trg_DmgEvent, function DmgEvent_Actions)
call TriggerRegisterEnterRectSimple(AddEnter, bj_mapInitialPlayableArea)
call GroupEnumUnitsInRect(udg_g, bj_mapInitialPlayableArea, null)
call ForGroup(udg_g, function DmgEvent_Add)
endfunction