Attack that hits harder, when enemy has lower HP percentage than the one attacking.

Greetings and salutations sages and intellectuals of the RPG Maker forums! I come to you in the time of considerably smaller need than previously.
I was thinking about creating an attack, that will deal more damage when an enemy has lower health percentage than the character carrying out the deed.
I assumed a formula that goes:
if ( a.hp > b.hp ) {a.atk * 4} else {a.atk * 2}
Will accomplish what I desire, but I wanted to make sure with people more knowledgable in the subject.

I thank you for all the responses in advance.
I assumed a formula that goes:
...
Will accomplish what I desire
fastest way to see is to test it and see if it does what you want. if it doesnt, then you know something about it isnt correct and itd be easier to ask about.

I was thinking about creating an attack, that will deal more damage when an enemy has lower health percentage than the character carrying out the deed.
a.hp > b.hp
thats not the same. what youve done here is compare their current HPs directly. it will not factor the HP percentages. youd have to divide each battler's current hp by their max hp (or use the hpRate() function)

Code:
a.hpRate() > b.hpRate() ? a.atk * 4 : a.atk * 2
fastest way to see is to test it and see if it does what you want. if it doesnt, then you know something about it isnt correct and itd be easier to ask about.



thats not the same. what youve done here is compare their current HPs directly. it will not factor the HP percentages. youd have to divide each battler's current hp by their max hp (or use the hpRate() function)

Code:
a.hpRate() > b.hpRate() ? a.atk * 4 : a.atk * 2
Yes, that works! Thank you very much.

Original thread: https://forums.rpgmakerweb.com/threads/attack-that-hits-harder-when-enemy-has-lower-hp-percentage-than-the-one-attacking.173902/