Hi, I've seen variations of this question asked alot, but not specifically one like this. Is there a way to make a skill that does 50% more damage for every 25% HP missing from the user, up to a maximum of 200? I'm not really the greatest at DMG formulas and I'm still pretty new to it. I have yanfly's Damage Core if that helps any.
Skill That Does More Damage For Every Quarter HP Missing
RPG Maker MV SupportWhat does this mean? A maximum of 200 damage? A maximum of 200% would be pointless because at that point you're trying to hit a target that's already dead.
Increasing the damage when the target's hp is lower is really simple math; but doing it only on increments of 25% will require JavaScript.
Code:
let value= insert your original damage formula here; value+=Math.floor((b.mhp-b.hp) / (b.mhp*.25))*value*.5
Sorry 200%, forgot the%. Also for it to be 200% they would have to be at 1 HP which would be uncommon, but it would still be nice to have anyways.
As that's not mathematically accurate 😉 (being at 1 hp isn't 100% damaged), the above formula won't take that into account. Rounding up instead of down would screw up all the other increments. So you'd have to add an additional chunk of code just to account for however often you might target an enemy with 1 hp.
And, just out of curiosity, what's the point? Doing any damage will kill them when they have 1 hp, so why would you want to bother making it do even more damage just to display a higher number?
Anyway, the formula I provided should do the rest of what you asked. Test it out, let us know if there are any problems.
I tried the code and skill did the base value damage, but it didn't increase when the characters HP decreased. I'm not sure if I did something wrong but here's the code I used
Code:
let value= a.atk * 4 - b.def * 2; value+=Math.floor((b.mhp-b.hp) / (b.mhp*.25))*value*.5
We're checking HP missing from the user, right?
So you can try this:
Edit:
Let's say your damage formula is currently:
To scale this up based on missing HP, we can multiply it by the equation of a straight line from:
A few quick checks:
a.atk * 4 - b.def * 2To scale this up based on missing HP, we can multiply it by the equation of a straight line from:
(hp - 1, mult) = (0, 2)- i.e. 200% damage at 1 HP; to(hp - 1, mult) = (maxHp - 1, 1)- i.e. 100% damage at max HP.
mult = intercept + (hp - 1) * gradient
= 2 + (hp - 1) * (1 - 2) / (maxHp - 1)
= 2 - (hp - 1) / (maxHp - 1)A few quick checks:
- At HP = 1, the multiplier is
2 - 0 / (mhp - 1), i.e.2. - At max HP, the multiplier is
2 - (mhp - 1) / (mhp - 1), i.e.1. - If HP = 50 and max HP = 99, the multiplier is
2 - 49 / 98, i.e.1.5.
(a.atk * 4 - b.def * 2) * (2 - (a.hp - 1) / (a.mhp - 1))Edit:
Oops, I misread the original post as more damage when the target is missing hp, not user. Sorry 🤣
To be fair to my stupidity...you might have seen everything in the formula I typed referencing
To be fair to my stupidity...you might have seen everything in the formula I typed referencing
b 😛Oh I see, so would I just replace all instances of "b" in the formula to "a"?
Use the formula caethyril provided.
I actually like this formula, but it doesn't quite do what I'm looking for when I use the skill. Do you know if it would be able to do the same effect except the opposite, so 200% extra DMG at Max HP, and it decreases as the user's HP gets lower?
Never mind, code works perfectly fine. The variance was just to high
Great!
I spotted a potential divide-by-zero problem if the user's max HP = 1. Here's a safer version:
I.e. "if user's max HP is equal to 1, use a multiplier of 2, otherwise calculate the multiplier based on user HP". You don't have to use this one if you're certain the user will never have 1 max HP.
Happy RPG Making~ 👋
I spotted a potential divide-by-zero problem if the user's max HP = 1. Here's a safer version:
(a.atk * 4 - b.def * 2) * (a.mhp === 1 ? 2 : 2 - (a.hp - 1) / (a.mhp - 1))I.e. "if user's max HP is equal to 1, use a multiplier of 2, otherwise calculate the multiplier based on user HP". You don't have to use this one if you're certain the user will never have 1 max HP.
Yes, you can follow the same approach as I outlined in the spoiler. The differences would be:
intercept = 1(100% damage at 1 HP).gradientis positive (multiplier increases as HP increases).
(a.atk * 4 - b.def * 2) * (1 + (a.hp - 1) / (a.mhp - 1))Happy RPG Making~ 👋
Thank you so much, works perfectly.
Original thread: https://forums.rpgmakerweb.com/threads/skill-that-does-more-damage-for-every-quarter-hp-missing.157022/