• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Block Damage

Status
Not open for further replies.
Level 19
Joined
Feb 4, 2009
Messages
1,313
How to block damage?

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))
however this only heals the target and things like rejuvation will be stopped
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)
new question: is there a chance that u and a will be overwritten by something else before the timer expires?

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 :D

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
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 o_O
 
Last edited:
How to block damage?

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))
however this only heals the target and things like rejuvation will be stopped
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)
new question: is there a chance that u and a will be overwritten by something else before the timer expires?

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 :D

but why do you need a timer that expires after 0.00 seconds? I think its okay if you put that set life into the first trigger..this wont be able to block damage if you have full hp right? btw there another way to do this if you would like to know and it can save units with full hp from getting damaged.....

create an item based on potion of divinity set its duration to .01 then make sure that "Automatically Used when acquired" is on in the object data then just add it to the unit...
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
but why do you need a timer that expires after 0.00 seconds? I think its okay if you put that set life into the first trigger..this wont be able to block damage if you have full hp right?

right
therefore the timer

btw there another way to do this if you would like to know and it can save units with full hp from getting damaged.....

create an item based on potion of divinity set its duration to .01 then make sure that "Automatically Used when acquired" is on in the object data then just add it to the unit...

invulnerability would cause the attacker to change the target and he isn't supposed to do that (at least that happened as I tried to trigger 0.01 sec of invulnerability)

however it seems to work fine now
thanks anyway
 
right
therefore the timer



invulnerability would cause the attacker to change the target and he isn't supposed to do that (at least that happened as I tried to trigger 0.01 sec of invulnerability)

however it seems to work fine now
thanks anyway

okay... but I cannot understand what use a timer of 0.00 seconds has.. sorry..
 
Level 24
Joined
Feb 9, 2009
Messages
1,787
the trolls in Orc's race have beserk ability set the damage increase to i believe either -0.01 or -1.00 but i know it blocks spell damage.

D4rk if you want a trigger i have triggered shield spell that does exactly what you were trying to do, if you want to try it give me a pm

also Adiktuz he put the wait beacause the set life trigger activates before the damage is subtracted
so if your unit has 100 hp as its current health and maximum and the unit with this trigger is damaged he will not keep 100, so if the damage is 10 the unit will go down to 90 until the trigger is stopped other than that if the unit's health is under the integer of damage then the target is basically invincible.
 
Status
Not open for further replies.
Top