# RMMV Damage Formula - ideas and help

#### emelian65

##### Veteran
I planning to make the spells from my game be single Target or aoe target by using some of Yanfly plug ins, for some strange reason the <Disperse Damage> is now working, but I fear that is only temporarily so I want to know if there is a way to do it directly in the damage formula.

FFX-2 handled the spells that way, they only give you Single Target spells but you could make them aoe but deal less damage. that's what I want to do instead of making one spell for each tier and then for each single or multi, although it seems I'll need to do that for foes as they CANNOT make use of the single aoe feature.

#### SergeX

##### Veteran
Let's see if anyone can help me...

In my game, elemental spells are tied with variables, and the damage output is influenced by these variables. In my game, this is made so according to the environment, the elemental spell can get a bonus (ex: a water spell used on a beach place would have a 50% boost) or a deboost (a water spell used in the dry desert would do -50% damage).

In VXA I used to have this formula, which doesn't work on MV.

(100 + a.mat* 4 ) * ( 1 + ( v[x] / 10) )

I'm using the Armor Scaling plugin from Yanfly. How can I translate this formula and make it work on MV?

The logic behind the formula is:

if [v] < 0 = damage nerf (ranges from -10% at [v] = -1 to -50% at [v] = -5)

if [v] = 0 = normal damage

if [v] > 0 = bonus damage (ranges from +10% to +50% at [v] = 5)

Last edited by a moderator:

#### Aethers

##### Villager
New to RMMV and the coding in general, and I want to ask if it is possible to assign Variable to the enemies in battle (or anything with ID for example?) for easier calculation?

In the project, enemies have [Natural Defense] (Read: Defense Stat) and [Armor] (read: a variable).

Basically it comes down to [Attacker's Total damage] - [Enemy's Natural Defense + Armor] in the end.

However, some abilities allows to bypass (pierce) or chip the [Armor] (Bash).

Basically, the variable isn't always constant and is required in the damage formula.

Using the script function/Notetags, is is possible to assign variable [x] to say enemy 1;2;3 and so on? So I can assign the formula in calculation for each enemies independently.

How should I go around this in custom script so I don't have to work with battle events? I assume it is possible to call enem(ies) ID and go from there?

Sorry if I am being unclear, I am still quite unsure about starting on the whole JS Function thing.

EDIT: To clarify, what I had in mind is to use battle event (condition: Turn 0) to assign all the required variables into the Enemies as well as players and let the custom calculation in Skills note tags to do the job for the rest of the battle. Is there a way to do so?

EDIT2: After some researching, it seems enemy's note can be used as Script function. I am just guessing, but Is there a way to attach or create a variable for the enemy from here?

Last edited by a moderator:

#### KeeganKLM

New to RMMV and the coding in general, and I want to ask if it is possible to assign Variable to the enemies in battle (or anything with ID for example?) for easier calculation?

In the project, enemies have [Natural Defense] (Read: Defense Stat) and [Armor] (read: a variable).

Basically it comes down to [Attacker's Total damage] - [Enemy's Natural Defense + Armor] in the end.

However, some abilities allows to bypass (pierce) or chip the [Armor] (Bash).

Basically, the variable isn't always constant and is required in the damage formula.

Using the script function/Notetags, is is possible to assign variable [x] to say enemy 1;2;3 and so on? So I can assign the formula in calculation for each enemies independently.

How should I go around this in custom script so I don't have to work with battle events? I assume it is possible to call enem(ies) ID and go from there?

Sorry if I am being unclear, I am still quite unsure about starting on the whole JS Function thing.

EDIT: To clarify, what I had in mind is to use battle event (condition: Turn 0) to assign all the required variables into the Enemies as well as players and let the custom calculation in Skills note tags to do the job for the rest of the battle. Is there a way to do so?

EDIT2: After some researching, it seems enemy's note can be used as Script function. I am just guessing, but Is there a way to attach or create a variable for the enemy from here?

I couldn't understand you very well, but I think I know what you're trying to do.

Are you trying to make Armor kind of like an extra Health bar so that you have to take out the armor first, then you can deal damage to the actual Health?

If that IS what you're looking for, I'm pretty sure this will solve your problem:

