# RMMVMultiple hpRate check

#### Deagron

##### Veteran
Hello, I hope my issue is on the right thread.

I've been doing my project smoothly for now, and came across an issue with a skill that checks the hp of the target to increase its base damage.

My damage formula works correctly as I tested it on my usual skills, though it's a bit lengthy since variance was too big (the formula is inspired by Dragon Quest 8's damage formula). Here it is without the hp mechanic :

dmg = ((a.mat*0.7)*(a.level*0.035)) + ((a.mat*0.25) + ((a.level/70)*55)) - (b.mdf/6) ; rge1 = dmg-((dmg/16)+1) ; rge2 = dmg+((dmg/16)+1) ; dmg = Math.floor(Math.random() * (rge2 - rge1 + 1)) + rge1 ; tdmg = (v[20]) * dmg ; tdmg

where v[20] depends on states that the character can have

I've been searching a bit in order for the skill to depend on the target's hpRate. As I wanted the skill to not be overpowered below the 10% hp, I tired to make an event changing a variable or a if(b.hpRate()) kind of thing in the damage formula.
The issue comes there, cause when I try the skill it doesn't deal damage anymore. So what I want to achieve is this kind of result :
-if the HP of the target is above 80% of its maximum, the damage of the skill is reduced by 20%
-if the HP of the target is above 50% of its maximum, the damage of the skill is normal
-if the HP of the target is above 20% of its maximum, the damage of the skill is increased by 20%
-if the HP of the target is under 20% of its maximum, the damage of the skill is increased by 50%

Can I achieve it with my current damage formula ? Is there a way to have a 'if x ? else : if y ?' situation in RMMV ?

#### Andar

##### Veteran
when I try the skill it doesn't deal damage anymore.
if the damage formula works without that extension but not with it, then that is usually a sign that there is either an undefined name or a typo in the formula - because the eval breaks to zero if encountering an error during processing.

you might get some help in finding that error if you post what doesn't work.

That said, I suggest a slightly different approach to prevent that mess of damage formulae.
A damage formula can call any global script function, so I suggest requesting a plugin that does nothing but define some global formulae to be used in the damage function.

then you write the more complex parts of your damage process into that plugin and just call the calculation from the damage formula. This will make your formulae much more readable.

#### Magnus0808

##### Software Developer
Sure, the following should do it. Just replace the last tdmg with it.

Code:
``tdmg * (b.hpRate() > 0.8 ? 0.8 : (b.hpRate() > 0.5 ? 1 : (b.hpRate() > 0.2 ? 1.2 : 1.5)))``

It is basically a simplified bunch of if-else statements in a single line.

#### Deagron

##### Veteran
Sure, the following should do it. Just replace the last tdmg with it.

Code:
``tdmg * (b.hpRate() > 0.8 ? 0.8 : (b.hpRate() > 0.5 ? 1 : (b.hpRate() > 0.2 ? 1.2 : 1.5)))``

It is basically a simplified bunch of if-else statements in a single line.
It worked ! thank you

### Latest Profile Posts

I've decided "Attack on Equestria" should be released first... hence this new ARG channel! https://www.youtube.com/channel/UClKiUI8xOVx9dsF4kRXUmxw
Check it out, and subscribe! The ARG will lead up to the video game. It's not a creepy game, but I just thought it should follow ARG standards.
For anyone interested in my project M - i finally made a gamethread about it

Yay. I turned 39 today. Another year older, another year closer to the grave.
I'm sure the latest post/thread in the sidebar used to have 5 posts. Was it always been like this?

Threads
110,407
Messages
1,053,065
Members
143,469
Latest member
ClementPanchout