• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[General] Flat Bonus for Armor

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
No it is not directly possible. You can indirectly do it by making armor increase toughness by 0% (no difference) and the triggering/using hardened skin to do the damage reduction but this is far from an easy task to do, especially if you want it to scale/change in response to certain things.

For this reason I would recommend using StarCraft II as this mechanic is supported by default (WC3 armor can be emulated with an appropriate armor formula defined for the unit type).
 
JASS:
library GetDamage requires Table
    globals
        private HandleTable tab
        private HandleTable damage
        //Set this to true if you want this system to get the attack damage of every unit of your map.
        //But be aware that this may lag.
        //If you let this to false then you will have to use the function Add(unit) to add a unit to this system.
        private constant boolean ALL_UNITS = false
        private constant integer DUMMY_ID = 'd000'
        private constant real ARMOR_CONSTANT = 0.06
    endglobals
    
    static if not ALL_UNITS then
        globals
            private group UNITS = CreateGroup()
        endglobals

        public function Add takes unit u returns nothing
            call GroupAddUnit( UNITS, u )
        endfunction
    endif
    
    public function GetDamage takes unit u returns integer
        return damage[u]
    endfunction
    
    public function GetArmor takes unit u returns real
        local real life = GetWidgetLife( u )
        local real life2
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local unit v = CreateUnit( Player(15), DUMMY_ID, x, y, 0 )
        local real test = 10
        if GetWidgetLife(u) > 200 then
            set test = 100
        endif
        call UnitDamageTarget( v, u, test, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null )
        set life2 = life - GetWidgetLife( u )
        call RemoveUnit( v )
        set v = null
        call SetWidgetLife( u, GetWidgetLife( u ) + life2 )
        if ( life2 > test ) then
            return (-1*(test - life2 ) ) / ( life2 * ARMOR_CONSTANT ) 
        else
            return ( test - life2 ) / ( life2 * ARMOR_CONSTANT )
        endif
    endfunction
    
    private struct Damage extends array
        unit attacker
        unit attacked
        trigger t
        thistype recycle
        static integer instanceCount
        static thistype recycleNext
        
        static method cond2 takes nothing returns boolean
            local thistype this
            if tab[GetEventDamageSource()] != 0 then
                set this = tab[GetEventDamageSource()]
                set damage[this.attacker] = R2I(GetEventDamage())
                call tab.flush(this.attacker)
                call DestroyTrigger(this.t)
                set this.attacker = null
                set this.attacked = null
                set this.t = null
                call this.destroy()
            endif
            return false
        endmethod
        
        static method cond takes nothing returns boolean
            local thistype this
            local boolean b = true
            static if not ALL_UNITS then
                if not IsUnitInGroup(GetAttacker(), UNITS) then
                    set b = false
                endif
            endif
            if b then
                if recycle == 0 then
                    set instanceCount = instanceCount + 1
                    set this = instanceCount
                else
                    set this = recycle
                    set recycle = recycle.recycleNext
                endif
                set this.attacker = GetAttacker()
                set this.attacked = GetTriggerUnit()
                set this.t = CreateTrigger()
                set tab[this.attacked] = this
                call TriggerRegisterUnitEvent( this.t, this.attacked, EVENT_UNIT_DAMAGED )
                call TriggerAddCondition( this.t, Condition( function thistype.cond2 ) )
            endif
            return false
        endmethod
        
        method destroy takes nothing returns nothing
            set recycleNext = recycle
            set recycle = this
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
            call TriggerAddCondition( t, Condition(function thistype.cond) )
            set tab = HandleTable.create()
            set damage = HandleTable.create()
            set instanceCount = 0
            set recycleNext = 0
            set t = null
        endmethod
    endstruct
endlibrary

Get Armor/Damage Library might work, credits to Malhorne.
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
JASS:
library GetDamage requires Table
    globals
        private HandleTable tab
        private HandleTable damage
        //Set this to true if you want this system to get the attack damage of every unit of your map.
        //But be aware that this may lag.
        //If you let this to false then you will have to use the function Add(unit) to add a unit to this system.
        private constant boolean ALL_UNITS = false
        private constant integer DUMMY_ID = 'd000'
        private constant real ARMOR_CONSTANT = 0.06
    endglobals
    
    static if not ALL_UNITS then
        globals
            private group UNITS = CreateGroup()
        endglobals

        public function Add takes unit u returns nothing
            call GroupAddUnit( UNITS, u )
        endfunction
    endif
    
    public function GetDamage takes unit u returns integer
        return damage[u]
    endfunction
    
    public function GetArmor takes unit u returns real
        local real life = GetWidgetLife( u )
        local real life2
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        local unit v = CreateUnit( Player(15), DUMMY_ID, x, y, 0 )
        local real test = 10
        if GetWidgetLife(u) > 200 then
            set test = 100
        endif
        call UnitDamageTarget( v, u, test, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null )
        set life2 = life - GetWidgetLife( u )
        call RemoveUnit( v )
        set v = null
        call SetWidgetLife( u, GetWidgetLife( u ) + life2 )
        if ( life2 > test ) then
            return (-1*(test - life2 ) ) / ( life2 * ARMOR_CONSTANT ) 
        else
            return ( test - life2 ) / ( life2 * ARMOR_CONSTANT )
        endif
    endfunction
    
    private struct Damage extends array
        unit attacker
        unit attacked
        trigger t
        thistype recycle
        static integer instanceCount
        static thistype recycleNext
        
        static method cond2 takes nothing returns boolean
            local thistype this
            if tab[GetEventDamageSource()] != 0 then
                set this = tab[GetEventDamageSource()]
                set damage[this.attacker] = R2I(GetEventDamage())
                call tab.flush(this.attacker)
                call DestroyTrigger(this.t)
                set this.attacker = null
                set this.attacked = null
                set this.t = null
                call this.destroy()
            endif
            return false
        endmethod
        
        static method cond takes nothing returns boolean
            local thistype this
            local boolean b = true
            static if not ALL_UNITS then
                if not IsUnitInGroup(GetAttacker(), UNITS) then
                    set b = false
                endif
            endif
            if b then
                if recycle == 0 then
                    set instanceCount = instanceCount + 1
                    set this = instanceCount
                else
                    set this = recycle
                    set recycle = recycle.recycleNext
                endif
                set this.attacker = GetAttacker()
                set this.attacked = GetTriggerUnit()
                set this.t = CreateTrigger()
                set tab[this.attacked] = this
                call TriggerRegisterUnitEvent( this.t, this.attacked, EVENT_UNIT_DAMAGED )
                call TriggerAddCondition( this.t, Condition( function thistype.cond2 ) )
            endif
            return false
        endmethod
        
        method destroy takes nothing returns nothing
            set recycleNext = recycle
            set recycle = this
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
            call TriggerAddCondition( t, Condition(function thistype.cond) )
            set tab = HandleTable.create()
            set damage = HandleTable.create()
            set instanceCount = 0
            set recycleNext = 0
            set t = null
        endmethod
    endstruct
endlibrary

Get Armor/Damage Library might work, credits to Malhorne.

I'm jass retarded. But I just realized I have a DDS, is there any way to detect armor through a DDS and negate it and apply the deduction through triggers, i.e.

Damage ignores armor, or armor % is calculated and negated, then armor amount is detected ex, 2 armor, and that value is deducted from the damage...?
 
Status
Not open for further replies.
Top