http://yanfly.moe/2016/02/13/yep-70-absorption-barrier-rpg-maker-mv/

Let's see if anyone can help me...

In my game, elemental spells are tied with variables, and the damage output is influenced by these variables. In my game, this is made so according to the environment, the elemental spell can get a bonus (ex: a water spell used on a beach place would have a 50% boost) or a deboost (a water spell used in the dry desert would do -50% damage).

In VXA I used to have this formula, which doesn't work on MV.

(100 + a.mat* 4 ) * ( 1 + ( v[x] / 10) )

I'm using the Armor Scaling plugin from Yanfly. How can I translate this formula and make it work on MV?

The logic behind the formula is:

if [v] < 0 = damage nerf (ranges from -10% at [v] = -1 to -50% at [v] = -5)

if [v] = 0 = normal damage

if [v] > 0 = bonus damage (ranges from +10% to +50% at [v] = 5)

That's a very nice concept, having some spells work better/worse in certain areas!

I'm 98% sure that the formula (100 + a.mat* 4 ) * ( 1 + ( v[x] / 10) ) works on MV.

After all, my formula ( a.atk - b.def ) * a.mat / b.mdf * 13 / 3 * ( v[5] - 1 ) works totally fine, so I don't know why yours wouldn't...

And I actually use the same defence formula(basically but not literally) as Yanfly's Armor Scaling Plug-In, but I prefer to keep that inside the formula rather than having the plug-in do it for me, cause I like to see everything that's happening to my formula.

The only few problems I can think of that you may be doing are...

