# Damage Formulas 101

#### ATT_Turan

##### Forewarner of the Black Wind
Edit: removed because I found a more active thread to ask the same question, as this one appears to have been dead a while
Just as a suggestion, there's not much reason to do that. Recent/unread posts show up in the same lists on the site. So unless there's someone who's only working off of notifications from threads they've Followed, we're going to see your post regardless of which specific damage formula thread it's in

#### emelian65

##### Regular
Theorically, making a check for more than one condition would work with && on it right?

For example:

JavaScript:
``a.mp && a.tp >= 35 ? 75 : 40;``

Could this work if I need the skill to deal extra damage as long as MP and TP are above 35? Or should I need to do something else?

#### ATT_Turan

##### Forewarner of the Black Wind
Theorically, making a check for more than one condition would work with && on it right?
No, that's not correct JavaScript syntax. Each side of the boolean operator must be a complete comparison. See:

So you'd do `a.mp>=35 && a.tp>=35`

#### Fonixed

##### Regular
I'm not receiving any battle damage with this formula I'm not sure why.
Can this be done or do I need to make two different damage formulas with the same name?
JavaScript:
``if (a.actorId() === 1) { (v[1] + a.atk * 4 - b.def * 2); } else { (a.atk * 4 - b.def * 2); }``

#### Shaz

##### Keeper of the Nuts
@Fonixed, try == instead of ===. What's in variable 1?

#### Fonixed

##### Regular
@Fonixed, try == instead of ===. What's in variable 1?

I've given Variable 1 the value of 25, it's just a random value that I'm using to see if I can get it working.

Also == and === have the same effect in this case. I can deal damage but not receive any.

Last edited:

#### ATT_Turan

##### Forewarner of the Black Wind
Also == and === have the same effect in this case.
With RPG Maker they always will. Unless you manually set a variable to something weird, they will always be numbers and not need to be a strict comparison.

I can deal damage but not receive any.
Because enemies don't have an actorId() field. When an enemy uses the skill, calling actorId() is undefined and zeros out the entire formula.

#### kn1000a

##### Golden Vampire
How much of these can be applied on VXA? I know MV uses javascript but idk how much I can reference, I could not find a comprehensive "Damage Formula 101" for VXA (Forma wrote one but it was not as in depth with each functionality)

Are these functions here like currentExp() the same in VXA? Would've be so nice if VXA let me uses as much as what is documented here.

#### ATT_Turan

##### Forewarner of the Black Wind
Are these functions here like currentExp() the same in VXA? Would've be so nice if VXA let me uses as much as what is documented here.
No, VX uses Ruby for scripting while MV/Z are coded in JavaScript - two completely different languages.

You can look up the VXAce script call list for functions to use in that engine.

#### Lisanthius0705

##### Warper
Hey, I'd like to make a damage formula that allows me to hit an enemy and at the same time give back a fixed number (for example) 7 of mana and TP to my allies and myself. Is it possible to do this?

#### ATT_Turan

##### Forewarner of the Black Wind
Hey, I'd like to make a damage formula that allows me to hit an enemy and at the same time give back a fixed number (for example) 7 of mana and TP to my allies and myself. Is it possible to do this?
Yes, but it's generally not best practice to put that in the damage formula.

The first post of this thread lists the functions for gaining MP and TP. You can use the forEach() method to do it to everyone. For example:
Code:
``a.friendsUnit().forEach(battler => battler.gainMp(7)); damage formula``

However, if you give that skill to enemies or you ever use the auto battle trait, it can produce unexpected results. So it's better to use something like Yanfly's Skill Core to execute code like that only when a skill is actually used.

#### Zakarijazh

##### I love making maps!
So i thought I could make a formula that drained 35% of a target's TP and restored it to the user but I feel like I'm missing something?

