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

% Bonus Stats Trigger

Status
Not open for further replies.
Level 6
Joined
Jun 28, 2016
Messages
70
Hi evryone !

Today i had an idea for a rpg project of mine...
Many maps actually use this idea already.

I would like to know how to Create a special ability
Allowing heroes to gain a % scaling stats bonus, meaning :

Exemple: Hero possess 100 str with the "Ring of the Behemoth" he gain a 5% Scaling Str bonus -> his str would now be 105 & if he were to have 200 basic str in the futur he would have 210 str.

If anyone have worked with this kind of mathematic bundle before, i'l gladly take a class to understand it's mechanics.

Thank you for your time !
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
There is an action to change an attribute:
  • Hero - Modify Strength of (Triggering unit): Set to 10
You first need to determine how much strength you want to add. For example strength * 0.1, if you want +10% strength.
The only difficulty is, that once you increase your stats by let's say 20 after you got the item, you should get an additional 2 strength.
It's probably best to keep track of the heroes base strength with variables, so you know how much strength he has without the relative bonus.
Whenever your base strength is changed you recalculate the relative strength bonus.
 
Level 6
Joined
Jun 28, 2016
Messages
70
i'l try to be more specific : Actually i'm trying to add " Bonus stats " (not modified stats) like an Item ability would. I want it to Scale Itself over time.
so i would like to know how to build a leakless tracking system for Stats & a "Stats Bonus Creator system" that can work with % of the basic stats.

If that's possible.
 
Level 10
Joined
Oct 5, 2008
Messages
355
Jampion was more or less right, you need to seperately track the attribute a hero possesses. That means either periodic event checking, or registering somehoe (either through (aquire item event), (level up event) etc.). The last apporach would be more efficient, albeit a bit more complex and you could miss stuff, over throwing the system in the process, although the periodic check could catch alterations wrongly.

Since you are searching for the item-bonus effect, i would say you are more or less at the point where you need to look at. Multiple systems use the principle of multiple level item abilities to dynamically increase damage/defense. This should be possible with attributes also. Make 3 abilities with 11 levels, everyone should be attribute bonus.
The levels whould be the following:
1. Ability:
0,1,2,3,4...9
2. Ability:
0,10,20,30,40...90
3. Ability:
0,100,200,300,400....900
=> You could use more abilities or could use a hexadecimal or other system, what you like
If you now add an amount of the corresponding attribute to the unit, add it to the saved amount (should be different from the tracked standart amount, to avoid bonus loops), add all these three to the unit (if not already present), and set them to the following level:
1. Ability:
(#Statbonus mod 10) + 1
2. Ability:
R2I((I2R(#Statbonus mod 100)/10)) + 1
3. Ability:
R2I((I2R(#Statbonus mod 1000)/100)) + 1

This should set the abilities to the corresponding decimal bonus.
 
Level 6
Joined
Jun 28, 2016
Messages
70
so i would need 9 Hexadecimal ability & will need to / x + - them in order to somehow get the % value i needed for the item. While Checking the Basic Value evry 0.25 sec for example ?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Oh yeah. I did not think about the green numbers.

First focus on a system that allows you to add any value as bonus.
Creating a good API is often hard to accomplish in GUI, but I would probably use two parameter variables (unit and bonus amount) and then run a trigger to change the bonus for a unit to the given amount. Reading the current value can be done directly by using arrays or hashtables depeding on whether you prefer unit indexer + arrays or hashtables.

You are going to need abilities. These abilities are based on the item abilities of the normal attribute bonus items (Gauntlest of Ogre Strength, Mantle of Intelligence,...).
You will create unit abilities instead of item abilities though.
you create one ability per power of two (1,2,4,8,16,32,...), because by combining these abilities you can get any amount of bonus in a certain interval.
@Lord_Earthfire I think you can't use multiple levels with these abilities, but I might be wrong.
The approach Lord_Earthfire mentioned is more intuitive, but requires more abilities, that's why I prefer using powers of two (basically binary number system).

You need to store the current attribute bonus from this system for every unit. Let's say your unit has +7 strength. this means is has the abilities +1, +2 and +4. When you want to add another 2, you will be at +9 and want to have +1 and +8.
So basically when you change the bonus you want to have you first remove all bonus abilities from that unit and add the new abilities. For that you need to know, that you had +7 before, so you know that you want to have +9 after you add 2.
It is possible to calculate the current bonus from the abilities the unit has, but this is inefficient, so better store it.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
It is important to keep track of the actual bonus stats that are being added due to percentage bonuses otherwise you will suffer from loss of stats due to rounding error. An example of a map that failed to do this was DBZ Tribute Ultra and all its spin offs, depending on your power level (stat multiplier) you would gain more or less stats from certain sources due to rounding error. Fractional stats can be stored in an accumulator or if adding a stat bonus you can remove the current bonus amount and re-compute the bonus amount from current stats entirely.

Technically hero stats are real values, fractional stats do exist and do have meaning. However one cannot really manipulate hero stats as a real, so it is better to round all values to an integer mechanically.
 
Level 10
Joined
Oct 5, 2008
Messages
355
I think you can't use multiple levels with these abilities, but I might be wrong.
You can use the hero ability "attribute bonus" and conveet it into a unit ability if the item ability fails to do the job. It has a field to hide the icon iirc.

so i would need 9 Hexadecimal ability & will need to / x + - them in order to somehow get the % value i needed for the item. While Checking the Basic Value evry 0.25 sec for example ?
Pretty much yes, you could get away with more or less, dependingon how high your attributes scale and which numeral system you are using
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You can use the hero ability "attribute bonus" and conveet it into a unit ability if the item ability fails to do the job. It has a field to hide the icon iirc.
Yeah you are right, but that would only work with your method and not with the binary method, because you can't have a ability multiple times on different levels. In the binary system you have to be able to have +1 and +2 to get +3, which is not possible if +1 and +2 are in the same ability with different levels.
 
Level 10
Joined
Oct 5, 2008
Messages
355
Well, i could think of a way to have multiple abilities of different levels, but that approach sounds quite bug abusing in my mind. You brought me to an idea i need to test out.

On topic: thats a good point. I just like having higher bases, since, although i have a higher number of ability levels, need less abilities overall, which saves me some clicking in gui.(really, my next project really needs to be a jass one...)
 
Status
Not open for further replies.
Top