Deal a minimum of 1 damage.

Hello friends, I'm looking for a way to make skill damage deal a minimum of 1 damage, similar to how in DQ Metal Slimes take damage.

I have tried several things and researched a little, but I am very lost and the truth is that I don't know where I can go to find a guide or tutorial that explains the basics.

Some help?

1703844269415.png
You might find this thread useful.
But in short, Math.max(1, a.atk * 4 - b.def * 2)
simplest way is something like: (a.atk - b.def) +1 (wont work) see other 2.

another way is: formulaA > 1 ? formulaA : 1

more ways is: Math.max(1, a.atk * 4 - b.def * 2)

or use a plugin found [here].
You might find this thread useful.
But in short, Math.max(1, a.atk * 4 - b.def * 2)
Thanks you a lot!!
simplest way is something like: (a.atk - b.def) +1
That doesn't work.
(10 - 50) + 1 = -39
That doesn't work.
(10 - 50) + 1 = -39
if you put it this way in extreme measures, I can agree a lot, but it's also
a way I wont go myself, as a plugin that does it will always work, but I think you
need to check if the value is lower than 0 to output 1 as in the 2nd sample.

if the player is overpowered, than it never work the way as given (my bad).
but personally, I go for the plugin as you don't have to make the checks =)
so whatever formula is given, it always out put 1 for both sides.
if you put it this way in extreme measures, I can agree a lot, but it's also
a way I wont go myself, as a plugin that does it will always work, but I think you
need to check if the value is lower than 0 to output 1 as in the 2nd sample.
I'm sorry, I just don't understand the English here. The example doesn't have to be extreme - your formula will not do what the OP asked in any situation unless the ATK and DEF are exactly the same number.

The other two examples you gave are correct, and they are the only way to answer this question - you must use code.

There's no way to use just math and say "have a minimum of 1".

(well, maybe if you get into specific combinations of exponential and logarithmic whatever, I'm not a mathematician. But I think that's more complicated than a simple function call)
I corrected it 🙂 but I can agree, mathematician in JS is complicated for me.
so I gave what came up in mind.
mathematician in JS is complicated
again, it has nothing to do with javascript.
it doesn't work in ANY mathematics, including using pen and paper to calculate.
(well, maybe if you get into specific combinations of exponential and logarithmic whatever, I'm not a mathematician. But I think that's more complicated than a simple function call)
It doesn't actually need to be that complicated: ((a+b)+|a-b|)/2 will be equal to either a or b, whichever is greater (not that this is very useful here 😛 ).
It doesn't actually need to be that complicated:
I'd say bitwise is technically a logical operator, not a mathematical one, so it falls into the first part of my post saying you need to use code 😉

At which point, yes, there are multiple methods of implementation.
But in short, Math.max(1, a.atk * 4 - b.def * 2)
Note that it is still possible to receive 0 damage with this approach, since other things apply after the formula is evaluated, e.g. element rate, physical/magical damage rates (PDR/MDR), and guard effect (GRD). I imagine that is what's wanted, but if not, then a plugin may be needed for more control.

I'd say bitwise is technically a logical operator, not a mathematical one
There's no bitwise-or there. Mac wrote |a-b|, which is pretty standard mathematical notation for the absolute value, i.e. Math.abs(a-b) in JS. It's a piecewise function, so you'd end up with 2 cases:
  • a ≥ b: (a + b + (a - b)) / 2 = 2a / 2 = a
  • a < b: (a + b + (b - a)) / 2 = 2b / 2 = b
Like ShadowDragon mentioned, JS has notation to more concisely express this: a > b ? a : b. The logic is identical to Mac's first reply, which uses Math.max.
There's no bitwise-or there. Mac wrote |a-b|, which is pretty standard mathematical notation for the absolute value
That must be math I didn't do, because I've never seen that in math 😛

In a damage formula (JavaScript), the pipe is the bitwise OR operator.

That might not be what Mac was intending to notate, but it was my feeble understanding.

Original thread: https://forums.rpgmakerweb.com/threads/deal-a-minimum-of-1-damage.164251/