# Can't make a skill do minimum amount of damage.

#### Mr. Detective

##### NATO Special Operative
This is the formula for a skill for an enemy: 10 + (a.atk * 1.15 - b.def).

So, I want the enemy to do at least 10 damage every time it attacks a character. This is to ensure that no matter how high a character's defense stat is, they'd still take damage. Sounds simple, but strangely enough, I keep getting 0 damage on a particular character with high physical defense.

What did I do wrong here? What am I missing?

Stats, in case you need them: Enemy = 21 ATK; MC = 42 DEF.

#### Ouro

##### Veteran
Skills can default to doing 0 damage if there's something wrong with the damage formula. Try 10 + ((a.atk * 1.15) - b.def) and see how that goes?

#### Zevia

##### Veteran
As you mentioned, if the defense is high enough, the 10 isn't enough to offset the final number. Using your stats, if we have: 10 + (21 * 1.15 - 42), then we get 10 + (24.15 - 42), which is 10 + (-17.85) which is -7.85, which ultimately is less than 0, so 0 damage.

Code:
``const damage = 10 + (a.atk * 1.15 - b.def); damage < 10 ? 10 : damage;``

We create a formula that says, "If 10 + (a.atk * 1.15 - b.def) is less than 10, then do 10 damage. Otherwise, do the result of the formula."

So try using an inline ternary as mentioned above.

A ternary is a conditional statement that takes three expressions:
1. An expression that evaluates to either true or false
2. A statement that will run if 1 evaluates to true
3. A statement that will run if 1 evaluates to false

And it's written as 1 ? 2 : 3. So if 1 is true, run statement 2, otherwise, run 3. So what we do is say, "Take the number generated by running 10 + (a.atk * 1.15 - b.def)", then say, "If the resulting number is less than 10" (true), "use the number 10" (2), otherwise (false), "use the resulting number".

#### ATT_Turan

##### Forewarner of the Black Wind
As Zevia said, if you simply plug the numbers into your formula and do the math, you'll see how you're getting less than 10 damage.

The solution above will work perfectly, but I'll give a more compact one:
Code:
`` Math.max(10+(a.atk*1.15-b.def), 10)``

#### Mr. Detective

##### NATO Special Operative
As you mentioned, if the defense is high enough, the 10 isn't enough to offset the final number. Using your stats, if we have: 10 + (21 * 1.15 - 42), then we get 10 + (24.15 - 42), which is 10 + (-17.85) which is -7.85, which ultimately is less than 0, so 0 damage.

So that's how it works. XD I didn't know the engine takes negative number, so I thought if the defense is higher than attack, the result will just be 0. So 0+10 will be at least 10 damage. I'll have to be more careful with damage formula from now on, now that I know this.

Thanks everyone for the help!

#### ATT_Turan

##### Forewarner of the Black Wind
I didn't know the engine takes negative number, so I thought if the defense is higher than attack, the result will just be 0.
It doesn't take a negative number, it does exactly what you describe. That's why the equation you typed in was being turned into 0.
So 0+10 will be at least 10 damage.
Except the part of the equation you're typing as 0 wasn't 0. It was -17.

There's nothing special about the words a.atk or b.def, they're just numbers doing normal math.

The code has no way to know there are specific places you want to create a limit of 0 unless you tell it - if you follow your original damage formula as actual, regular math, you would not get a result of 10.

#### Arctica

##### Veteran
For your formula to work as is, you'd have to use a bigger multiplier, but this doesn't account for the possibility that you create a mob with a defense that'll still exceed the attacker's strength.

### Latest Profile Posts

My first serious victim in game hacking - Pawnbarian.

I love these two design wise lol... The high school principal and the captain of the women's wrestling team. they team up as bosses to save the school's accreditation.
I love your profile pic. Definitely one of my favorite scenes from OPM
Had a funny feeling about my laptop last night so I moved my project over to desktop via thumbdrive, just experienced my first corrupted project and couldn't be happier about the timing!! *proceeds to copy file onto every thumbdrive in the house*