# Flat Minimum Damage?

#### Quet

##### Villager
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)

#### caethyril

##### ^_^
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.

#### Quet

##### Villager
Yes, that worked, Thanks a lot!

#### BK-tdm

##### Waifumancer
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)

#### caethyril

##### ^_^
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`

### Latest Profile Posts

In twitter, square phoenix had successfully prompted chatgpt to make the mini game watermelon pangpang.

drew some stuff to see how frontview might look. not entirely sold on or off of it yet. "could" work, but something feels missing.
Shower Thoughts: ". . . Scammers would be OP in the Elder Scrolls. They could just get speech 100 and blatantly ask everyone for all of their money, and everyone would think it's a great investment. And then after being robbed blind, they'd say, with a smile on their face, 'need something?' "
Day #2 for advent is compiled. Please, go to their threads to share love! But, if you wanna talk to me…what’s your favorite Christmas carol or holiday song?

136,693
Messages
1,268,822
Members
180,406
Latest member
General_Melt