Why does this happen? (HP Rate)

So I'm going through the painfully slow process of adding classes/skills to the database, creating new animations, and scripting in functionality where necessary when I encountered some odd behavior.

Why01.PNGWhy02.PNG

hp_rate as I've understood it, should return what is essentially the decimal equivalent of the percentage of HP remaining.

If health is at full: hp_rate = 1

If health is at half: hp_rate = 0.5

Through some testing, this has been shown to be true, however, when I multiply a say... atk by hp_rate, the value increases drastically as HP falls while I'd expect it to decrease instead...

# The formula for the berserk state is bascially: user.atk *= (1 / user.hp_rate) #Should increase as hp falls.# The formula I tested above is: user.atk * user.hp_rate # Should decrease as hp falls.Instead they both return insanely high values as hp damage is taken. Now, I'm not asking for a solution, I just want to know what's causing this.
If the above is exactly what you entered as the damage formula, that could be the issue right there. There is no user variable in the damage formula. It is a.atk and a.hp_rate.


However, if we assume you actually entered the damage formula correctly and not as you've shown above, there are a few other things that could cause it.


Got any scripts that might influence damage calculations or those stats?


Does it work properly in a brand new project with absolutely NO script mods/additions?


Could you give us a screenshot of your skill and let us know what the ATK, HP and MAXHP values are at this point in the game?
I don't know if 563 would qualify as "insanely high" considering the other numbers... Did you overlook the decimal point by chance? What numbers would you expect there?

Yes, that's what hp_rate is supposed to do for battlers.

user.atk *= (1 / user.hp_rate)

might not work because of the assignment operator  =  ( user.atk = ...  is undefined by default, there are other ways to modify a battlers parameters).
@Shaz
It was just an example. I'll be exact from now on. The two screenshots show the issue in action:

a.atk * a.hp_rate # should decrease the value as HP fallsThis has only happened when I multiplied atk by hp_rate. If you look at the line below the one that is highlighted in the second screenshot, you'll see:

a.hit * (1 / a.hp_rate)Which works fine, as evident in the first screenshot by the second yellow number 1.65%

Before any damage is taken:
HP = 1,337
ATK = 54
HIT = 1.0%

(No changes from the first screenshots, my enemies are just random)
Why03.PNG

Here's the skill itself:
Why04.PNG

Since the problem is showing up in the skill's description window, it wouldn't really be related to any damage calculations unless I called calc1 or calc2, but I'm not having issues with those. Now that you've brought it up though, it could easily be the 'berserk' state which is managed by Lunatic States. I'll have a look now.

@Another Fen
Yeah 563 is insane considering the formula that returns that number is "a.atk * a.hp_rate", with ATK being only 54. I would expect this number to decrease as HP falls, but it's multiplied over 10 times instead.

Just to be clear the use of 'user' was just an example, it's not something I'd use within skills damage formula or notetags. By user I just meant "the user of this skill".
I'm going to move this to RGSSx Script Support, as the whole thing is obviously set up this way due to a script you're using. Can you please add a link to the download page of the script?


I had initially assumed you had just put that into the damage formula and that it wasn't related to the script.
Seems to have been an oversight on my part. Instead of just updating the ATK parameter whenever the afflicted actor received damage, the value was being added permanently on each occurrence. I tried a few things, but I don't know of a good way to temporarily increase parameters using Lunatic States.

So I opted to simply increase overall damage output without affecting any parameters. Pretty easy to pull off when damage formulas are localized.

#--------------------------------------------------------------------------- # Berserk (Berserker) #--------------------------------------------------------------------------- if a.state?(99) then x *= (1.0 / a.hp_rate) endx is previously calculated earlier in the script and returned as the skill's output damage. Works as expected, though I'd like it if hit rate were to increase in a similar fashion. I don't want to write another script just to deal with a single aspect of this skill though...

@Shaz
Not sure if you meant Lunatic States or not, but there it is. The scripts that handle damage formulas and that which allows for formula evaluation within the help window are personal scripts that I haven't released as of yet. The one that extends the size of the help window and allows the notes section to be used as description text is in my signature.

Original thread: https://forums.rpgmakerweb.com/threads/why-does-this-happen-hp-rate.51851/