# Damage Formulas 101

#### ScorchedGround

##### Blizzards most disappointed fan (More than ever)
@Indinera
I don't really like using ternary operator in my formulas, they look ugly and disorganized.
I rather use normal JS formatting

Your formula would look like this then:

JavaScript:
``c=a.atk-b.def; if (a.hpRate() < 0.3) {250 + 4*c} else if (a.hpRate() < 0.5) {4*c} else {c}``

If you really don't use the formula in this way, you can just use your own formula and test it out.
The numbers won't lie.

#### Indinera

##### Indie Dev
Thank you, saving this for future reference in case I bump into an issue.
Ternary formulas look ugly but they are very compact, which is something I like.
I don't like having to scroll through a long formula with a box so small it displays like 20% of it at once.

#### Flauschifluff

##### Warper
Hello. So, I can't seem toget the Variables working properly. The Formula is this:

60 + (a.atk * (a.level * 0.2) + a.luk) * (1 + v[2]) - b.def * 5

Everytime used the variable 2 will be changed, a random number between and including 0 and 9.
Could there be difficulties if the variable isn't defined yet?
While writing this edited the event slightly, it now works on the second use onward. Might be unlucky RNG rolls but it seems to be very close.
A normal Attack without the multiplication of 1 + v[2] deals around 50 damage and all rolls i got so far was just ranging between 50 and 70, that could be within the 20% variance couldn't it?

#### emelian65

##### Veteran
Hello, it may be weird to ask, but is there an actual way to use, something like the Evation rate in the damage formula, I was thinking in something simple as a.eva, but I think is not a flat number but a percentage (if the system actually has a way of finding the eva value for actor and enemy), I dont0 want to to be a hit or miss just a suimple damage, is it possible?

#### ScorchedGround

##### Blizzards most disappointed fan (More than ever)
@emelian65
You can use all parameters in the damage formulas.
However, most of them are not actually processed as % numbers, but rather decimals.

Basically,
100% evasion rate translates to 1.
50% evasion rate translates to 0.5.

So you could do something like

(a.hit * 100) to convert the decimal back to the % number.

Here is the list of all parameters you can use:

Base Parameters

mhp - max hp
mmp - max MP
atk - attack
def - defence
mat - magic attack
mdf - magic defence
agi - agility
luk - luck

Extra Parameters (Default Value is 0 -> 0%)

hit - Hit rate
eva - Evasion rate
cri - Critical rate
cev - Critical evasion rate
mev - Magic evasion rate
mrf - Magic reflection rate
cnt - Counter attack rate
hrg - HP regeneration rate
mrg - MP regeneration rate
trg - TP regeneration rate

Special Parameters (Default Value is 1 -> 100%)

tgr - Target Rate
grd - Guard effect rate
rec - Recovery effect rate
pha - Pharmacology
mcr - MP Cost rate
tcr - TP Charge rate
pdr - Physical damage rate
mdr - Magical damage rate
fdr - Floor damage rate
exr - Experience rate

Last edited:

#### arkantos

##### Villager
Hi, Can anyone give me some guidance? I want to make a skill similar to the knights of FFT, where they broke parts of the equipment. (swords, armor, etc).

#### ATT_Turan

