Warcraft III resources & community, 2003–2006 · archived

UnitBlockNormalDamage

not rated
Submitted by KaTTaNaFunctions0 downloads
Blocks all normal damage dealt to the given unit, until the duration expires.
If you want it to last forever, set duration to 0 or less.

Note, that by "normal" I mean damage dealt by units and spells, it has nothing to do with damage types (eg. Normal/Piercing/Siege/etc.).
Triggers can still reduce the life of the unit.

This might not save the unit from dying if the attack deals more damage than the unit's maximum hitpoints.

Source

function UnitBlockNormalDamage_Child2 takes nothing returns nothing
    local real dmg = GetEventDamage()
    local unit u = GetTriggerUnit()
    local real life = GetUnitState(u, UNIT_STATE_LIFE)
    local real delta
    if ( life+dmg > GetUnitState(u, UNIT_STATE_MAX_LIFE) ) then
        set delta = GetUnitState(u, UNIT_STATE_LIFE)+dmg-GetUnitState(u, UNIT_STATE_MAX_LIFE)
        call SetUnitState(u ,UNIT_STATE_LIFE, life+dmg )
        call TriggerSleepAction(0)
        call SetUnitState(u ,UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + delta )
    else
        call SetUnitState(u ,UNIT_STATE_LIFE, life+dmg )
    endif
endfunction
function UnitBlockNormalDamage_Child1 takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerRegisterUnitEvent(trg, bj_makeUnitRescuableUnit, EVENT_UNIT_DAMAGED)
    call TriggerAddAction(trg, function UnitBlockNormalDamage_Child2)
    if ( bj_enumDestructableRadius > 0 ) then
        call TriggerSleepAction(bj_enumDestructableRadius)
        call DestroyTrigger(trg)
    endif
endfunction
function UnitBlockNormalDamage takes unit u, real duration returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function UnitBlockNormalDamage_Child1)
    set bj_makeUnitRescuableUnit = u
    set bj_enumDestructableRadius = duration
    call TriggerExecute(trg)
    call DestroyTrigger(trg)
endfunction

Comments

3
Hmm, would it not be faster if you created the event inside of the first function?[/code][/jass]
You could call the function like this:

local unit caster=GetTriggerUnit()
local unit target=GetSpellTargetUnit()
local integer s=GetSpellAbilityId()
local integer level=GetUnitAbilityLevel(caster,s)
local real duration=I2R(level*5)+15[change these values]
call UnitBlockNormalDamage(target,duration)
set caster=null
set target=null
set ...=null
...

Hope I could help you. :wink:

BertTheJasser
:? This looks like it could make a good skill(Divine Shield,but you can still get hit), but i need some help. So this is so for what i got...
Event: A spell is cast
Conditions: Spell is equal to Block Damage
Actions:
Call: ???(i know i need to do this, but how)

{Also how do i make it so it changes the duration by the level of the abillity for triggering unit.)

Thx Bert..., i got it to work...(I hope)[Goes to church to pray for it to work(lol)]