a.setTp(a.Tp * .65); user.setTp(user.Tp + (a.Tp * .65)

#### ATT_Turan

##### Forewarner of the Black Wind
So i thought I could make a formula that drained 35% of a target's TP and restored it to the user but I feel like I'm missing something?

a.setTp(a.Tp * .65); user.setTp(user.Tp + (a.Tp * .65)
There are a few things wrong with this.

1 - There's no such property as "Tp". It's "a.tp" or "b.tp," etc.

2 - As described in the first post of this thread, the last thing in your formula must always be the value being used for damage. The setTp function does not return a value, so you're going to be getting `undefined` from all of that.

3 - There's no such thing as `user` in the damage formula - I'm not sure where you're getting that from. You might be confused with the documentation for plugin notetags, but the damage formula only has a and b.

4 - Your syntax is incorrect. The second statement (after the semicolon) has two open parentheses and one close.

If this skill is not supposed to do any HP or MP damage to the target at all, you probably don't want to use the damage formula for this. You must have a value if you do, which means if nothing else you'll see a 0 damage popup every time you use the skill. If that's the case, you'd be better off using something like Yanfly's Skill Core and putting the code into an After Eval notetag or something like that.

#### Zakarijazh

##### I love making maps!
There are a few things wrong with this.

1 - There's no such property as "Tp". It's "a.tp" or "b.tp," etc.

2 - As described in the first post of this thread, the last thing in your formula must always be the value being used for damage. The setTp function does not return a value, so you're going to be getting `undefined` from all of that.

3 - There's no such thing as `user` in the damage formula - I'm not sure where you're getting that from. You might be confused with the documentation for plugin notetags, but the damage formula only has a and b.

4 - Your syntax is incorrect. The second statement (after the semicolon) has two open parentheses and one close.

If this skill is not supposed to do any HP or MP damage to the target at all, you probably don't want to use the damage formula for this. You must have a value if you do, which means if nothing else you'll see a 0 damage popup every time you use the skill. If that's the case, you'd be better off using something like Yanfly's Skill Core and putting the code into an After Eval notetag or something like that.
okay, thanks. I'll try to do something with the skill core. I did some other stuff but I'm not good as coding at all, so it's... a process. lol

#### Disponi

##### Villager
I want to make an item that has double strength in battle. How would I go about checking to make sure I'm in the Battle Scene?

#### ATT_Turan

##### Forewarner of the Black Wind
I want to make an item that has double strength in battle. How would I go about checking to make sure I'm in the Battle Scene?
Code:
``SceneManager._scene instanceof Scene_Battle ? original formula : stronger formula``

#### Disponi

##### Villager
Code:
``SceneManager._scene instanceof Scene_Battle ? original formula : stronger formula``

Thanks, that did it! Had to swap the formula places, though.

#### ATT_Turan

##### Forewarner of the Black Wind
@Disponi Oops, sorry, yeah, quickly typed that backward

##### Villager
I'm not so good in formulas. Could you please explain me one thing. Is it possible to create formula that will change damage to heal or heal to damage depending on state or something like that? I'll be very grateful.

Right now I'm trying to create a classes that normally heal characters but damage undead enemies with the same skills. I already know about Silv Undead plugin but I'm also using FROG Health which demands special fomulas written in the plugin options. In other case it's bugging the game. Silv's Undead works only with straight formulas like a.atk and so on.

Found what I need in the another thread. Won't bother. Will just create damaging skills for my healers.

Last edited:

#### Dark_Ansem

##### Regular
Found what I need in the another thread. Won't bother. Will just create damaging skills for my healers.
What was the solution?

### Latest Profile Posts

I haven't check my game DL in a while. So time to see if I get a error 404 message. Because I deleted it due to a lack of space. Or it instantly crashes the second it starts. Or if I end up in some random map because I forgot to reset the start point. Or any combination of them.

Design finished. Onto finishing the entire sprite sheet and alternative colours now
What does it say about you when a mushroom is your best friend?
If a game had a moral-choice system at the beginning 3 chapters where defeating an on-screen encounter grants a "-2" at the end of the level whereas evading it granted "+2" at the end of the chapter, and then each chapter also had a dialogue choice that'd give/take points depending on the answer the player gives, how many points would you expect to gain from the dialogue choices?

My next plugin will be:

DYNAMIC SWITCHES! (For RPG MAKER MZ)

What does this plugin allow?

Basically it allows you to create switches that work even though the game is closed.

Example of use:

You can make a system that you can only run a mini game once a day (or an event or whatever you want) and you have to wait 24 hours to play again.