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

Mr. Detective

NATO Special Operative
Veteran
Joined
Sep 9, 2012
Messages
1,034
Reaction score
494
First Language
English
Primarily Uses
N/A
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?
32


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

Thanks in advance!
 

Ouro

Veteran
Veteran
Joined
Aug 4, 2019
Messages
115
Reaction score
219
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Aug 4, 2012
Messages
673
Reaction score
397
First Language
English
Primarily Uses
RMMV
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.

Instead, if we do:
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
Veteran
Joined
Jul 2, 2014
Messages
4,122
Reaction score
2,519
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Sep 9, 2012
Messages
1,034
Reaction score
494
First Language
English
Primarily Uses
N/A
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!
007.gif
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,122
Reaction score
2,519
First Language
English
Primarily Uses
RMMV
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.

Good luck with your project!
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
159
Reaction score
256
First Language
English
Primarily Uses
RMMZ
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 Threads

Latest Posts

Latest Profile Posts

My first serious victim in game hacking - Pawnbarian.
Diana Path 2.png
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.
Kanori24 wrote on TheRamenGirl's profile.
I love your profile pic. Definitely one of my favorite scenes from OPM :D
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*

Forum statistics

Threads
122,074
Messages
1,146,302
Members
160,359
Latest member
TheRagingKing
Top