# Damage Formulas 101

#### ThreeSixNine

##### Veteran
I think I may not have properly explained what the goal was, but I may have gotten the answer I needed.

If the attack hits, it's supposed to deal damage, then apply a debuff to evasion. However, I didn't think to use a state to lower evasion, which would make doing this a bit easier (unless I'm wrong, but I'm open to learning). I'm gonna try going with applying a state that changes the evasion rate of the affected enemy.
I actually misspoke when I said the state would be added to the target and then the damage would be calculated.

If you check out the flow chart above, you'll see how each step is processed and when. States are added/removed after the damage is done, but must be processed before the actual damage calculation.

The above code:
`b.addState(369); 200 + a.mat * 2 - b.mdf * 2`
should work, just replace 369 with the ID of your evasion reducing state.

#### UmbrotheUmbreon

##### Legendary Umbreon
I actually misspoke when I said the state would be added to the target and then the damage would be calculated.

If you check out the flow chart above, you'll see how each step is processed and when. States are added/removed after the damage is done, but must be processed before the actual damage calculation.

The above code:
`b.addState(369); 200 + a.mat * 2 - b.mdf * 2`
should work, just replace 369 with the ID of your evasion reducing state.
Yeah I used the code you provided and it works fine. Is there a way to add to it further, like including a state with a percentage chance to be applied?

#### Trihan

##### Speedy Scripter
Yeah I used the code you provided and it works fine. Is there a way to add to it further, like including a state with a percentage chance to be applied?
If you wanted to do that, you could include a check against a random number. For example say you wanted a 15% chance of applying the state:

JavaScript:
``if (Math.randomInt(100) >= 85) b.addState(369); 200 + a.mat * 2 - b.mdf * 2``

One thing to note about this method which people tend to not know/forget (and Yanfly wrote an article about it a long time ago) is that if you use Autobattle at all in your game, it's better to do it a different way. The reason being when a battler is determining which of their actions to use, they actually evaluate the damage formula to figure out what's best, meaning in this case that their "test" enemies would end up having the state applied even if that action ends up not being used.

#### UmbrotheUmbreon

##### Legendary Umbreon
If you wanted to do that, you could include a check against a random number. For example say you wanted a 15% chance of applying the state:

JavaScript:
``if (Math.randomInt(100) >= 85) b.addState(369); 200 + a.mat * 2 - b.mdf * 2``

One thing to note about this method which people tend to not know/forget (and Yanfly wrote an article about it a long time ago) is that if you use Autobattle at all in your game, it's better to do it a different way. The reason being when a battler is determining which of their actions to use, they actually evaluate the damage formula to figure out what's best, meaning in this case that their "test" enemies would end up having the state applied even if that action ends up not being used.

What I currently have going is the skill has two effects to it. A chance to stun, and a guaranteed evasion debuff. The stun effect is in the effects part, but I saw no way to apply an evasion debuff there. That's why I originally came here to figure out how to get my skill to apply an evasion debuff if it succeeds. I was curious if it was possible to include both the guaranteed evasion debuff and a chance to stun in the damage formula. As far as auto-battle goes, I don't know if the game I'm going for will include it, since a lot of the game will be based on choices you make throughout it, so not too concerned about that. I'll give that formula a try though, and see how it works.

#### ThreeSixNine

##### Veteran
You should be able to add both through the effects of the skill.
You can also add additional effects through linking a common event to the usage of the skill.

#### Trihan

##### Speedy Scripter

What I currently have going is the skill has two effects to it. A chance to stun, and a guaranteed evasion debuff. The stun effect is in the effects part, but I saw no way to apply an evasion debuff there. That's why I originally came here to figure out how to get my skill to apply an evasion debuff if it succeeds. I was curious if it was possible to include both the guaranteed evasion debuff and a chance to stun in the damage formula. As far as auto-battle goes, I don't know if the game I'm going for will include it, since a lot of the game will be based on choices you make throughout it, so not too concerned about that. I'll give that formula a try though, and see how it works.
Yeah, debuffs only apply to base parameters. You'll have to add a state that inflicts an evasion reduction.

#### UmbrotheUmbreon

##### Legendary Umbreon
I appreciate the help guys. I'm still so new to coding and such. It's quite intimidating but I really wanna learn

#### Solar_Flare

##### Veteran
If you wanted to do that, you could include a check against a random number. For example say you wanted a 15% chance of applying the state:

