There are 3 methods for giving stat bonuses:
Adding abilities - Usable for almost all stats. Shows a green number except with health and mana. There's a limit based on how many abilities you have and you have to always consider which abilities you've already added, meaning that on the system level you set the bonus, instead of adding it.
Glitching with levels - Infinite bonuses possible, since you can keep doing this.
Tomes - Works essentially the same as glitching with levels, except that instead of the glitch trick you just use items, which you can delete after that. Usable for base hero attributes(useless, because you have a function for that), damage and health.
Adding is the cheapest, but has a limit based on the number of abilities.
Glitching is the best because it's not much more expensive than adding, but provides an unlimited range of bonuses.
Tomes are for when you can't use either adding or glitching.
I've included the first 2 in the testmap. For now I'm quite tired, so I only wrote up the thinking involved in the health part(glitching), but the armor one is easier(adding), so you might be able to figure it out based on the other explanation and on the test map.
There are also the formulas for maximum(and minimum) possible bonuses in the armor example.
Health:
When you give the unit an ability that increases health, its health gets modified by the level 1 amount. When it's removed, the amount of the current level is detracted. There's a bug that when the level of such an ability is changed, it doesn't notice at all, so the health given doesn't change.
So here's the trick:
Make the first level of the ability give no bonus(0).
Make all other levels give the opposite of the bonus that they usually would give.
So with this we get a lineup of
0
1
2
4
8
16
...
4096
-8192
Why is the last number negative? Well, this is how we handle both positive and negative numbers. Keep in mind that with this bug, each health amount is actually the opposite of what it really adds, so the last level actually gives health and all others(except level 1) reduce it.
However, we have a few problems:
The first level of an ability can not be 0, so we had to shift all values one level up.
In addition, we wanted the first level to be 0, so that's another time we shifted all values up by a level. It's easy to handle in the code though:
Whenever we calculate the bonus that a level gives with Pow(2,level) we instead use Pow(2,level-2).
Okay, so what's more in this code? Since by abusing this bug we don't need the abilities to stay on the unit we can just keep doing this and get any bonus we want(positive or negative). I included this automatically in the code.
Since most of the bonuses really reduce health we also have one other potential problem - if unit (max) health gets negative while it's being changed the unit will simply die. To solve this we first check if the amount to add is positive and if so, give the unit the highest possible bonus. We repeat this, for reasons outlined in the previous paragraph, until the amount is no longer over 0.
However, the math doesn't work right if numbers are negative(even(as opposed to odd) powers of a number can never give negative numbers). For this reason we change the bonus to the opposite of what it was and act like the next abilities we add were actually positive. It's easier mathematically this way.