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

Item +20% main stats?

Level 5
Joined
May 8, 2020
Messages
78
1711956575262.png


I'm stuck with this
 
now you would need to add INTER to the current Hero's strength. use an action inside category hero for that.
Then you need to find a way to make that also work for agility and int heroes.

In warcraft 3 V1.31.1 and higher one can get the main attribute of an hero using the unit integer field.
I showed it here How to make item that gives stats to primary attribute?

for older versions you need to find out the main attribute yourself maybe by some unused Object Editor field you can read, or hardcode it for each heroType.
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
Consider that updating the attributes of a unit like that won't take future changes to the stat into account, and would need to be worked around. This is *some*what of a problem here because you can't just easily tell the game to recompute... you actually have to remove the stats you added before, calculate the new correct value, and then add the correct new bonus to the unit to reach that value. Simple example:
  1. I have 20 strength at base, and pick up an item that grants me 10% bonus strength. I now have 22 strength.
  2. I pick up gloves that grant +10 strength.
  3. If I just add that +10 to my current STR of 22, I'll have 32 total STR... but that's not correct: I have 30 base strength +10% should be 33 STR.
  4. I must take my original 22 strength, divide it by my multiplier of 1.10 to get my 'true' strength, add the 10, then multiply that number by 1.10 again.

  5. If I were to use my 'new' value of 32 strength and divide it by my 1.10 multiplier, I would also not end up with the correct amount, as the bonus from my new +10 STR item would be applied twice instead of once. This is another pitfall.
Finally, consider that you can't have fractional strength (like 15.2), so such computations must always truncate down for consistency lest you accidentally drop a strength point here and there from rounding errors you weren't prepared for. So what is the proper method to account for all of this:
  • -------- When computing the first time: --------
  • Set TrueAttribute = (The unit's current attribute value, like 20 STR above)
  • Set BonusAmount = 0.20 //20% bonus
  • Set BonusGranted = (Integer(TrueAttribute x BonusAmount))
  • Hero - Add BonusGranted to the unit's current stat
  • -------- store the value of BonusGranted to use it later --------
  • -------- --------
  • -------- When recomputing for any reason: --------
  • Set CurrentAttribute = (The unit's current attribute value, like 32 STR above)
  • Set TrueAttribute = (CurrentAttribute - BonusGranted)
  • Set BonusAmount = 0.20 //20% bonus
  • Set OldBonus = BonusGranted
  • Set BonusGranted = (Integer(TrueAttribute x BonusAmount))
  • Hero - Add (BonusGranted - OldBonus) to the unit's current stat
  • -------- Re-store the value of BonusGranted to keep reusing it later --------
 
Top