• 🏆 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!

[JASS] Dealing completly fixed damage

Status
Not open for further replies.
Level 14
Joined
Dec 12, 2012
Messages
1,007
Hello all,

I was woundering if there is a way to deal a certain amount of damage to a unit with completly ignoring its armortypes/resistances/customized damage table/everything.

Of course it could be done with
JASS:
call SetUnitState(target,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE) - amount)

BUT if the unit dies, the damager wont get any xp (as there is no damager).

Is there a way?

Greetings,
lfh
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
JASS:
//let u be a global unit with an unknown quantity of hp
//let attacker be a global unit who must deal exactly fixed r damage to u.
//let bigD be a global real whose value is significantly larger than r

scope example initializer i
    private function i takes nothing returns nothing
        local real hp=GetUnitState(u,UNIT_STATE_LIFE)
        if hp>r then
            call SetUnitState(u,hp-r)
        else
            call UnitDamageTarget(attacker,u,bigD,null,DAMAGE_TYPE_UNIVERSAL,null)
        endif
    endfunction
endscope

make sense?
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
JASS:
make sense?[/QUOTE]

Yes, but what if I customized the damage table in that way that I set damage from Spells to zero for a certain armor type? Then even the biggest damage amount won't help.

Of course I could use all different damagetypes in a row but then a damageevent will be fired everytime the unit is immune to the corresponding attack. Even worse, the amount of damage is returned as 1 although it is zero (unit doesn't get damaged). Therefore one can't filter it out by checking for zero damage.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
Perhaps the solution lies in choosing an attack type as you discovered here?

Lol, I totally forgot about this :facepalm:

This works now allways, even if you set the whole damage table to zero:

JASS:
function DealFixDamage takes unit source, unit target, real amount returns nothing

    local real UNIT_MIN_LIFE = 0.406
    local attacktype ATTACK_TYPE_UNIVERSAL = ConvertAttackType(7)

    local real beforeHitpoints = GetUnitState(target,UNIT_STATE_LIFE)
    local real newHitpoints = beforeHitpoints - amount

    // This is used to have access to the damage amount in the DamageEvent
    set udg_fixDamage = amount

    if newHitpoints >= UNIT_MIN_LIFE then
        call SetUnitState(target,UNIT_STATE_LIFE,newHitpoints)
        call UnitDamageTarget( source, target, 0, true, false, ATTACK_TYPE_UNIVERSAL, DAMAGE_TYPE_UNIVERSAL, null)
    else
        call SetUnitInvulnerable( target, false )
        call UnitDamageTarget( source, target, 1000000000, true, false, ATTACK_TYPE_UNIVERSAL, DAMAGE_TYPE_UNIVERSAL, null)
    endif

    set ATTACK_TYPE_UNIVERSAL = null

endfunction

function Trig_DamageEvent_Actions takes nothing returns nothing
    set udg_damage = GetEventDamage()

    // Check if the damage was a fixed damage
    if udg_fixDamage != 0 then
        set udg_damage = udg_fixDamage
        set udg_fixDamage = 0
    endif

    // Display the correct amount of damage
    call BJDebugMsg("Damage: "+R2S(udg_damage))
        
endfunction

function test takes nothing returns nothing
    // Do 100 fixed damage
    call DealFixDamage( source, target, 100.00 )
endfunction

Cool, this really works great. Thanks!

lfh
 
Status
Not open for further replies.
Top