1. You might not be setting the variable(s) correctly before the battle. (be sure to do battles on (Playtest) rather than (Battle Test...) if you want to use that formula, since variables most likely won't change before the battle starts, unless you manually set them to do so)

2. The Armor Scaling Plug-in is affecting the formula unexpectedly.

3. You may be leaving v[x] as literally v[x] in the coding instead of replacing x with a number.

By the way, you never specified why/how it doesn't work. You should specify what it does after you (insert verb here).

It helps if you specify exactly what doesn't work about it. Even if it's the generic, well-known "only returns as 0," it's just always better to have more information.

Last edited by a moderator:

#### SergeX

##### Veteran
That's a very nice concept, having some spells work better/worse in certain areas!

I'm 98% sure that the formula (100 + a.mat* 4 ) * ( 1 + ( v[x] / 10) ) works on MV.

After all, my formula ( a.atk - b.def ) * a.mat / b.mdf * 13 / 3 * ( v[5] - 1 ) works totally fine, so I don't know why yours wouldn't...

And I actually use the same defence formula(basically but not literally) as Yanfly's Armor Scaling Plug-In, but I prefer to keep that inside the formula rather than having the plug-in do it for me, cause I like to see everything that's happening to my formula.

The only few problems I can think of that you may be doing are...

1. You might not be setting the variable(s) correctly before the battle. (be sure to do battles on (Playtest) rather than (Battle Test...) if you want to use that formula, since variables most likely won't change before the battle starts, unless you manually set them to do so)

2. The Armor Scaling Plug-in is affecting the formula unexpectedly.

3. You may be leaving v[x] as literally v[x] in the coding instead of replacing x with a number.

By the way, you never specified why/how it doesn't work. You should specify what it does after you (insert verb here).

It helps if you specify exactly what doesn't work about it. Even if it's the generic, well-known "only returns as 0," it's just always better to have more information.

It's like you said: damage only returns as 0, I don't know why. Maybe it's a syntax problem? My coding skills are poor, so I can't pinpoint the exact cause neither fix it.

I've tried with Armor Scalling off and even so I kept getting 0, so I don't think that the problem is the plugin, but rather the formula itself.

Thank you very much!

#### Crimson Dragon Inc.

##### Crimson Dragon
so if i'm reading this right.......i can use variables in damage formula using the code v[x] where x is the chosen variable?

#### KeeganKLM

.

so if i'm reading this right.......i can use variables in damage formula using the code v[x] where x is the chosen variable?

yup.

Wanna know a TON of other stuff you can also do?

Go here and have your mind explode: http://www.rpgmakercentral.com/topic/36290-damage-formulas-101-mv-edition/

It's like you said: damage only returns as 0, I don't know why. Maybe it's a syntax problem? My coding skills are poor, so I can't pinpoint the exact cause neither fix it.

I've tried with Armor Scalling off and even so I kept getting 0, so I don't think that the problem is the plugin, but rather the formula itself.

Thank you very much!

You're welcome!

But that is very odd...

I can't think of much else, other than checking the Variable, making sure you spelled a.mat right (I speak from experience), and maybe check b.mdf, even if it's not in your formula. Since you're using Yanfly's Armor Scaling, that just might effect it, but I can't tell right now, as I do not have it installed, but I noticed on Yanfly's page for it that it had some note tags saying  <Magical Armor Penetration: x%>  and  <Magical Armor Penetration: x>  so I'd check that in the plug-in and your game.

Other than that, I'm not sure what you'd be doing wrong... Sorry if I can't help ya.

#### Mahoken

##### Veteran
Probably a simple question that's been answered before, but how do I make this skill deal double damage if the enemy is affected by a state (or multiple states)?

This is the formula I have at the moment, but it keeps giving me 0 damage when I use it, so I know something is wrong (I have no idea how to code):

b.isStateAffected(5) ? ((a.level*14)+(1.3*a.mat))*(100.0/(100+b.mdf)) : ((a.level*7)+(0.65*a.mat))*(100.0/(100+b.mdf));end

#### BodkinsOdds

##### Villager
And then he promptly forgot about it, and didn't write anything up when he got home from work. Sorry.

I just remembered an amazing guide I found a while ago, which might even be worth asking @Shaz to add to the OP. It can be found here: https://rpgmakermv.co/threads/damage-formulas-101-mv-edition.2172/

Sadly, it wasn't able to provide a simple solution. When I tried the formula (a.mp);(a.setMp(0)) it dealt 0 damage. I think it was running everything at once, then animating, then recalculating the damage, because a.mp and a.setMp(0) both worked individually. So we're going to have to go back to the plugin method.

Actually, you're overthinking it. The final statement in the formula is the damage, so all you need to do for this is:

var d = a.mp; a.setMp(0); d

And done.

Probably a simple question that's been answered before, but how do I make this skill deal double damage if the enemy is affected by a state (or multiple states)?

This is the formula I have at the moment, but it keeps giving me 0 damage when I use it, so I know something is wrong (I have no idea how to code):

b.isStateAffected(5) ? ((a.level*14)+(1.3*a.mat))*(100.0/(100+b.mdf)) : ((a.level*7)+(0.65*a.mat))*(100.0/(100+b.mdf));end

This one is easy. First, if you get rid of the ;end it'll work fine, secondly you don't need to type in the damage formula twice:

var d = ((a.level*7)+(0.65*a.mat))*(100.0/(100+b.mdf)); b.isStateAffected(5) ? d * 2 : d

This way is easier to maintain if you change the damage formula later. If you really meant it to be double damage before defenses then:

var d = ((a.level*7)+(0.65*a.mat)); b.isStateAffected(5) ? d * 200 / (100 + b.mdf) : d * 100 / (100 + b.mdf)

Last edited by a moderator:

#### emelian65

##### Veteran
Probably a simple question that's been answered before, but how do I make this skill deal double damage if the enemy is affected by a state (or multiple states)?

This is the formula I have at the moment, but it keeps giving me 0 damage when I use it, so I know something is wrong (I have no idea how to code):

b.isStateAffected(5) ? ((a.level*14)+(1.3*a.mat))*(100.0/(100+b.mdf)) : ((a.level*7)+(0.65*a.mat))*(100.0/(100+b.mdf));end

Try this one, but the only problem I see with yours is the 100.0 why are you adding that?

Code:
``b.isStateAffected(5) ? ( (a.level * 14 ) + ( 1.3 * a.mat ) ) * ( 100 / ( 100 + b.mdf ) ) : ( ( a.level * 7 ) + ( 0.65 * a.mat ) ) * ( 100 / ( 100 + b.mdf ) )``

#### Mahoken

##### Veteran
Actually, you're overthinking it. The final statement in the formula is the damage, so all you need to do for this is:

var d = a.mp; a.setMp(0); d

And done.

This one is easy. First, if you get rid of the ;end it'll work fine, secondly you don't need to type in the damage formula twice:

var d = ((a.level*7)+(0.65*a.mat))*(100.0/(100+b.mdf)); b.isStateAffected(5) ? d * 2 : d

This way is easier to maintain if you change the damage formula later. If you really meant it to be double damage before defenses then:

var d = ((a.level*7)+(0.65*a.mat)); b.isStateAffected(5) ? d * 200 / (100 + b.mdf) : d * 100 / (100 + b.mdf)

Seems to be working very well, thank you! Only thing I'm having an issue with is adding more than one affected state to that formula, so another noob issue.

var d = ((a.level*7)+(0.65*a.mat)); b.isStateAffected(5,6,7) ? d * 200 / (100 + b.mdf) : d * 100 / (100 + b.mdf)

Does adding numbers in states affected work if you add commas like that?

#### Crimson Dragon Inc.

##### Crimson Dragon
hey um trying to write a damage formula for a skill that grows stronger with every use...........any ideas on how to implement this?

#### Shaz

##### Global Moderators
Seems to be working very well, thank you! Only thing I'm having an issue with is adding more than one affected state to that formula, so another noob issue.

var d = ((a.level*7)+(0.65*a.mat)); b.isStateAffected(5,6,7) ? d * 200 / (100 + b.mdf) : d * 100 / (100 + b.mdf)

Does adding numbers in states affected work if you add commas like that?

That's because isStateAffected receives ONE argument, not as many as you want to throw at it.  Try [5,6,7].some(function(state) { return b.isStateAffected(state); })

@Crimson Dragon Inc. you'd probably have to use a variable in the damage formula, and make the damage formula increment it as well.

Last edited by a moderator:

#### Aethers

##### Villager
@KeeganKLM

Yeah, I was too absorbed with my initial idea I didn't realize the armor scaling and absorption already do what I wanted. My bad. ALSO, THANKS for that Damage101 link. That sure helps me to understand how lunatic coding works.

I still have a bit of question about variables though! Please bear with my question a bit longer (even if my questions sounds...stupid/ignorant)

Can Variables be used as INDEPENDENT Parameter?

Okay, this is actually two question. Is it possible to establish a brand new parameter for the actors (and in extension, enemies) without exchanging the pre-existing ones (MATK/ ATK/TRT/PHA/etc) ? For example, if I want to make a parameter for everyone like, uhh, (for example) [FATIQUE (FTQ)] or something like that; would it be possible?

However, would this brand new parameter :

1. Useable in damage formula or ANY formula in general? BUT

2. Also treated independently for each actor?

It might be a bit confusing but let's say I set var001 as [FTQ]. If I only reference this variable for each actor, the damage will be all messed up because even if everyone start or have different [FTQ], it overwrites the same variable. Which is bad. ALTERNATIVELY, if I make [FTQ1],[FTQ2] and so on for every actor, it makes the formula full of conditions - check which user it is before using which VAR. Which is doable, but also tedious.

I am looking at user.Matk kind of reference/parameter call during damage calculation which makes it a lot easier (I think?) and neater script. In addition, I am also looking at the new Self Variable plugin, which sounds promising, but I am not sure how and if it is possible to.

Bottom line, making a user.stat (I guess, I don't know if this is even the correct way of saying this) ?

Can the above example applied to enemies

Right, it gets more confusing for me too. So can it be done/set up for enemies too. The VAR will rise and fall as the battle goes on; which makes me a bit more concerned about it. Let's say I used Variable again - since that's all I know because I never use any RM after 2003 - and make [E-FTQ] and set it for a monster - maybe in notetag.

What happens if there are multiple enemies of the same ID in the enemy Troops? I am pretty sure it gets all messed up since it is a single variable that gets overwritten by multiple same IDs. Not to mention the calculations required for each battle event would probably be ridiculously long/complicated.

This is why I am interested about attaching it as an individual stat for each combatant/actor/enemy instead. Please tell me it is possible lel.

Last but not least?

In some JS example, I see sometimes a new variable being defined. For example, in one of Yanfly's tips and trick

<Custom Apply Effect>
target._deathMarkDmg = 0;
</Custom Apply Effect>

<Custom React Effect>
if (value > 0 && attacker === origin && this.isHpEffect()) {
target._deathMarkDmg += value;
}
</Custom React Effect>

That target._deathmarkdmg is something brand new I think (?). So the question is, we can define a variable via JS? How is it different from using VAR001 and so on? Does this value stick forever (I have seen codes that end it as =undefined to clear the value)? Does it only apply for that battle?

Basically I want to know if it works differently than normal SETVAR function Rpgmaker have.

Sorry if it drags on too long, but I am really looking forward to see what I can (and not) do with all these possibilities.

Last edited by a moderator:

#### Bob7

##### Veteran
Just a quick question, is there anyway to introduce the variable from another character?

I'm trying out some multi-character skills (skills that use two actors for joint attack.) In this example, I want to use the initial user's attack and the 2nd character's magic attack for the calculation.  (2nd character's special attack + (2 x 1st character's attack))

Is there a way to target a specific actor's stat (not merely the actor in Slot 2, but the specific character in question)?

#### KeeganKLM

Just a quick question, is there anyway to introduce the variable from another character?

I'm trying out some multi-character skills (skills that use two actors for joint attack.) In this example, I want to use the initial user's attack and the 2nd character's magic attack for the calculation.  (2nd character's special attack + (2 x 1st character's attack))

Is there a way to target a specific actor's stat (not merely the actor in Slot 2, but the specific character in question)?

How I would do this, is I'd make a skill that does absolutely nothing except call a common event. (Only because common events happen after the actual attack) You can call a Common Event through a skill in the Effects section.

For this example, we'll call the common event "Team Attack" and I'm going to use the names Diego and Terry for this example.

For now, I'm just going to assume you know how to disable the skill when one of the actors are out of the party. If you don't, then tell me (and specify certain things like if the player can willingly get them out of the party or not) and I'll get back to you on that.

In Team Attack, have it set Variable (X) to Actor Terry's MAT. (You can do this by going to Change Variables...)

Then, have it Force Action on Diego to make him use this other skill I'll just call "Teamwork!".

(By the way, Force Action doesn't let you choose the target, but I believe that somehow you can make it so that a skill tries to target someone with a specified state if the target is randomized. I can't remember how, but I'll look into it when I can.)

(Force Action lets you target the previous target, so just select that one and you'd probably be fine.)

I believe Force Action works by indexes, if I remember correctly. So for now, all I can think of for using Diego on the Force Action command is using a list of conditional branches that test which party member slot he's in, which I could probably explain more in depth when I can use MV again.

But anyway, you could use Variable (X) in the skill "Teamwork!" so that it modifies its damage.

Here's an example for the skill formula:

v[x] + ( a.atk * 2 )

Of course, instead of using v[x], you'd have to replace x with whatever variable you decide to use. If you need anything specified a bit more, feel free to ask.

Also...

@Aethers

I'm actually not that good at coding at all, or at least creating it.

However, in my quest to help you with my current wisdom and knowledge, I thought what you might want was a plug-in that added more parameters (that you'd be able to set/modify through note tags). I know that I, personally, would LOVE to have a plug-in like that, but I sadly couldn't find anything. But then again, I was always the worst at researching...

If you can somehow figure out how to use something like that, or find a plug-in that would work that I obliviously missed, I'd appreciate it if you could notify me, as I'd like to use something like that as well.

Last edited by a moderator:

#### Bob7

##### Veteran

How I would do this, is I'd make a skill that does absolutely nothing except call a common event. (Only because common events happen after the actual attack) You can call a Common Event through a skill in the Effects section.

For this example, we'll call the common event "Team Attack" and I'm going to use the names Diego and Terry for this example.

For now, I'm just going to assume you know how to disable the skill when one of the actors are out of the party. If you don't, then tell me (and specify certain things like if the player can willingly get them out of the party or not) and I'll get back to you on that.

In Team Attack, have it set Variable (X) to Actor Terry's MAT. (You can do this by going to Change Variables...)

Then, have it Force Action on Diego to make him use this other skill I'll just call "Teamwork!".

(By the way, Force Action doesn't let you choose the target, but I believe that somehow you can make it so that a skill tries to target someone with a specified state if the target is randomized. I can't remember how, but I'll look into it when I can.)

(Force Action lets you target the previous target, so just select that one and you'd probably be fine.)

I believe Force Action works by indexes, if I remember correctly. So for now, all I can think of for using Diego on the Force Action command is using a list of conditional branches that test which party member slot he's in, which I could probably explain more in depth when I can use MV again.

But anyway, you could use Variable (X) in the skill "Teamwork!" so that it modifies its damage.

Here's an example for the skill formula:

v[x] + ( a.atk * 2 )

Of course, instead of using v[x], you'd have to replace x with whatever variable you decide to use. If you need anything specified a bit more, feel free to ask.

Also...

@Aethers

I'm actually not that good at coding at all, or at least creating it.

However, in my quest to help you with my current wisdom and knowledge, I thought what you might want was a plug-in that added more parameters (that you'd be able to set/modify through note tags). I know that I, personally, would LOVE to have a plug-in like that, but I sadly couldn't find anything. But then again, I was always the worst at researching...

If you can somehow figure out how to use something like that, or find a plug-in that would work that I obliviously missed, I'd appreciate it if you could notify me, as I'd like to use something like that as well.

Well, after trying that out and some further research, it seems like that yes, I have to create different parts to the skill, and then combine it all at once.

Thanks to some further assistance, I've done my best to make the skill animations as fluent as possible while making sure the individual skills use the correct variables at certain stages. (So the first hit would be its own skill, and then the second hit would also be its own skill there.)

However, while all this worked out as I liked it to, I did eventually hit a wall with restrictions (which basically ensuring the skill doesn't go off if the 2nd character is in no position to use the skill.) While I could disable the skill if the 2nd character was not present or was KOed, I couldn't stop them if they didn't have the required amount of points nor if they were unable to move.

I'm going to try another plugin to rectify that one remaining problem, and should all go well, I think I can finally create a dual skill that calculates individual hits using specific formulas, while being subject to both members meeting the requirements.

#### TheRiotInside

##### Extra Ordinaire
@KeeganKLM Hey, if you were still looking around for a plugin to add custom parameters, definitely check out Quasi Params Plus! You can make your own parameters with it, which can be used in damage formulas and has compatibility with a lot of popular plugins.

Last edited by a moderator:

#### Riku_Masamune

##### Veteran
a.gainHp(-500~-999);a.mat*5

I've tried everything I can think of to get a random -number. Works with solo numbers. I even did a list of numbers using || (or) for them to take place, but only did the first set when written out a.gainHp(-111||-222) etc. It's a spell that I was trying to use that'd be taxing on the user, but a bit more "fair" to the player and a surprise when Actor looses a lot of HP. Any help would be appreciated.

#### TheRiotInside

##### Extra Ordinaire
@Riku_Masamune Hey, see if this works:

a.gainHp(-(Math.randomInt(500) + 500)) ; a.mat * 5

My syntax might be off somewhere, but the Math.randomInt(500) function should give you something in the 0 to 499 range, so adding 500 after should give you the 500 to 999 you're looking for.

Last edited by a moderator:

### Latest Profile Posts

Another comic with Backstage Malak...
If you want to ask him anything, you can ask on my DeviantArt page! I'm not sure if you're allowed to do it here.
Forum tip of the day ...
If you get a temporary suspension for being a jerk to people who are trying to help you, and arguing with mods and admins, don't go making new accounts. Chances are, if you p**s us off enough to suspend you for a week, we're not going to hesitate giving you a permanent ban when you give us a reason.

I'm so close to releasing my game on steam!
Us:
"This game is awesome! I wish there are more games like this in the future."
Also us:
"I hate how games stopped being original and start copying other successful games."
Should've done this a few days ago but...

Rest in Peace, Sir Clive Sinclair
1940 - 2021
Entrepreneur, Technologist, Father of the Modern British Computing Industry, and protagonist of Legend of ZUN.

Without you, England's games and tech industry wouldn't be where it is.