##### Forewarner of the Black Wind
Hi, Can anyone give me some guidance? I want to make a skill similar to the knights of FFT, where they broke parts of the equipment. (swords, armor, etc).
This has nothing to do with a damage formula. This would be accomplished by placing a state on the target, or calling a common event, or using an action sequence (I'd do it there).

Last edited:

#### Corporal_Siva

##### Warper
I'm trying to make an attack that deals more damage the less HP a user has, but it won't seem to work for me. This is the formula I'm using.

a.mhp/a.hp*30*a.atk/b.def < 200*a.atk/def ? a.mhp/a.hp*30*a.atk/b.def : 200*a.atk/b.def;

#### Solar_Flare

##### Veteran
For starters, you have one `def` that's missing the `b.` in front of it.

Even with that fixed, I think your formula does the opposite of what you want. If I recall correctly, there is `a.hpRatio()` which is just another way to write `a.mhp/a.hp`, but unless I'm missing something, what you actually need here is `(1 - a.hpRatio())`.

#### TheGentlemanLoser

##### "And when we fall, we will fall together..."
Hey, so this one's pretty tricky and I have no idea if it's even possible, honestly.

I'm using SRD's Timed Attack w/ the Timed Attack Arrows feature. The plugin created a new (variable? argument? what is the correct terminology for this I'm hopeless) for use in damage formulae, \$gameTemp.tas_power which returns a result between 0 and 1, meaning an attack would deal full damage with a perfect input and 0% with a fail. I wasn't crazy about that but it was very easy to modify, I just used (\$gameTemp.tas_power + 0.5) so that a failure does half damage and a success does 1.5x damage, easy peezy.

So that's better, but I have a feeling what I *really* want to do will be harder, if it's possible. Is there anything I can write in the formula bar to make it check if \$gameTemp.tas_power = 1 and if it is, initiate a followup skill (also identified in the formula bar and probably the same skill)? So if you're "on beat" with the button presses, you can keep spamming the attack as long as you have the resources to activate the skill and don't miss an input.

I have VE_BasicModule and VE_FollowUpSkills installed but turned off and not yet config'd, because I'm not sure if VE_FollowUpSkills can be made to work with this weird idea I have.

Another question, would math.min(actualdamageformulahere, b.hp-1) result in a damage expression that can reduce the target to 1HP but not actually kill them, i.e. a "nonlethal" skill? Suppose that's easy enough to test, although that's for a different project I'm not actively working on atm so couldn't hurt to ask.

#### miragewolf

##### Villager
Hi, how would I be able to emulate D&D multi attack with this, such as +20/+15/+10 to hit?

It seems the formula would read lie this.

But a.atk-b.def; a.addstate(x); would result in error aka 0 point damage

(x state is the penalty from first attack), haven't succeeded in making another attack after first debuff

Also the game crashes if I've Yanfly's damage core on with the below formula. Is there something wrong with it? Tried to make grab type of attack.

if (a.mat +a.hp/10 +13) > (b.hp/10 + b.mat + Math.random(20)){b.addState(27); a.atk + a.mat - 8 -b.def} else {(a.atk *0.8 + a.mat -8- b.def)}

##### Veteran
I am looking for some help on using a script call in the damage formula. I am attempting to use the QSprite plugin in the damage formula when an attack occurs.

I have tried using Common Events, but this just has the sprite motion occur after the attack.

Any help would be appreciated.

My formula is below:

this.pluginCommand("QSprite", [\$gameVariables.value(4), "play","atk"]); a.atk * 4 - b.def * 2

#### Solar_Flare

##### Veteran
You can abbreviate `\$gameVariables.value(4)` to just `v[4]`.

Besides that, the reason your formula doesn't work is because it expects `this` to be a game interpreter, but it's actually something else… I can't remember what specifically, perhaps an "action"?

My first suggestion would be to dive into the QSprite plugin source code to figure out what the QSprite plugin command actually does. If it's something simple, you might be able to simply substitute that code in place of the pluginCommand call.

#### Andar

##### Veteran
pluginCommand(
beside the answer above, the plugin commands were never meant to be called by script at all - their entire function is to replace script commands with an easier framework.
As such a plugin contains a function that processes the arguments of the event command into their true script functions, and you now called that process by script. That is as if you want to travel from Berlin to Brussels by taking the "shortcut" through Tokio on the other side of Earth...

You should go into the plugin code and look for the function that processes the plugin commands, then check there what script function is called by that and use this script call directly, completely bypassing the plugin command option.

##### Veteran
You can abbreviate `\$gameVariables.value(4)` to just `v[4]`.

Besides that, the reason your formula doesn't work is because it expects `this` to be a game interpreter, but it's actually something else… I can't remember what specifically, perhaps an "action"?

My first suggestion would be to dive into the QSprite plugin source code to figure out what the QSprite plugin command actually does. If it's something simple, you might be able to simply substitute that code in place of the pluginCommand call.

beside the answer above, the plugin commands were never meant to be called by script at all - their entire function is to replace script commands with an easier framework.
As such a plugin contains a function that processes the arguments of the event command into their true script functions, and you now called that process by script. That is as if you want to travel from Berlin to Brussels by taking the "shortcut" through Tokio on the other side of Earth...

You should go into the plugin code and look for the function that processes the plugin commands, then check there what script function is called by that and use this script call directly, completely bypassing the plugin command option.

Thanks to both of you on the input.

Unfortunately the QSprite plugin is a bit out of my scope. I just spent a few hours trying to narrow down the exact portion that causes the Sprite motion to occur and I am having a tough time narrowing it down.

Link to plugin: https://quxios.github.io/plugins/QSprite

I am ultimately trying to use this plugin with the SRPG plugin to have on map battles with more animation frames than the 3 allowed by the SRPG plugin. Any additional insight would be appreciated.

#### Solar_Flare

##### Veteran
The key section to examine for this purpose appears to be here.

For your specific example, you would need to find the subsection for `cmd === 'play'`. Based on that, the following code should do what you want:

JavaScript:
``QPlus.getCharacter(v[4]).playPose('atk', false, false, false, false);``

I'm not certain if all the `false`s are required; you might be able to shorten it to this:

JavaScript:
``QPlus.getCharacter(v[4]).playPose('atk');``

If you need to do a different command, just look through the above link (or your local copy thereof) to find the name that needs to replace `playPose` for that command.

#### UmbrotheUmbreon

##### Legendary Umbreon
Hey there

So I saw the post earlier about applying parameters to damage formulas (to change evasion and such), but I'm a bit lost. Engine I'm using is MV and the project is a new project. Here's what I've put for the formula, and I've tried testing it out (I saw the stun affect the monster, but I don't know if the evasion worked).

200 + a.mat * 2 - b.mdf * 2; b.eva * .5

I'm not the best with codes and formulas, but I'm doing my best to try and learn and improve. Now if this IS right, how do I get it to show the evasion lowered? I don't mind using a random icon in the default database if an icon is needed.

#### Andar

##### Veteran
200 + a.mat * 2 - b.mdf * 2; b.eva * .5
no, this isn't right for a number of reasons.

first, due to the way the damage formula works the damage done is always the last number processed.
and since you didn't store the first number calculated that is exactly like you only wrote the second part, so it does damage of b.eva * 0.5 (or almost nothing).

second, at the point when the damage formula is calculated the evasion is already checked and won't be tested again, so it doesn't change anything in the evasion itself. please refer to:

there are a few other problems as well, so I suggest you give a description of what you want to happen and someone can hopefully tell you how to do it right.

#### ThreeSixNine

##### Veteran
Hey there

So I saw the post earlier about applying parameters to damage formulas (to change evasion and such), but I'm a bit lost. Engine I'm using is MV and the project is a new project. Here's what I've put for the formula, and I've tried testing it out (I saw the stun affect the monster, but I don't know if the evasion worked).

200 + a.mat * 2 - b.mdf * 2; b.eva * .5

I'm not the best with codes and formulas, but I'm doing my best to try and learn and improve. Now if this IS right, how do I get it to show the evasion lowered? I don't mind using a random icon in the default database if an icon is needed.
So first, the damage formula box evaluates js code, so there are a lot of things that can be done there. But, one main point to remember is that IF there is a semi-colon anywhere in the box, only the code after the final semi-colon can be used to calculate damage. This is outlined in the original post of this thread.

That being said, anything done to change the properties of a battler must come before the damage calculation, which should show that the damage formula box has a very specific focus on dealing damage. While it's certainly nice to be able to factor in many data points other than the common parameters everyone is familiar with, the damage formula box is not always the place to add a game-play mechanic.

Your above code will ignore everything before the semi colon and do damage to the target equal to half it's evasion parameter.

I'd say your best bet in this situation would be to create a state that lowers the target's eavsion by half and apply that to the target BEFORE you calculate the damage.

Referring to the original post, we see that states can easily be added using the code:
`addState(stateId)`

So something like:
`b.addState(369); 200 + a.mat * 2 - b.mdf * 2`
would add state 369 to the target and then run the actual damage formula.

This still may not achieve your goal, if your trying to make an attack that lowers the target's evasion before the attack lands.

#### UmbrotheUmbreon

##### Legendary Umbreon
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.

### Latest Profile Posts

Messing around with fragment shaders (filters). This thing is HUGE and I'm surprised almost no one makes good use of. Even the number of plugins that do this stuff are limited.

There's 7 main areas in the game that are all connected. This train get's you from an underground lab to the center of someone's subconscious. inside the train you can talk to some of the passengers. but going to the top of it, there's battles.
Speedrunning all character portraits just so they all have the same quality. Not sure if this was a good idea, but now I'm almost done.
We now have a gameplay video!
That is a cute Link picture, reminds me of the Samurai Jack artstyle.