JavaScript:
``if (Math.randomInt(100) >= 85) b.addState(369); 200 + a.mat * 2 - b.mdf * 2``
I think for readability it's better to reverse that conditional:
JavaScript:
``if(Math.randomInt(100) < 15) b.addState(369); 200 + a.mat * 2 - b.mdf * 2``

#### mkrudesign

##### Villager
Is there a way to set that the minimum amount of damage for a skill as a percent instead of a fixed amount?

For the standard attack skill, the formula I use is: Math.max(a.atk * 4 - b.def * 2,1) So the minimum this skill can do is 1 damage.

The thing is, it gets pretty dumb when enemies who are meant to be intimidating end up hitting for 1 HP if the player becomes over powered. Is there a formula that I can use to make the minimum damage for this skill be, let's say 5% of the target's total health? It would be way easier than having to rebalance the entire game, since mine is open ended.

#### ATT_Turan

##### Forewarner of the Black Wind
Is there a way to set that the minimum amount of damage for a skill as a percent instead of a fixed amount?
Just replace the "1" with whatever equation you want. So, mathematically, 5% of your target's total health is `b.mhp*.05`

Thus, `Math.max(a.atk*4-b.def*2, b.mph*.05)`

#### ScorchedGround

##### Blizzards most disappointed fan (More than ever)
Is there a formula that I can use to make the minimum damage for this skill be, let's say 5% of the target's total health?

You basically just do the exact thing as before, but replace the "1" with the minimum damage you wish for.

e.g.
Math.max(a.atk * 4 - b.def * 2, b.mhp*0.05)

Now, if you asked me, I wouldn't use a % amount because that could get wonky at some points, but rather a flat amount of the attackers stats.
Something like:
Math.max(a.atk * 4 - b.def * 2, a.atk * 0.5)

Edit: Ninja'd

#### mkrudesign

##### Villager
Thank you! I wasn't sure if it was that easy!

#### mkrudesign

##### Villager
You basically just do the exact thing as before, but replace the "1" with the minimum damage you wish for.

e.g.
Math.max(a.atk * 4 - b.def * 2, b.mhp*0.05)

Now, if you asked me, I wouldn't use a % amount because that could get wonky at some points, but rather a flat amount of the attackers stats.
Something like:
Math.max(a.atk * 4 - b.def * 2, a.atk * 0.5)

Edit: Ninja'd
Could you explain the downside to using a % amount? You mentioned things could get wonky. Is there something I'm missing here?

#### Quack

##### Villager
Could you explain the downside to using a % amount? You mentioned things could get wonky. Is there something I'm missing here?
I don't think he was objecting to using a percentage amount, but that it was a percentage of the target's hp.
Sometimes bosses have very high hp so you could potentially end up in a situation where 5% of the target is actually more than the normal attack value before being reduced by target's defense.
If you just want to prevent attack value from getting too low, it might be better to set your "minimum" damage value to a percentage of the normal attack value before it is reduced by defense rather than a percentage of the target's hp.
JavaScript:
``Math.max(a.ath * 4 - b.def, a.atk * 4 * 0.05)``

#### ATT_Turan

##### Forewarner of the Black Wind
I don't think he was objecting to using a percentage amount, but that it was a percentage of the target's hp.
Sometimes bosses have very high hp so you could potentially end up in a situation where 5% of the target is actually more than the normal attack value
I don't know what ScorchedGround's objection was, but the original post for this formula did indicate it's for an enemy skill, so killing bosses too quickly wouldn't be a concern

#### lolotron6

##### Villager
Thank you for all this great info, Skunk!

### Latest Profile Posts

Been playing through Skies of Arcadia again, and it really makes me wanna see someone try to implement how ship battles were done in the game into RPG Maker (or really just in general).

split view of both versions of the pocket city you traverse through. there's differences like areas only being accessible in one version of Autumn Bay. or events that only happen in one or the other.
theortically if there were a developer who spied on people's game playthroughs and changed things in real time to make it harder for them, what might be said game developer's motivation?
Hi everyone! Enjoying this nice long weekend. How are you all doing?
I just successfully tested having events check if specific actors are in a particular party slot and then changing image to match. This will let me make scenes take into account who is in the party at the time and arrange them accordingly - this is important since I'll have extra actors beyond current party. The script used is the same from MV and is compatible with my current core plugin setup in MZ. Thank goodness.