How to have stronger enemy attacks depending on damage taken last turn?

Hi, RPGMaker Forums!
I've recently tried to create a system that would increase the attack damage of a skill an enemy uses depending on the percentage of the enemy's health that was lost in the last turn. Unfortunately, my system causes crashes, and I'm wondering how I could go about doing this properly. Here's what I have currently, this probably isn't the most efficient way of doing this, but this is how I currently have it:
3 Variables: Enemy %, Enemy Current Health, and Enemy New Health
  • At the start of each turn, Enemy Current Health is set to the enemy's current health.
  • At the end of each turn, Enemy New Health is set to the enemy's new current health.
  • Enemy % is then set to the Max HP of Enemy
  • Take Enemy Current Health and subtract Enemy New Health to get the amount of damage Enemy has taken this round
  • Enemy % is divided by the new value of Enemy Current Health, and then divided by 100 to get the percentage of the enemy's max health that was taken last turn
  • Enemy % is then multiplied by 3 and added to 1 to get the value that I multiply this enemy's attack damage by in the skill formulas to get the final damage values. This might come out at a value around ~1.21 or so, so that's a 21% increase in damage for that turn.
Yes, this is a bit of a roundabout way to do it, but I don't know Javascript and this is the only way I could think to do it.
However, occasionally when using this formula, skills involving the multiplier (I multiply skills by Enemy %) will crash the game with the error:

TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double is non-finite
This seems to be the same error as this thread, and the reasoning behind it was explained fairly in-depth in that thread. As far as I know its an undefined value / NaN value screwing things up, which then sets the HP value to a NaN, which the graphics for the health bar cannot draw, -> crash.

So, is there a way to have skills that scale depending on how much damage the enemy has taken this round, either using javascript or plugins or such? I've heard that some plugins could affect this error but a lot of them are kind of essential, here's a short list of the ones that I think would be impacting it:
YEP_BattleEngineCore
YEP_SkillCore
YEP_X_VisualHpGauge


Any help with this would be greatly appreciated, I'm not sure whether to post this in the Javascript support channels, we'll see.
Thanks!
Are you willing to give up the visual heath bar plugin? As you probably guessed that’s most likely causing the crash.
What could cause this issue is that the value comes out as a very long decimal value that the plugin can't handle properly. Make sure the damage value is rounded up or down before the damage execution, for example with Math.round(value) or Math.ceil(value).
What could cause this issue is that the value comes out as a very long decimal value that the plugin can't handle properly. Make sure the damage value is rounded up or down before the damage execution, for example with Math.round(value) or Math.ceil(value).
That seems to have fixed it, put that into the damage formula and the crashes haven't happened again yet. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-have-stronger-enemy-attacks-depending-on-damage-taken-last-turn.128370/