• 🏆 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] [Help] Getting Informations about an Unit

Status
Not open for further replies.
Level 2
Joined
Feb 15, 2008
Messages
6
Well hello guys. I looked through the forums, google and soon and now i reached the point where i have to create a new thread.

So my question:

How can i find those following things and save them into a variable:
Attack Power of an Hero.
Defense of an Hero.
 
Level 4
Joined
May 4, 2008
Messages
113
Well hello guys. I looked through the forums, google and soon and now i reached the point where i have to create a new thread.

So my question:

How can i find those following things and save them into a variable:
Attack Power of an Hero.
Defense of an Hero.

You can't, it's basically impossible.

You could probably vaguely calculate attack power by checking how much damage the unit is doing when it attacks, but that would often be innaccurate. You could get defense by adding up every possible thing that might change the hero's defense, but that'd take ages.

Doesn't seem worth it to me.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
You could calculate the defense briefly with the formula

Originally Posted by Warcraft III - Basics -> Hero Basics

Defense:
1 point of Agility = 0.3 increase in armor
Total Armor = -2 (Base Armor) + 0.3 * Hero's AGI

In the matter of adding items which gives armor, and abilities such as devotion aura, you would have to check everytime you receive the specific item or has the specific buff and manually add that to the formula.

The attack power, as in "attack damage"? Like Ziggy already mentioned, it's kind of impossible. There are a few ways to do it, but those I can think of is not good enough and worth the trouble.
 
Level 15
Joined
Dec 18, 2007
Messages
1,098
This is impossible, really. Unless you found out that Blizzard has a hidden coding language in Warcraft that they use to code all their spells and the game mechanics.
Thus, it is rather impossible to find the attack damage of a unit or the armour of a unit unless you are a really hard working guy and does lots of formulas and make a breakthrough.
 
Level 6
Joined
May 5, 2008
Messages
210
it isn´t impossible.


Set x = ((Intelligenc of (Picked unit) (Add bonuses)) + 2)

or whatever your main attribut is. This is ONLY the min damage of the normal heros (change 2 to the Number of dicec of the hero, if 1 int isn´t 1 damage you´ll have to multiple it with 1.5, 2 or whatever)

for Armor

Set x = ((Agility of (Picked unit) (Add bonuses)) x 0.3 - 2)
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
You could use the following function to get armor:

JASS:
//Logarithm
//by : Vexorian
//"Will * try to guess * the Logarithm it does have good results but it is not as good as having a native Logarithm though."
function Logarithm takes real x, real base returns real
 local real inc=1
 local real n=0
 local real dif1=x-1
 local real dif2=0
 local integer f=1
    if x<=0 or x==1 then
        return 0.0
    elseif x<1 then
        set f=-1
        set x=1/x
        set dif1=x-1
    endif
    loop
        set n=n+inc
        set dif2 = dif1
        set dif1 = x-Pow(base,n)
        exitwhen dif1 == 0
        if dif1 > dif2 or dif1 < 0 then
            set n = n - inc
            set dif1=dif2
            set inc = inc / 10
        endif
    endloop
 return n*f
endfunction


//Calculates the armor of an unit
//by: Natac & Mueslirocker
//requires:
// - Chaos- deals 100% damage to all types of armor.
// - The ability 'AIl1' increases hp by 200
// - Logarithm function
function GetUnitArmor takes unit checkingUnit returns real 
    // Variablen initialisieren
    local real    life    = GetUnitState(checkingUnit, UNIT_STATE_LIFE)
    local real    armor   = 0.00
    local real    damage  = 0.00
    local boolean lowlife = false

   //increase life by 200 so that units with hp <200 wont die
    if( GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) < 200 ) then
       call UnitAddAbility(checkingUnit, 'AIl1')
       set lowlife = true
    endif

	//set unit life to 100% so it wont die
    call SetUnitState(checkingUnit, UNIT_STATE_LIFE, GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) )

    //deal 100 Chaos damage
    call UnitDamageTarget(checkingUnit, checkingUnit, 100.00, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)

    //Save damage
    set damage = GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) - GetUnitState(checkingUnit, UNIT_STATE_LIFE)

    //Remove Life Bonus
    if ( lowlife == true ) then
        call UnitRemoveAbility(checkingUnit, 'AIl1')
        set lowlife  = false
    endif

    //restore hp before testing
    call SetUnitState(checkingUnit, UNIT_STATE_LIFE, life)

    //100% reduction -> 10000 armor
    if ( damage == 0 ) then
        set checkingUnit = null
        return 10000.00
    endif

    //100% reduction -> -233.28 armor
    if ( damage == 200) then
        set checkingUnit = null
        return -233.28
    endif 

    //calculate armor
    if ( damage <= 100.00 ) then // < 100% damage: armor >= 0
        set armor = ((100.00-damage)/damage) /0.06
    else                         // > 100% damage: armor < 0
        set armor = Logarithm( 100/(200-damage), bj_E ) / -0.061
    endif

    //Clear
    set checkingUnit = null
    set life         = 0.00
    set damage       = 0.00

    return armor
endfunction

To get the damage of an unti you could have a trigger logging all damage done by your heror and calculate the damage out of this data.

Or you would have to store all items and spells affecting damage. You could probably write a GMSI script to do this.
 
Status
Not open for further replies.
Top