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

Get Unit Damage

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
GetUnitDamage
by: BloodForBlood

vJASS:
library GetUnitDamage
/*-------------------------------------------------------------------------------------------------\
|                                    GetUnitDamage                                                   |
|                                         by: BloodForBlood                                           |
|                                                                                                   |
|    What this does:                                                                                   |
|        Gets the damage of unit.But it's not fast.                                                   |
|        And this doesn't include the damage bonus abilities(this only includes item).               |
|        If anyone have suggestions to make it faster                                                   |                               |
|        and includes damage bonus abilities,                                                          |
|        just message me or comment at Hive Workshop.                                               |
|                                                                                                   |
|    How to Import:                                                                                   |
|        Copy the unit(Dummy Damage Taker) and ability(GetUnitDamage Attack Speed Bonus)               |
|        and copy this trigger then paste it to your map.                                           |
|                                                                                                  |
|                                                                                                   |
|    How to use:                                                                                       |
|        GetUnitDamage takes unit whichUnit returns real                                               |
|            whichUnit: refers to the unit you wan't to get                                           |
|                       its damage.                                                                   |
|            Example: GetUnitDamage(YourUnit)                                                       |
|                                                                                                   |
|     Special Thanks To:                                                                               |
|        GetItemCostById system by weaaddar's where I get                                           |
|        the concept of this.                                                                       |
|                                                                                                   |
\-------------------------------------------------------------------------------------------------*/

    globals
        //Change the value to the exact raw code of dummy unit(Dummy Damage Taker).
        private    constant integer DAMAGE_TAKER_ID = 'DMGT'
        //The dummy unit's owner.
        private constant player PLAYER_OWNER = Player(15)
        //Change the value to the exact raw code of attack speed bonus ability(GetUnitDamage Attack Speed Bonus).
        private constant integer ATTACK_SPEED_BONUS_ID = 'DMGS'
    endglobals

    //Don't change below unless you know what you're doing.
    function GetUnitDamage takes unit whichUnit returns real
        local integer id = GetUnitTypeId(whichUnit)
        local unit DamageTaker
        local unit u
        local real dmg
        local real DefaultHealth
      
        set DamageTaker =  CreateUnit(PLAYER_OWNER, DAMAGE_TAKER_ID, 0, 0, 0)
        set DefaultHealth = GetUnitState(DamageTaker, UNIT_STATE_LIFE)
        set u =  CreateUnit(PLAYER_OWNER, id, 0, 0, 0)
        call SetUnitX(u, GetUnitX(DamageTaker))
        call SetUnitY(u, GetUnitY(DamageTaker))
        call UnitAddAbility(u, 'Atru')
        call UnitAddAbility(u, 'Agho')
        call UnitAddAbility(u, ATTACK_SPEED_BONUS_ID)
        call SetHeroLevel( u,  GetUnitLevel(whichUnit), false )
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = UnitInventorySize(whichUnit)
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            call UnitAddItemByIdSwapped( GetItemTypeId(UnitItemInSlotBJ(whichUnit, GetForLoopIndexA())), u )
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop
        call IssueTargetOrder(u, "attackonce", DamageTaker)
        loop
            exitwhen GetUnitState(DamageTaker, UNIT_STATE_LIFE) != DefaultHealth
            call TriggerSleepAction(0.01)
        endloop
      
        set dmg = DefaultHealth - GetUnitState(DamageTaker, UNIT_STATE_LIFE)
        call SetUnitState(DamageTaker, UNIT_STATE_LIFE, GetUnitState(DamageTaker, UNIT_STATE_MAX_LIFE))
        call KillUnit(u)
        call RemoveUnit(u)
        call KillUnit(DamageTaker)
        call RemoveUnit(DamageTaker)
        set u = null
        set DamageTaker = null
        return dmg
    endfunction

endlibrary

It also includes Boundless Strike from DotA 2 as a template,but it's just a test spell.
Contents

Get Unit Damage (Map)

Reviews
MyPad
Until a new approach is found regarding GetUnitDamage for previous versions of warcraft, this resource has been moved to Substandard. If the author wishes to update the resource, he/she may request in thread or PM the Staff. Status: Substandard

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,887
First of all: Don't use bj_forLoopAIndex or bj_forLoopBIndex, use your own variable for this one since it was proven to be more effective and faster.
Why even reset the hp of the dummy unit "damage taker" if it is going to be removed? Also, why do you even kill the unit first and then remove? Just remove it instead.
Instead of the wait a timer would be better.
I don't think you need to use the BJ on adding the item
I have doubts about this system because: 1 - The name of it dubious, i thought this would return the full damage ignoring armor and armor type, should be GetUnitItemDamageSum
2 - As i just stated about ignoring armor and armor type, if the user has modified them with other reductions or amplifiers, this won't give the correct result.
3 - At moment your system fails if the unit is a non-hero without inventory

With the new patch, we can not only get the base damage of the unit but the dice and dice sides, and set the cooldown of the attack.

JASS:
call BlzSetUnitAttackCooldown( Unit, 0.01, 1 )
call BlzSetUnitBaseDamage( Unit, BlzGetUnitBaseDamage(Unit, 0), 0 )
call BlzSetUnitDiceNumber( Unit, 4, 0 )
call BlzSetUnitDiceSides( Unit, 1, 0 )
//this is all for the weapon 1

Quick tip: dont tick every option on the tags, this is not a spell, so "target ground" and "target object" shouldn't be included, also "GUI/ Triggers" because this isn't certainly GUI, only vJASS (almost doesn't look like it anyways).
 
Level 5
Joined
Mar 15, 2017
Messages
96
First of all: Don't use bj_forLoopAIndex or bj_forLoopBIndex, use your own variable for this one since it was proven to be more effective and faster.
Why even reset the hp of the dummy unit "damage taker" if it is going to be removed? Also, why do you even kill the unit first and then remove? Just remove it instead.
Instead of the wait a timer would be better.
I don't think you need to use the BJ on adding the item
I have doubts about this system because: 1 - The name of it dubious, i thought this would return the full damage ignoring armor and armor type, should be GetUnitItemDamageSum
2 - As i just stated about ignoring armor and armor type, if the user has modified them with other reductions or amplifiers, this won't give the correct result.
3 - At moment your system fails if the unit is a non-hero without inventory

With the new patch, we can not only get the base damage of the unit but the dice and dice sides, and set the cooldown of the attack.

JASS:
call BlzSetUnitAttackCooldown( Unit, 0.01, 1 )
call BlzSetUnitBaseDamage( Unit, BlzGetUnitBaseDamage(Unit, 0), 0 )
call BlzSetUnitDiceNumber( Unit, 4, 0 )
call BlzSetUnitDiceSides( Unit, 1, 0 )
//this is all for the weapon 1

Quick tip: dont tick every option on the tags, this is not a spell, so "target ground" and "target object" shouldn't be included, also "GUI/ Triggers" because this isn't certainly GUI, only vJASS (almost doesn't look like it anyways).
Oh...Okay I'll update it...I'm sorry,I'm new at vJASS and a new member of Hive.
And I also didn't know about 1.29 ;)
 
Level 5
Joined
Mar 15, 2017
Messages
96
Until a new approach is found regarding GetUnitDamage for previous versions of warcraft, this resource has been moved to Substandard.

If the author wishes to update the resource, he/she may request in thread or PM the Staff.

Status:

  • Substandard
Yeah it's okay, I abandoned this.This would be useful in other reason
 
Top