- Joined
- Feb 4, 2009
- Messages
- 1,314
How to block damage?
I tried:
additionally it won't work if the triggering unit has full hp (-> damage is dealt after unit is healt and I can't think of any way to heal the unit instantly after it took dmg)
adding invulnerability results in aggression loss of the attacker
and adding 99999 armor is too slow cause the damage is dealt before the ability takes effect
phase shift is too slow, too
edit:
it works if I do things like this
edit: it appears to work flawlessly
some guy told me that 0.00 sec expiration timers could screw up but I didn't notice anything like that either
thanks for the huge amount of responds
edit:
this code seems to work fine
took me a few hours to work this out
at first the code was three times as long until I began deleting stuff and moving functions around to see if it still works
I tried:
-
Block Damage
-
Events
-
Unit - Any unit Takes damage //with an add and ini trigger to add all the events
-
-
Conditions
-
Actions
-
Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + (Damage taken))
-
-
additionally it won't work if the triggering unit has full hp (-> damage is dealt after unit is healt and I can't think of any way to heal the unit instantly after it took dmg)
adding invulnerability results in aggression loss of the attacker
and adding 99999 armor is too slow cause the damage is dealt before the ability takes effect
phase shift is too slow, too
edit:
it works if I do things like this
-
Set a = (Damage taken)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Life of (Triggering unit)) Less than ((Max life of (Triggering unit)) - a)
-
-
Then - Actions
-
Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + a)
-
-
Else - Actions
-
Set u = (Triggering unit)
-
Countdown Timer - Start t as a One-shot timer that will expire in 0.00 seconds
-
-
-
Heal
-
Events
-
Time - t expires
-
-
Conditions
-
Actions
-
Unit - Set life of u to ((Life of u) + a)
-
-
edit: it appears to work flawlessly
some guy told me that 0.00 sec expiration timers could screw up but I didn't notice anything like that either
thanks for the huge amount of responds
edit:
JASS:
//==========(Remove bonus life and heal life)==========
function Dmg_Reset takes nothing returns nothing
call UnitRemoveAbility(udg_Dmg_Target, 'AIl2')//Remove hp bonus (+300 hp)
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life)//Heal again (if unit had full hp it couldn't be healed before)
set udg_Dmg_Taken = 0.00//Tell function below that actions were done already
endfunction
//==========(Actions on EVENT_UNIT_DAMAGED)==========
function DmgEvent_Actions takes nothing returns nothing
if udg_Dmg_Taken != 0.00 then//Apply actions above if not done yet; else timer will be overwritten and that's bad
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')//Add bonus life
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life+300.00)//Heal
call TimerStart(udg_Dmg_Timer, 0.00, false, function Dmg_Reset)//Start timer to do some actions after damage took place
endfunction
//==========(Register events and actions)==========
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
took me a few hours to work this out
at first the code was three times as long until I began deleting stuff and moving functions around to see if it still works
Last edited: