• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Detecting Total Attack damage

Status
Not open for further replies.
Level 3
Joined
Apr 26, 2008
Messages
26
How I can make Action to trigger what Ignores Total damage what enemy used against you?

I give example.

I got here Blademaster

And here i got Another Blademaster

Now they attack each other.

They both have damage as normal but i want this trigger action to ignore it

And also if someone can tell me how it detects enemy attack damage (total from bonuses etc)

I need these for many spells so i would be pleased if someone could help me :)

Ps: noes Jass pl0x
 
Level 9
Joined
Apr 3, 2008
Messages
700
1. To ignore damage add a skill to unit, stone armor (that one elf giant have), set 0 dmg reduce and 100% chance for it.

2. To detect damage just add to to trigger an event "unit takes damage".

Note: you won't be able to detect normal damage with this way if your unit will be immune to it.
 
Level 3
Joined
Apr 26, 2008
Messages
26
No i Want to make ability which absorbs damage. im bit newb so i make it ''easy'' way just need to make Enemys psychical damage to morph to Spell damage when unit got this From Anti magic shell made spell. So thats why i need to make it ignore all damage from attack and/or Detect it so I can make it to do same amount of damage as Magical damage. I mean like I can detect and make my unit to make like 100% of its agility as damage can I make it like 100% of damage? thats what im looknig for
 
Last edited:
Level 3
Joined
Apr 26, 2008
Messages
26
Could you give me example from it cause i didnt get it. Since only attributes wont give damage also items with damage bonus give it :S
 
Level 3
Joined
Aug 19, 2007
Messages
24
This function is actually somewhat complex. I'm going to use gamecache in my examples - I don't use it much, so forgive me if I screw up some of the function names. You should use something better than gamecache if you have it. Also, you shouldn't be using Create/Destroy timer - use something like CSSafety (it's a lot more reliable)

The reason it's not a simple trigger is due to the fact that the EVENT_UNIT_DAMAGED event fires immediately before the unit suffers damage - so if we give the unit a bunch of life then we might 'spill over' above the unit's maximum life. The solution to this is to create a zero-duration timer so that it will heal your unit immediately after suffering damage. Of course, we don't want the unit to die if it's at low life - so we have to heal as much as we can now, before the damage "goes through", and then heal the rest immediately afterwards.

JASS:
//gc is a global gamecache (localvars or something)
//H2I is handle2integer function

function DRSpell_Timer takes nothing returns nothing
    //Adds leftover HP to unit's life, clears data, and destroys timer
    local integer uid = GetStoredInteger(gc, "DRSpell", "t"+I2S(H2I(GetExpiredTimer())))
    local real x = GetStoredReal(gc, "DRSpell", I2S(uid))
    call SetUnitState(I2U(uid), UNIT_STATE_LIFE, GetUnitState(I2U(uid), UNIT_STATE_LIFE) + x)
    call FlushStoredInteger(gc, "DRSpell", "t"+I2S(H2I(GetExpiredTimer())))
    call FlushStoredReal(gc, "DRSpell", I2S(uid))
    call DestroyTimer(GetExpiredTimer())
endfunction

function DRSpell_Damaged takes nothing returns nothing
    //Action when unit is damaged
    local real x = GetEventDamage() + GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE)
    local timer t
    local integer uid

    
    //If there will be leftover hitpoints then we have to process the damage before we can negate all of it
    if x - GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE) > 0 then
        call SetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE, GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE))
        set uid = H2I(GetTriggerUnit())
        set x = x - GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE)
        //set x equal to the amount that will spill over maximum
        call StoreReal(gc, "DRSpell", I2S(uid), x)

        set t = CreateTimer()
        call StoreInteger(gc, "DRSpell", "t"+I2S(H2I(t)), uid)
        call TimerStart(t, 0., function DRSpell_Timer)
    else
        //If there won't be any leftover hitpoints then simply negate the damage
        call SetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE, x)
    endif

    set t = null
endfunction

function DRSpell_Damage_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'Basd') > 0 //'Basd' is the rawcode for the buff your ability uses - use whatever condition you need to use
endfunction

function DRSpell_Learn takes nothing returns nothing
    //Create a new trigger when your unit learns the ability - this is necessary since there is not an EVENT_PLAYER_UNIT_DAMAGED event
    local trigger tr = CreateTrigger()
    call TriggerRegisterUnitEvent(tr, EVENT_UNIT_DAMAGED, GetTriggerUnit())
    call TriggerAddAction(tr, function DRSpell_Damaged)
    call TriggerAddConditions(tr, Condition(function DRSpell_Damage_Conditions))
    set tr = null
endfunction

function InitTrig_DRSpell takes nothing returns nothing
    //Create trigger the "on learn" trigger - this must be called during initialization
    local trigger tr = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(tr, EVENT_HERO_SKILL, 'asdf') //'asdf' is the rawcode for your ability
    call TriggerAddAction(tr, function DRSpell_Learn)
    set tr = null
endfunction

I use something very similar to this. It works very well.
 
Level 3
Joined
Apr 26, 2008
Messages
26
I am sorry that you used alot of time on that but I asked non jass versio if its possible cause really i dont have ANY idea what that big mess on jass scrits is....

and no idea how i ever could make it work...
 
Status
Not open for further replies.
Top