Math Question

I'm trying to make it so defense cuts damage in half every time defense doubles, starting with 200 defense giving 50% damage resistance. My problem is I'm having trouble finding a formula that works well. Usually anything with division causes a headache as damage/(def/100) means that I can't have defense be zero or a low number (it would increase how much damage a player takes). Mathematically alone, I've also been trying things with exponents and even logarithms, but to no avail. I can almost guarantee there is a mathematical formula that will work, but I lack the PhD and experience to figure it out. Any ideas? The numbers might look like this:

Defense 0, 200, 400, 800

Damage Taken 1000, 500, 250, 125
1000 * (0.5)^(b.def/200) should do it. Though which engine? This really should be in engine support as exact details of how to enter it depends on the engine used.
Ruby (VXAce)
Code:
1000 * ((0.5)**(b.def/200))

Javascript (MV/MZ)
Code:
1000 * Math.pow(0.5, (b.def/200))

There
1000 * (0.5)^(b.def/200) should do it. Though which engine? This really should be in engine support as exact details of how to enter it depends on the engine used.

Doesn't work, as when you hit 600 defense, it adds another power, when it should be 800 defense.
Then there isn't a simple way to make what you want work. If doubling the defence halves the damage, then halving the defence will double the damage, and that means very low defence will produce very high damage.

The only thing you could do (unless you decide to change tack and go with bgilisp's formula) is to use an if-then: if defence < 200, use [formula A], if defence > 200 use 100000/b.def.

(I haven't specified what "formula A" would be since the only data point you've given is (0, 1000), which on its own isn't enough to know what the output should be. What output values do you want for defence 50, 100, 150?)
Doesn't work, as when you hit 600 defense, it adds another power, when it should be 800 defense.
So you divide it out by 2 again, to get the multiple of 200, then add one for your starting exponent.

((b.def/200)/2)+ (b.def == 200) ? .5 : 1

You still haven't said which engine you're using. That will work in MV/Z.
See the issue is you set values that *cant* be done as a true exponential by the normal exponential equation. A true exponential would change powers every 200 defense. Not every double of defense. A change to allow 800 to be treated as a power of 3 would also shift the other numbers to no longer match.

Exponential equations use two points to connect. I used the first two. If I use the last two it will be a different equation but not hit the others. You will need to pick one as you got 4 points that do not go together for an exponential equation of the form y = C*a^(x/D). C is the value when x = 0 so that was easy. A is y2/y1 (500/1000 here), D is how far the next point is (200 apart).

This is covered in most precalculus books if curious.

Turans method above appears to work for up to 800, but if you are allowing 1600 def then 1600/200/2 = 4 + 1 = 5, so will be power of 5 not 4, and the current pattern has 1600 is power of 4. So I'd honestly suggest changing it a little instead.

Also engine this is in is required, as this has to be moved to engine support as this part you posted in is for if you should do something not how to do something. If not posted I'll take an educated guess.
Turans method above appears to work for up to 800, but if you are allowing 1600 def then 1600/200/2 = 4 + 1 = 5, so will be power of 5 not 4, and the current pattern has 1600 is power of 4.
You're right, it would have to be some kind of scaling divisor if the defense values can continue past that.

I think the concept is just more complicated than it's worth...the numbers you get from your class and your items can be anything you want, just make them work a different way.
You're right, it would have to be some kind of scaling divisor if the defense values can continue past that.

I think the concept is just more complicated than it's worth...the numbers you get from your class and your items can be anything you want, just make them work a different way.
This. Since the dev controls the values for everything, my suggestion would be to change it to go 600 = the value they have for 800 at the moment, and just change how they hand out DEF. After all they do get to control how much DEF the player has via all the database settings.

The other suggestion is to use the formula they suggested in the beginning and just don't do low DEF values. You can also decide to just start everyone at 200 or something. I've played many a games that did that (example: Most Trails games like Trails in the Sky 2, Cold Steel 2, 3, 4, etc).

Edit: I think it could be done with an exponential within an exponential, but its honestly not worth it. I could probably figure it out eventually but not while in the middle of a 3 week stats class.
Another angle to consider, "Double the defense to halve the damage" gets messy if you think of the situation where you move a defense stat from 0 to 1. Proportionally that an increase of infinity percent which won't work as the OP stated clearly we want a formula that can handle defense values of zero
Another angle to consider, "Double the defense to halve the damage" gets messy if you think of the situation where you move a defense stat of 0 to 1.
You're not wrong, but by default in RPG Maker you can't have a parameter of 0. So a dev would have to specifically choose to create that situation.

Edit: Which I now see was mentioned in the OP. So...that 😛
If curious, this is why I did this for my division formula:

(attack formula here)/(b.def + 20).

That +20 in the denominator makes sure it never goes to 0 there, as at worst, you will be divided by 20.
at worst, you will be divided by 20.
Yes, I think it would be quite bad if I were divided by 20. That's worse than being drawn and quartered.
Thinking about it, I think I will do damage resistance equals def/4. This will allow me to have 100 def give 25% resistance at lv. 1, and will allow me to have 50% resistance with 200 defense (cap at 50% for armor). I'll also add in a level scaling feature so that more defense is needed per level to keep the same amount of resistance. This will allow me to balance offensive and defensive equipment easier mathwise. I can always have spells cut damage in half multiplicatively, as that will still allow me to stack less damage taken.

Original thread: https://forums.rpgmakerweb.com/threads/math-question.164551/