1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] [Help] Getting Informations about an Unit

Discussion in 'Triggers & Scripts' started by Xeon212, Feb 21, 2009.

  1. Xeon212

    Xeon212

    Joined:
    Feb 15, 2008
    Messages:
    6
    Resources:
    0
    Resources:
    0
    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.
     
  2. ZiggyMcjoney

    ZiggyMcjoney

    Joined:
    May 4, 2008
    Messages:
    109
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.
     
  3. Eccho

    Eccho

    Joined:
    Nov 29, 2006
    Messages:
    2,297
    Resources:
    2
    Spells:
    2
    Resources:
    2
    You could calculate the defense briefly with the formula

    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.
     
  4. deathdoorway

    deathdoorway

    Joined:
    Apr 13, 2005
    Messages:
    621
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Thats a very advance triggering u gonna be doing their. If you need attack damage do the main att / how much it needs to gain 1 damage with. Also be sure to add in if the unit has a base attack damage.
     
  5. M4stah

    M4stah

    Joined:
    Feb 16, 2009
    Messages:
    711
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Why do you need it? I'm pretty sure we have some people here who can make a alternative trigger with the desired result.
     
  6. Zack1996

    Zack1996

    Joined:
    Dec 18, 2007
    Messages:
    1,088
    Resources:
    3
    Models:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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.
     
  7. Urwaldbewohner

    Urwaldbewohner

    Joined:
    May 5, 2008
    Messages:
    99
    Resources:
    0
    Resources:
    0
    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)
     
  8. M4stah

    M4stah

    Joined:
    Feb 16, 2009
    Messages:
    711
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Urwaldbewohner, that is inaccurate. Cant you show a trigger where you calculate the attack WITH bonus items and buffs added? i doubt you can.
     
  9. peq

    peq

    Joined:
    May 13, 2007
    Messages:
    171
    Resources:
    1
    Maps:
    1
    Resources:
    1
    You could use the following function to get armor:

    Code (vJASS):

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