Can you modify a hero's stats, enemy's stats, money, etc. by a percentage rather than by a whole number with plotscripting?
Jump to navigation
Jump to search
Of course. With plotscripting you can do any math you want, and modifying a value by a percentage is just math.
The formula to find A% of the number B is
(B * A) / 100
Note: In HamsterSpeak there are only integer (whole) numbers, so to avoid catastrophic rounding error you have to be careful of the order in which you perform operations. Always do multiplications before division, as above (the brackets are optional in this case).
Here is an example that sets a hero's HP to 10% of its maximum
variable(who) who := find hero(hero:Bob) variable(max) max := get hero stat(who, stat:HP, maximum stat) variable(new HP) new HP := max * 10 / 100 set hero stat(who, stat:hp, new HP, current stat)