I created a shield system that works fine except the part of 1 hit kill. I have a problem to prevent 1 hit kill. Is there a way to prevent it. Lets say a unit with 300 max hp has 150 hp left. How do I make it so it have 150 hp left being hit?
Is there a way of doing this only in triggers? Or do I have to add something?
JASS:
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 = GetUnitState(target,UNIT_STATE_LIFE)
local real MaxLife = GetUnitState(target,UNIT_STATE_MAX_LIFE)
local integer shieldvalue = GetCustomIntValue(target)
local real shieldvaluereal = I2R(GetCustomIntValue(target))
call DestroyTimer(t)
//Set to 3 - prevents unecesary calls
if Damage > 3 then
if UnitHasBuffBJ(target, 'B000') == true then
if CurrentLife-Damage < MaxLife then
if shieldvaluereal > Damage then
call SetUnitState(target, UNIT_STATE_LIFE, CurrentLife+Damage)
set shieldvaluereal = shieldvaluereal - Damage
set shieldvalue = R2I(shieldvaluereal)
call SetCustomIntValue(target, shieldvalue)
else
call SetUnitState(target, UNIT_STATE_LIFE, CurrentLife+shieldvaluereal)
call SetCustomIntValue(target, 0)
set shieldvaluereal = 0.00
call UnitRemoveBuffBJ( 'B000', target )
call GroupRemoveUnitSimple(target, udg_ShieldGroup)
endif
else
endif
else
endif
else
endif
call FlushChildHashtable(udg_hashdamage, GetHandleId(t))
set target = null
return false
endfunction
//This timer is for allowing full hp units able to block damage
function Trig_Damage_Detection_Conditions 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 timer t = CreateTimer()
call SaveReal(udg_hashdamage, GetHandleId(t), 1, DamageMemory)
call SaveUnitHandle(udg_hashdamage, GetHandleId(t), 2, tu)
if CurrentLifeMem > DamageMemory then
call TimerStart(t, 0.01, false, function Damage_Block)
else
call TimerStart(t, 0.00, false, function Damage_Block)
endif
set tu = null
return false
endfunction
//===========================================================================
function InitTrig_Damage_Detection takes nothing returns nothing
set gg_trg_Damage_Detection = CreateTrigger( )
call DisableTrigger( gg_trg_Damage_Detection )
call TriggerAddCondition( gg_trg_Damage_Detection, Condition( function Trig_Damage_Detection_Conditions ) )
endfunction