Flat Minimum Damage?

Hello, I've been trying to make some attacks to do Minimal damage, however, it seems the damage formula saves negative damage, so even if I have a formula like this (a.atk - b.def)+10 it wont work. I did several tests
Hero has 50 attack, Enemy has 100 defense.

(a.atk - b.def)+10 = 0 damage
(a.atk - b.def)+55 = 5 damage

So it seems the formula saves negative values

Is there a way to make a formula that does minimal damage after parameter calculations?
I was wondering if there is way to put conditions (if), so if the damage is below zero, turn it into zero and add 10 but I don't have enough knowledge in the engine.

Anyone has any idea? Thank you in advance (sorry for my english)
Try this:

Math.max(a.atk - b.def, 10)
I.e. "return a.atk - b.def or 10, whichever is larger".

Note that if the Skill/Item has a Variance, that is applied after the damage formula. Other factors like element rates are also applied after the formula.
Yes, that worked, Thanks a lot!
Note that max returns the bigger number, if you want "damage formula, or 100 minimum" use math.min, as it will return the lowest of the two in case something like player def mitigates the damage and ends up either negative or lower than your intended minimum damage.

You can also use percentages of health with the max/min function in case you want a set attack or skill do a maximum of 25% of the target's hp as damage for example which would be expressed as (a or b .mhp*0.25)
if you want "damage formula, or 100 minimum" use math.min, as it will return the lowest of the two in case something like player def mitigates the damage and ends up either negative or lower than your intended minimum damage.
I'm not sure if this is a typo? As I stated, use Math.max(value, cap) for a lower bound:
  • If value < cap it should return cap (larger value);
  • If value ≥ cap it should return value (larger value).
Similarly for an upper bound: use Math.min(value, cap).

My original suggestion can be written as an if-else instead if you prefer, e.g.

var r = a.atk - b.def; r < 10 ? 10 : r
if (a.atk - b.def < 10) 10; else a.atk - b.def

Original thread: https://forums.rpgmakerweb.com/threads/flat-minimum-damage.153092/