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

[Trigger] Detect Defense

Status
Not open for further replies.
Level 5
Joined
Apr 29, 2015
Messages
143
Detect Armor Value

Well, anyone know a way to find unit's armor value or some trigger code that detects unit armor?

I would really need it for triggering unit's armor with Hardened Skin levels and would appreciate a help.

If someone know a proper system that uses "Hardened Skin" for defense mechanism then I would really appreciate that ALOT if anyone knows the trigger code for it.
 
Last edited:
Level 12
Joined
Jan 2, 2016
Messages
973
I know a way how to detect unit's armor.
JASS:
function GetUnitArmor takes unit u returns real
    local unit dummy = CreateUnit( bj_PLAYER_NEUTRAL_EXTRA, 'dumy', GetUnitX(u), GetUnitY(u), 0.00)
// 'dumy' is your dummy's ID
    local real health = GetWidgetLife(u)
    local real max_hp = GetUnitState( u , UNIT_STATE_MAX_LIFE )
    local real armor_rating
    call SetWidgetLife( u , max_hp )
    call UnitDamageTarget( dummy, u, max_hp/2, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    set armor_rating = (max_hp/2)/(max_hp - GetWidgetLife(u))
    call SetWidgetLife( u , health )
    call RemoveUnit(dummy)
    set dummy = null
    set u = null
    return (armor_rating - 1)/0.06  //The 0.06 is a number you get from the gameplay constants.
endfunction

You could have a constant dummy, which isn't getting removed, and just make IT deal the damage, instead of creating it every time, and then removing it :p
It'd make things easier.

You could also add some ability to the unit, which is adding a lot of HP (30 000 for example), and then just deal constant damage (15 000 for example).
Then the armor_rating formula would look like set armor_rating = 15000/(max_hp - GetWidgetLife(u))
just don't forget to remove the bonus HP ability after.
And few more notes (about this way): you need to get unit's life before it gets the ability, and set max_hp to unit's max hp after giving it the ability in order to avoid bugs :p
The point of the 15000 damage way is that higher damage amounts give a better reading of the unit's armor, thus they are more accurate.
 
Last edited:
Level 5
Joined
Apr 29, 2015
Messages
143
That may be useful but it seems more than I needed, all I need is a defense value detection to set unit's Hardened Skin ability as their defense, while in game constants... Armor damage reduction is already set to 0, just in case.

So do you possibly know that? =o
I appreciate that though. =)
 
Level 12
Joined
Jan 2, 2016
Messages
973
Well, as you may have guessed, if the armor reduction in the gameplay constants is alreayd set to 0, then the method I told you wouldn't work.

The only other possible way is to make a hashtable, containing the armor values of all the units you are going to use on your map.
And load the value from the hashtable.

However - this wouldn't work with armor bonuses from items, auras, etc..
 
Level 5
Joined
Apr 29, 2015
Messages
143
There is no stat called "defense" in wc3.
Do you mean armor, or the damage reduction caused by Hardened skin, or something third?

Yeah, that's whats I mean about the "defense".
And I mean "Hardened Skin" level based on the armor value.

Like if armor is 3, it will reduce the damage by 3 on every hit.

Well, as you may have guessed, if the armor reduction in the gameplay constants is alreayd set to 0, then the method I told you wouldn't work.


The only other possible way is to make a hashtable, containing the armor values of all the units you are going to use on your map.
And load the value from the hashtable.

However - this wouldn't work with armor bonuses from items, auras, etc..

Oh, then that will not do since my map will definitely have item, ability and unit upgrades. :(
 
Level 12
Joined
Jan 2, 2016
Messages
973
Well, another way to do what you want would be to trigger the whole Armor calculation yourself:
Give this Hardened skin ability to all the units, and set its level to their armor amount manually (by looking at their base armor)
When you finish an upgrade, that gives armor - increase the level of their hardened skin by the amount of armor they have gotten.

When a hero acuires an item, that gives armor - set the level of his hardened skin to its current level + the bonus armor from the item.

But meh... this will cost way too much effort xP

The easiest way would be if you are using a DDS, that can alter the damage units take, then perhaps you could make a system, that does what you want, but all the damage dealt will be triggered :p

EDIT: Actually I think I will make this system for you, as I already have some experiance with similar systems :)

EDIT 2: You need to wait until Bribe answers me, cuz I'm using his DDS as base for my system, and something bugs out, and it's not because of my code :p
 
Last edited:
Level 12
Joined
Jan 2, 2016
Messages
973
Okay, Bribe didn't answer, but I thought of a way how to fix it myself...
There ya go :)
JASS:
scope ArmorAltering

    globals
        constant integer HEALTH_BONUS = 'A001'
        constant real TEST_DAMAGE = 50000.00
        constant real ARMOR_COEFICIENT = 0.06
    endglobals

    private struct DamageAndArmor
        real damage
        real armor
        
        static method create takes unit u, real init_dam returns DamageAndArmor
            local DamageAndArmor DnA = DamageAndArmor.allocate()
            local real health = GetWidgetLife(u)
            local real max_hp
            local real armor_rating
            call UnitAddAbility(u, HEALTH_BONUS)
            set max_hp = GetUnitState(u, UNIT_STATE_MAX_LIFE)
            call SetWidgetLife(u, max_hp)
            call DisableTrigger(udg_DamageEventTrigger)
            call UnitDamageTarget( udg_DamageEventSource, u, TEST_DAMAGE, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
            call EnableTrigger(udg_DamageEventTrigger)
            set armor_rating = TEST_DAMAGE/(max_hp - GetWidgetLife(u))
            set DnA.damage = init_dam*armor_rating
            set DnA.armor = (armor_rating-1)/ARMOR_COEFICIENT
            call SetWidgetLife( u , max_hp )
            call UnitRemoveAbility( u , HEALTH_BONUS )
            call SetWidgetLife( u , health )
            return DnA
        endmethod
    endstruct

    private function Armor_altering takes nothing returns boolean
        local DamageAndArmor Base = DamageAndArmor.create(udg_DamageEventTarget, udg_DamageEventAmount)
        debug call BJDebugMsg("armor = "+R2S(Base.armor)+", base damage = "+R2S(Base.damage))
        set udg_DamageEventAmount = Base.damage - Base.armor
        set udg_DamageEventType = udg_DamageTypeReduced
        call DamageAndArmor.destroy(Base)
        return false
    endfunction

//===========================================================================
    function InitTrig_Armor_altering takes nothing returns nothing
        set gg_trg_Armor_altering = CreateTrigger(  )
        call TriggerRegisterVariableEvent( gg_trg_Armor_altering, "udg_DamageModifierEvent", EQUAL, 1.00 )
        call TriggerAddCondition( gg_trg_Armor_altering, Condition(function Armor_altering) )
    endfunction
    
endscope
 
Level 12
Joined
Jan 2, 2016
Messages
973
Just beware, cuz this is "version 1", and it may have some bugs :p
I'm not sure if it wouldn't be changing spell damage too xP
I haven't really used Bribe's damage engine before =/

EDIT: Okay, I updated it..
You can check the last link in my signature :p
 
Last edited:
Level 5
Joined
Apr 29, 2015
Messages
143
Oh ok, I'll have to look closely with the problem though.

And wow, will definitely have to follow your resource, thanks for submitting that. :D
 
Status
Not open for further replies.
Top