Can I do this in the damage formula?

Or would I need a plugin?

In addition to the regular ATK - DEF as the base damage of a skill, I want to factor in two other parameters into the formula. But I want them to work kind of like based on a ratio.

For example, let's say I also want to compare a.agi and b.luk. The higher the difference between a.agi and b.luk, the damage should increase, up to about 4x when a.agi is double or more than b.luk. And conversely, the higher the difference between b.luk and a.agi, the damage should decrease, up to about 75% when b.luk is double or more than a.agi.

So if the attacker has 100 agility and the target has 50 luck, the base damage (ATK - DEF) should increase by 200%. If the attacker has 50 agility and the target has 100 luck, the base damage (ATK - DEF) should decrease by 75%.

Is there a dmg formula that can do this, and if so, what would it be? Thank you so much in advance.
I think this could be achieved by using the Math.pow() function.
If you consider the damage formula bar like an equation, you want the damage to increase exponentially the greater the difference between agility and luck. So you could try squaring the difference between these two stats.

(a.atk - b.def) * Math.pow((a.agi / b.luk), 2)

In this case, for a.agi =100 and b.luk = 50 it should return 4 (400%)
For a.agi = 50 and b.luk = 100 it should return 0.25 (25% = 75% reduction)

You can cap it at 400% and 25% using Math.min and Math.max functions:

(a.atk - b.def) * Math.min(4, Math.max(0.25, (Math.pow((a.agi / b.luk), 2))))

(I haven't tested this so might not work but I think this is along the lines of what you are looking for?
Yeah, that is totally possible with only the damage formula. Give me a minute, I need to start up my internal calculator (a.k.a. my brain).
anything you can do in a mathematical formula or in coding itself can be done in the damage formula.
what can't be done there are either things not describable as a mathematical formula, or things that require time to pass.

The higher the difference between a.agi and b.luk, the damage should increase, up to about 4x when a.agi is double or more than b.luk.
This can be read as examples for both cases.

You can easily design formulae where the ratio or difference between a.agi and b.luk increases the damage done - for example (base) *a.agi/b.luk as one of many options.

You cannot mathematically describe conditions like "but the increase should stop at 4x".
There are coding commands that can do that, but that adds entire code sequences to the damage formula, especially if there are multiple conditions (like adding 75% minimum in the other direction).

Such kind of coding would quickly extend beyond the space available in the damage formula, but a plugin could provide functions that do the same for less letters in the script.


EDIT: the code answer above was edited in later and not visible when I wrote this, but basically demonstrates my points - the code functions for the limiting make the formula much longer.
And they still didn't fulfill all of the above description because the original specification was that at 100/50 the factor should be 2, not 4, and only the cap would be higher at 4x but not with those specific values. But if the power function is removed the numbers for the lower limit no longer fit.

getting everything to that example is not as easy as that first try.
Sure, you're just talking math. Converting one number scale to another is called linear interpolation.

This article has a bunch of JavaScript functions handily written out for you. You could try to reverse engineer and write them all out to paste into your damage formula, but it'll be way easier if you take the four functions (lerp, clamp, invlerp, range), paste them into a *.js file, then include it in a plugin.

Then, in your damage formula, you would simply call
Code:
(a.atk-b.def)*range(b.luk, a.agi, .75, 2, a.agi/b.luk)*range(a.luk, b.agi, .75, 2, b.agi/a.luk)

You may want to mess around with whether you actually want both of those to multiply your base damage, as you initially said, or whether you want to add them together to get the value you multiply by.
Did any of the above formula's did the trick for you? Cause than I won't even start working on a formula myself. 😛

Original thread: https://forums.rpgmakerweb.com/threads/can-i-do-this-in-the-damage-formula.145256/