• 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.

GetDamage

Status
Not open for further replies.
Level 18
Joined
Sep 14, 2012
Messages
3,413
Okay here is the code i'll explain what is this suppose to do after.
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 method .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
    
    //This detects only positive armor.
    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
        unit attacker
        unit attacked
        trigger t
        
        method destroy takes nothing returns nothing
            set this.attacker = null
            set this.attacked = null
            call DestroyTrigger(this.t)
            set this.t = null
            call this.deallocate()
        endmethod
        
        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 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
                set this = thistype.create()
                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
        
        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 t = null
        endmethod
    endstruct
endlibrary

Okay i finished this it supposes to store the attack damage of units (it is just the first prototype i know i can make it better). Yes i used Vexorian's table don't burn me xD !
I didn't test it and so on.
Tell me if there is something bad in this ^^

EDIT1 : Can now get positive armor.
EDIT2 : Negative too.
 
Last edited:
It could be viable--sort of. I think it would be a lot, lot better with databasing though. :) This method relies on the unit dealing damage, and that is reduced by armor, increased by stats, etc. etc. There are a lot of stuff that will change it around.

With databasing, you save the base attack damage by unit-types. Then you just factor in stats, bonuses, etc. and you can get the damage. :) The only problem is that the database method is map-specific. It might be feasible in wurstscript eventually though. ;D
 
Status
Not open for further replies.
Top