1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] GetUnitArmorReduction

Discussion in 'Submissions' started by Ofel, Aug 14, 2018.

  1. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    443
    Resources:
    10
    Spells:
    10
    Resources:
    10
    Just like to share this, with the new functions.

    Returns armor reduction of a unit against an attack type.
    Code (vJASS):

    function GetUnitArmorReduction takes unit u, attacktype aType returns real
        local real originalArmor = BlzGetUnitArmor(u)
        local real originalMaxLife = BlzGetUnitMaxHP(u)
        local real originalLife = GetWidgetLife(u)
        local real testLife
     
        call BlzSetUnitArmor(u, 0)
        call BlzSetUnitMaxHP(u, 10000)
        call SetWidgetLife(u, 10000.)
        call UnitDamageTarget(u, u, 100., false, false, aType, DAMAGE_TYPE_UNKNOWN, null)
        set testLife = GetWidgetLife(u)
     
        call BlzSetUnitArmor(u, originalArmor)
        call BlzSetUnitMaxHP(u, R2I(originalMaxLife))
        call SetWidgetLife(u, originalLife)
     
        return (10000. - testLife) / 100.
    endfunction
     
     
    Last edited: Aug 14, 2018
  2. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,684
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Won't the unit die if it has less than 100hp?
     
  3. Jampion

    Jampion

    JASS Reviewer

    Joined:
    Mar 25, 2016
    Messages:
    1,287
    Resources:
    0
    Resources:
    0
    The unit's hp is set to 10000 before the unit is damaged, so it won't die unless the attack type deals insanely high damage to the unit.

    Why did you set the units armor to 1 instead of 0? I think one is more interested in just the damage modificaton from attack/armor type, since damage reduction from armor points can be easily calculated.
     
  4. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,684
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Right, I didn't notice the
    BlzSetUnitMaxHP
     
  5. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    443
    Resources:
    10
    Spells:
    10
    Resources:
    10
    I don't know, I just thought that 0 will not cause the unit to have the specified armor reduction.

    Updated.
     
  6. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    400
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    I also thought so, but haven't tried.

    Won't
    call UnitDamageTarget(u, u,100., false, false, aType, DAMAGE_TYPE_UNKNOWN, null)

    run damage event handlers? If so, it might further modify the damage aside from reducing it due to armor. Also, what about mana shield and the like?

    Btw, side question, what does the attack boolean parameter of UnitDamageTarget does? I honestly don't know.
     
  7. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    443
    Resources:
    10
    Spells:
    10
    Resources:
    10
    I wasn't aware of this.
    It seems damage event handlers must coop not to modify the damage for this one. :confused:
    I don't have a solution yet. Maybe I should submit this to the Lab?
    I tried using mana shield, and the mana shield reduces the damage according to the unit's mana (the unit's mana reduces too). :/
    Idk either. It doesn't show any difference when you use it or not.
     
  8. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,684
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    I think this might also fire the unit state events.

    TriggerRegisterUnitStateEvent
     
  9. Jampion

    Jampion

    JASS Reviewer

    Joined:
    Mar 25, 2016
    Messages:
    1,287
    Resources:
    0
    Resources:
    0
    Spirit Link would be an issue as well. The damage will be reduced and other linked units will take damage.

    I think it affects certain abilities like for example Spiked Carapace or Thorns Aura. Better to turn it off in most cases, else the damage dealer might take a lot of damage due to these abilities.
     
  10. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    7,747
    Resources:
    28
    Packs:
    1
    Maps:
    8
    Spells:
    17
    Tutorials:
    2
    Resources:
    28
    Might want to look to GetUnitArmor by gorillabull. I remember implementing it somewhere and has a pretty good precision.
     
  11. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    443
    Resources:
    10
    Spells:
    10
    Resources:
    10
    I see, I might consider posting this to the Lab and experimenting more later.

    Unofficially Need Fix xD
    I think it uses more slower process, since WE now has the new 'set unit armor' function, this function make the process more straightforward.
    But the flaws are still the same like mine I guess.
     
    Last edited: Aug 16, 2018
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,081
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    If the user has GUI Damage Engine, you could fit that into this script.

    You have to phase the calculation. What if a damage type would amplify the damage beyond the unit's new max HP?

    1. Apply 0 armor
    2. Damage the unit
    3. use DamageEventAmount to see how much the unit will take
    4. Set DamageEventAmount to 0 and set DamageEventOverride to true
    5. Set the armor back to normal

    Technically, another system could be used to calculate the armor reduction so you don't need to mess with that either.
     
  13. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    7,747
    Resources:
    28
    Packs:
    1
    Maps:
    8
    Spells:
    17
    Tutorials:
    2
    Resources:
    28
    Not sure about Gorillabull's version, but I recall it workd properly and was approved at Map Section if memory preserves. Never tried it with Spirit Link tho.