addState() in Damage Formula Calculates the Damage Incorrectly?

hi! i have a question regarding strange results in the damage calc. i have the following:

if (b.elementRate(2) > 1) {((20+a.mat)/2) - (b.mdf/4) + b.addState(11); 100} else {((20+a.mat)/2) - (b.mdf/4)}

and it does exactly what i want it to do—inflict a status upon hitting an elemental weakness. however, for some reason, the damage that is dealt is somewhere around 700% of what it should be. for reference, the elemental weakness is set to 150%, the attacker has a MAG of 21, and the opponent has a MDF of 20. when the state is inflicted, all damage is increased by a further 125%, but this shouldn't apply on the first turn.

i should be dealing ~25 damage, but i end up getting ~180 damage when testing. is my syntax incorrect? even factoring in all of the damage mods, i should only be maxing out near 32. i suspect that the "100" for the addState() may be confusing the calculation. any ideas?

thank you ahead of time! 🙂
The 100 is definitely the primary source of the issue. But I don't quite know what to suggest to you, because I'm confused about why it's even there in the first place. I don't mean that in a flippant way. I just mean that I don't have a clue of what your intentions were by putting the 100 there, so it's hard to tell you precisely how to fix your formula.

In a damage formula, if you have a semicolon, then whatever is to the right of that semicolon is going to be the actual final result of the formula. The stuff to the left of the semicolon gets discarded.

So if my formula is:
Code:
a.atk * 4 - b.def * 2; 100

Then the skill is going to do 100 damage. The calculations to the left of the semicolon won't count for anything.

So when your elemental condition evaluates to true, it's doing some pointless calculations, adding the state, and then returning a final result of 100.

Also, you don't want to generally include addState as part of your actual calculation. As in, you shouldn't use "+ b.addState". It should be in it's own expression, followed be a semicolon, and then followed by your actual formula.

Excluding the 100 part (since I don't know what you were going for with that), and removing some redundant parts, your damage formula should probably look something like this:
Code:
if (b.elementRate(2) > 1) b.addState(11); ((20+a.mat)/2) - (b.mdf/4)

Though it's very possible that I've got syntax errors in there, since I'm posting this from my phone.
The 100 is definitely the primary source of the issue. But I don't quite know what to suggest to you, because I'm confused about why it's even there in the first place. I don't mean that in a flippant way. I just mean that I don't have a clue of what your intentions were by putting the 100 there, so it's hard to tell you precisely how to fix your formula.

In a damage formula, if you have a semicolon, then whatever is to the right of that semicolon is going to be the actual final result of the formula. The stuff to the left of the semicolon gets discarded.

So if my formula is:
Code:
a.atk * 4 - b.def * 2; 100

Then the skill is going to do 100 damage. The calculations to the left of the semicolon won't count for anything.

So when your elemental condition evaluates to true, it's doing some pointless calculations, adding the state, and then returning a final result of 100.

Also, you don't want to generally include addState as part of your actual calculation. As in, you shouldn't use "+ b.addState". It should be in it's own expression, followed be a semicolon, and then followed by your actual formula.

Excluding the 100 part (since I don't know what you were going for with that), and removing some redundant parts, your damage formula should probably look something like this:
Code:
if (b.elementRate(2) > 1) b.addState(11); ((20+a.mat)/2) - (b.mdf/4)

Though it's very possible that I've got syntax errors in there, since I'm posting this from my phone.
yes, that worked perfectly. thank you so much! my monkey brain thought i needed the 100 at the end to denote a 100% chance to inflict the status condition, but it didn't occur to me that not specifying would just default to a 100% chance.
yes, that worked perfectly. thank you so much! my monkey brain thought i needed the 100 at the end to denote a 100% chance to inflict the status condition, but it didn't occur to me that not specifying would just default to a 100% chance.
addState does not in fact take any parameter besides the state ID; if you want a percentage chance, you need to generate a random number and compare it to a threshold value first.
I am confused... b.addState(11) is a value? And if so, what is the value?
Maybe I am wrong, but it seems to me like it says:
12 - 4 + turn on the light = ?

If that is there just to add the state, then it should be separate from the damage formula. Maybe something like this:

if (b.elementRate(2) > 1) {b.addState(11)} ; if (b.elementRate(2) > 1) {((20+a.mat)/2) - (b.mdf/4)} else {((20+a.mat)/2) - (b.mdf/4)}

I did not test this formula out.

Edit: Oh never mind. Ahtran already game you the right formula. It's little different from mine, but since I didn't test mine, and theirs seem to work, theirs is probably the right one.

Original thread: https://forums.rpgmakerweb.com/threads/addstate-in-damage-formula-calculates-the-damage-incorrectly.149653/