function Damage_Block takes nothing returns boolean
local timer t = GetExpiredTimer()
local real Damage = LoadReal(udg_hashdamage, GetHandleId(t), 1)
local unit target = LoadUnitHandle(udg_hashdamage, GetHandleId(t), 2)
local real CurrentLife = LoadReal(udg_hashdamage, GetHandleId(t), 3)
local real MaxLife = GetUnitState(target,UNIT_STATE_MAX_LIFE)
local integer shieldvalue = GetCustomIntValue(target)
local real shieldvaluereal = I2R(GetCustomIntValue(target))
local timer t2 = CreateTimer()
call DestroyTimer(t) //Warning: Only destroy non-periodic timers without pausing them beforehead
//Adds same hp same as the negative value to null out hp adjust
if LoadBoolean(udg_hashdamage, GetHandleId(t), 4) == true then
call UnitAddAbility(target, 'A001')
call SetUnitAbilityLevel(target, 'A001', 3 )
call UnitRemoveAbility(target, 'A001')
if Damage < 3 then
call SetUnitState(target, UNIT_STATE_LIFE, CurrentLife)
else
endif
else
endif
//Set to 3 - prevents unecesary calls
if Damage > 3 then
//ShieldBlock : 'B000 is the buff ID in test map, you have to replace this with the abilities buff code in your own map'
if UnitHasBuffBJ(target, 'B000') == true then
if shieldvaluereal > Damage then
call SetUnitState(target, UNIT_STATE_LIFE, CurrentLife)
set shieldvaluereal = shieldvaluereal - Damage
set shieldvalue = R2I(shieldvaluereal)
call SetCustomIntValue(target, shieldvalue)
else
call SetUnitState(target, UNIT_STATE_LIFE, CurrentLife+shieldvaluereal-Damage)
call SetCustomIntValue(target, 0)
set shieldvaluereal = 0.00
call UnitRemoveBuffBJ( 'B000', target )
call GroupRemoveUnit(udg_OakShieldGroup,target)
endif
else
endif
else
endif
call FlushChildHashtable(udg_hashdamage, GetHandleId(t)) //remove the entrys from the hash
set target = null
return false
endfunction
//This timer is important, otherwise full hp units will be taken damage
function Trig_Damage_Detection_Conditions_Copy takes nothing returns boolean
local unit tu = GetTriggerUnit()
local real DamageMemory = GetEventDamage()
local real CurrentLifeMem = GetUnitState(tu,UNIT_STATE_LIFE)
local real MaxLifeMem = GetUnitState(tu,UNIT_STATE_MAX_LIFE)
local real shieldvaluerealmem = I2R(GetCustomIntValue(tu))
local timer t = CreateTimer()
call SaveReal(udg_hashdamage, GetHandleId(t), 1, DamageMemory)
call SaveUnitHandle(udg_hashdamage, GetHandleId(t), 2, tu)
call SaveReal(udg_hashdamage, GetHandleId(t), 3, CurrentLifeMem)
if UnitHasBuffBJ(tu, 'B000') == true then
if DamageMemory > CurrentLifeMem then
call SaveBoolean(udg_hashdamage, GetHandleId(t), 4, true)
call UnitAddAbility(tu, 'A001')
//negative hp first, somehow I had to do this first for some odd reason
call SetUnitAbilityLevel( tu, 'A001', 2 )
call UnitRemoveAbility(tu, 'A001')
else
endif
call TimerStart(t, 0.00, false, function Damage_Block)
else
call FlushChildHashtable(udg_hashdamage, GetHandleId(t))
set t = null
endif
set tu = null
return false
endfunction
//===========================================================================
function InitTrig_Damage_Detection_Copy takes nothing returns nothing
set gg_trg_Damage_Detection_Copy = CreateTrigger( )
call DisableTrigger( gg_trg_Damage_Detection_Copy )
call TriggerAddCondition( gg_trg_Damage_Detection_Copy, Condition( function Trig_Damage_Detection_Conditions_Copy ) )
endfunction