Damage formula syntax

Hi all—

I did some research on calculating damage formulas and wanted to try out something different besides the default attack formula. I have two variables set aside for Damage and Damage Modifier. The first line calculates the damage, the second line calculates the mod, and the third line calculates the final damage.

v[21]=(a.atk - b.def) * 100;v[22]=100 - (v[21] * .0002);v[21] * v[22] / 100

I do a battle test and it doesn't seem to work. Everyone's attacks are doing quintuple-digit damage. Would someone please tell me what's wrong with this formula? Thank you.
The problem is... your formula. The syntax is correct. Your formula seems to be asking for damage numbers in the thousands.

v[21]=(a.atk - b.def) * 100;v[22]=100 - (v[21] * .0002);v[21] * v[22] / 100

Assume a.atk is 100 and b.def is 50.

Var 21 is set to (100 - 50) * 100 = 5000.
Var 22 is set to 100 - (5000 * 0.0002) = 100 - 1 = 99.
The final damage formula is Var 21 * Var 22 / 100 which is 5000 * 99 / 100 = 4950.

With numbers like a.atk = 250 and b.def = 100, your formula would result in 14550 damage.

I would ask why your "damage modifier" (Var 22) is such a wimp. Even in the case where Var 21 is quite big (15000), Var 22 only modifies the final number by 3%. In the first example, where Var 21 was 5000, it only modified it by 1%. It's almost as if the second and third clauses of your damage formula are there just for extra complexity; the end result is always going to be very close to what it would be if your formula were a much simpler (a.atk - b.def) * 100
Thanks! I see your point. I noticed another RPG had a damage mod like that. I'd rather do away with it and simplify if it's that pointless. That being said, is this how I would cap damage at 9,999?

if { (a.atk - b.def) * 10 <= 9999 } else { 9999 }
You can do min(damage goes here, 9999)

min() is a function that returns the lowest between 2 numbers. If your damage goes above 9999, you'll get 9999 as a result

(I'm not too familiar with MV's scripting language so someone correct my syntax if its wrong)
You can do min(damage goes here, 9999)

min() is a function that returns the lowest between 2 numbers. If your damage goes above 9999, you'll get 9999 as a result

(I'm not too familiar with MV's scripting language so someone correct my syntax if its wrong)

Thanks! That did it. RMMV likes to specify with adding "math" in front of it, so:

Math.min((a.atk - b.def) * 10, 9999)
Thanks! I see your point. I noticed another RPG had a damage mod like that. I'd rather do away with it and simplify if it's that pointless. That being said, is this how I would cap damage at 9,999?

if { (a.atk - b.def) * 10 <= 9999 } else { 9999 }

Not quite. The best way to do this is with a "min" function, like you have above, but if you wanted to use an if/else branch, here's how it's done:

if (condition) { statement_or_formula_if_true } else {statement_or_formula_if_false}

Your if/else won't work properly because you've placed the condition inside where the if_true section is supposed to be, and you don't have a statement or formula to run if it evaluates to true. (You might also need semicolons where lines would normally break, but I'm not sure whether if/elses require them - I think the syntax is legal without them.)

From a design point of view, I really recommend thinking through your damage formula and how it will affect everything in the game, like which stats will be more advantageous to build, how many hits enemies will take to defeat, and what the effects of slight over/underleveling of characters will have on the difficulty of battle. If your formulas are arbitrary and don't have a lot of thought behind them, the rest of your content will become literally impossible to balance well.

For some more extensive reading about designing good damage formulas, you can search through the Game Mechanics Design subforum for topics that tread on the topic. To give you a head start, here are a few of the topics on the issue that I've posted in: A B C
Not quite. The best way to do this is with a "min" function, like you have above, but if you wanted to use an if/else branch, here's how it's done:

if (condition) { statement_or_formula_if_true } else {statement_or_formula_if_false}

Your if/else won't work properly because you've placed the condition inside where the if_true section is supposed to be, and you don't have a statement or formula to run if it evaluates to true. (You might also need semicolons where lines would normally break, but I'm not sure whether if/elses require them - I think the syntax is legal without them.)

From a design point of view, I really recommend thinking through your damage formula and how it will affect everything in the game, like which stats will be more advantageous to build, how many hits enemies will take to defeat, and what the effects of slight over/underleveling of characters will have on the difficulty of battle. If your formulas are arbitrary and don't have a lot of thought behind them, the rest of your content will become literally impossible to balance well.

For some more extensive reading about designing good damage formulas, you can search through the Game Mechanics Design subforum for topics that tread on the topic. To give you a head start, here are a few of the topics on the issue that I've posted in: A B C

This is great! Many thanks. After some research, I've come up with simple yet steady one I like:

Math.min((a.level * a.mat) * x / b.mdf, 9999)
x = skill strength (5, 10, and 20 are good tiers)

Level matters, buffs still matter, and skills can scale and not become obsolete. What do you think?
Looks like a pretty good formula; the only thing I'd say to watch out for is that if MAT already increases with each LEVEL you earn, then you are setting up an exponentially-scaling formula that will be difficult to balance at high levels (consider how 5*5 = 25, but 6*6 = 36 which is a ~40% increase in the total when each factor increased by just 20%). On the other hand, if level and magic-attack do not automatically increase in synch with each other, your formula will do a good job of considering both so that they player can't just go hard in one and ignore the other.

Also, How would I apply the 9,999 cap to this?

Math.min(((a.level * a.mat) * 32 / b.mdf), 9999)

One thing to note - capping damage inside the formula itself will cap the calculated damage, but the actual damage done can exceed that cap based on elemental weaknesses (element rate), critical hits, damage variance (if above 0), etc. If you want to cap the actual damage done, this will require either a plugin or modifications to the game's base scripts. I think that Yanfly's Damage Core is one such plugin that will allow you to do it this way.

Original thread: https://forums.rpgmakerweb.com/threads/damage-formula-syntax.87230/