# RMMV Damage Formula - ideas and help

#### Vergel_Nikolai

##### Veteran
Code:
``let value = a.atk * 4 - b.def * 2; b.isStateAffected(4) ? value * 2 : value``
Do I put this formula on the damage formula box or the note tag?

#### Trihan

##### Speedy Scripter
The damage formula box.

#### Vergel_Nikolai

##### Veteran
Thanks for the tip.

#### Bigkill321

##### Villager
So I'm trying to write a formula that if I were to increase variable 1 that it would increase the damage dealt by 3.5%. I'm trying to store the damage from the formula in var 5 then set another, var 6, equal to that var 5 then make var 6 multiply by var 1 * 0.035. Then at the end add var 5 to var 6 for the end damage. I must not be understanding how the damage formulas work completely yet because its giving me 0 in combat.

Formula using:
\$gameVariables.value(5) = (a.atk - b.def / ((b.level / 2) + 2)) ; \$gameVariables.value(6) = \$gameVariables.value(5) ; \$gameVariables.value(6) = \$gameVariables.value(6) * (0.035 * \$gameVariables.value(1)) ; \$gameVariables.value(5) + \$gameVariables.value(6).

The stats that are being used is
a.atk = 50
b.def = 14
b.level = 1

Any help on why this isn't working would be appreciated.

#### Solar_Flare

##### Veteran
You can't assign to `\$gameVariables.value(5)`. To change the value of a variable, you need to write `\$gameVariables.setValue(5, newValue)`. Also by the way, you can access a variable in the damage formula using abbreviated syntax: `v[5]`.

Now, there's one other weird thing about your formula. Why are you using \$gameVariables 5 and 6 at all? Do you need these numbers somewhere else outside of the damage formula? If you don't, then you should just use JavaScript variables - it'll make for a much shorter and readable formula.

JavaScript:
``````var base = a.atk - b.def / (2 + b.level / 2);
var bonus = base * 0.035 * v[1];
base + bonus``````

Take out the line breaks obviously, but I think that should do the same as what the code you posted looked like it meant to do.

#### Bigkill321

##### Villager
You can't assign to `\$gameVariables.value(5)`. To change the value of a variable, you need to write `\$gameVariables.setValue(5, newValue)`. Also by the way, you can access a variable in the damage formula using abbreviated syntax: `v[5]`.

Now, there's one other weird thing about your formula. Why are you using \$gameVariables 5 and 6 at all? Do you need these numbers somewhere else outside of the damage formula? If you don't, then you should just use JavaScript variables - it'll make for a much shorter and readable formula.

JavaScript:
``````var base = a.atk - b.def / (2 + b.level / 2);
var bonus = base * 0.035 * v[1];
base + bonus``````

Take out the line breaks obviously, but I think that should do the same as what the code you posted looked like it meant to do.
Thanks for the reply. I use \$gameVariables for my var 1 since if you were to use v[1] and use test battle and dont have the var defined in the fight it leads to undefined or 0. I was using v[#] for the formula but it wasn't working so i figured i would just try \$gameVariables to just see if it would do anything. When it didn't i just copied it and pasted it here looking for help. To start out i was actually trying to use just x and y, I'm very new to using variables in damage formulas so i don't really know what works or not, and don't know anyting on javascript variables either.

#### Solar_Flare

##### Veteran
I use \$gameVariables for my var 1 since if you were to use v[1] and use test battle and dont have the var defined in the fight it leads to undefined or 0.
Ahh, that's true. Well, the code I posted doesn't depend on v[1] vs \$gameVariables.value(1), so you can use whichever you prefer.

#### whitesphere

##### Veteran
If you want to have non-linear Final Fantasy style damage scaling, where small differences produce small values, but larger differences produce extremely large values, this more complex formula works very well in RPG Maker MV and MZ:

Math.min(7999, 15*Math.pow(2, ((a.atk-b.def)/3)))

If the attack and defense (substitute a.mat and a.mdf for magic) are close, this formula results in small values. But, as the difference increases, the formula rapidly produces much larger values. The outer "Math.min" call bounds the damage at 7999. With the default "20% Variance" this caps damage at around 9999.

With this formula, an attack/defense difference of 3 causes a value of 30. If you increase that attack/defense difference to 12, the value is 240. And, increase it still further to 22 and the value becomes 3840. Basically, every difference of 3 doubles the damage.

Increasing the "3" divisor slows the rate of the very rapid increase. You can also add a linear value before the 15* to increase the base damage.

From a player's standpoint, this formula lets them see how powerful the party has become against weaker opponents. That Orc that you barely survived at level 10? Go back at level 20 and you can one-shot-kill it, most likely.

Expect to do a great deal of tweaking in the Battle Test screen though.

#### Miyoko

##### Villager
Got a couple of damage formula things I'm trying to hammer out at the moment, and I'm in over my head.

The first is an ability that heals both the caster, and the target. The formula is as follows:
x = Math.round(b.mhp * 0.15 + a.mdf); a.gainHp(x); x

The formula itself works and heals both parties, however it only shows the recovered health for the recipient and not the caster. Using Yanfly's battle engine core, I can use <display text: whatever> to display a message, but, I'm not sure what code I can use to show the amount healed by the caster, and who the caster is/was. Or... If there's just an easier way to do it.

The second thing I'm looking to do is have poison status effects that scale off of something and deal a flat damage value instead of a percentage. Again using another Yanfly script, Lunatic Pack - Action Beginning and End Effects this time, I'm able to make the status effect inflict a flat damage value, but I'm not sure how to make it scale off of a stat from the caster. One idea I had was to simply store the value of the caster into a variable, then have the script deal <variable> damage, but then if I have a different character use the same skill, it'd overwrite that value and thus change the poison damage the prior target is taking. I could make a separate variable for each character, as well as a clone of the same skill for each one that just applies the value to it's own unique variable but... That's just kind of getting messy at this point. I'm sure there's a better way to do it. Like I said, in over my head

I appreciate any advice / ideas!

#### Kagemaru

##### Veteran
Hello!
I'm trying to make a spell that instantly kills all enemies if the caster's level is higher than the target's level. Here's the formula that I used: a.level > b.level ? b.setHp(0) : 0;
I apologize if I'm totally wrong. I really sock at making those formulas.

I'm using RMMZ and yes, I'm using a plugin that allows enemies to have levels(VisuStella's Core Engine).

#### CHKNRAVE

##### Surprisingly not sponsored by Yanfly.
Watch out, you're in an RMMV thread for damage formulas.

Try b.die() instead, that's a way to instakill on MV, maybe it works on MZ.

#### Kagemaru

##### Veteran
I posted this here for 2 reasons:
1. Both RMMV & RMMZ use javascript, so I thought it would be okay to post here.
2. I didnt see a section for damage formulas for MZ, so I thought that meant that both makers use the same types of damage formulas.

#### Aesica

##### undefined
I posted this here for 2 reasons:
1. Both RMMV & RMMZ use javascript, so I thought it would be okay to post here.
2. I didnt see a section for damage formulas for MZ, so I thought that meant that both makers use the same types of damage formulas.

Put a console.log("enemy killed") or something statement in place of the b.die() statement to make sure the code is even being reached. If you use the skill and don't see "enemy killed" in the debug console after using the skill on an enemy it should work against, then you're somehow determining enemy levels wrong.

That said, I'm not a huge fan of using die() or even setHp() because both skip certain steps. The best possible way (assuming you're okay with showing damage popups, which you're going to get anyway because you're using the formula box) is just plain old b.hp. Make sure variance is set to 0%.

Edit: So:

Code:
``a.level > b.level ? b.hp : 0``

This is assuming of course that you aren't using any of VS's weird damage formula styles, which do a bunch of other random crap that may not be desired when attempting to inflict a specific amount of damage.

#### Kagemaru

##### Veteran
Nope, it still didnt work.
I had already disabled VisuStella's style formulas or w/e theyre called, so Im pretty sure that isnt whats causing the problem.

I tried
a.level > b.level ? console.log("enemy killed")
but nothing appeared. I turned off VisuStella's Battle Core plugin just in case(This is the plugin that adds the style formulas) but still nothing. I also turned off every plugin except for the Core Engine plugin, still nothing. Finally, I disabled every plugin I had to see if that would do something, but once again, there was nothing new, not even an error message to tell me that my formula was wrong.

If Im doing something wrong, I really dont know what it is. My test enemy has a
<Level: 3>
notetag in its notebox and my actor 1 is level 5. I even gave him a
<Initial Level: 5>
notetag to see if that would do something, but nope, nothing.

I know the above didnt work, but I still wanted to try the formula that you wrote just in case something would happen, but nothing. I did like you recommended and I set the variance to 0%. Dunno if this helps, but I also set the element to "none", the critical hits to "no" and the hit type to "certain hit".

#### AfroKat

##### Veteran
Nope, it still didnt work.
I had already disabled VisuStella's style formulas or w/e theyre called, so Im pretty sure that isnt whats causing the problem.

I tried
a.level > b.level ? console.log("enemy killed")
but nothing appeared. I turned off VisuStella's Battle Core plugin just in case(This is the plugin that adds the style formulas) but still nothing. I also turned off every plugin except for the Core Engine plugin, still nothing. Finally, I disabled every plugin I had to see if that would do something, but once again, there was nothing new, not even an error message to tell me that my formula was wrong.

If Im doing something wrong, I really dont know what it is. My test enemy has a
<Level: 3>
notetag in its notebox and my actor 1 is level 5. I even gave him a
<Initial Level: 5>
notetag to see if that would do something, but nope, nothing.

I know the above didnt work, but I still wanted to try the formula that you wrote just in case something would happen, but nothing. I did like you recommended and I set the variance to 0%. Dunno if this helps, but I also set the element to "none", the critical hits to "no" and the hit type to "certain hit".

if(a.level > b.level){b.hp;} else {a.atk;}

try that, sometimes if/else statements work for me in different formats. I usually can't get the ? one to work. idk it just happens.

#### Kagemaru

##### Veteran
Ooh! Sadly, it didnt work, but the a.atk part did work. In other words, it really is the first part that isnt functional. This is so frustrating! What am I doing wrong...

Edit:

Heres a screenshot of the skill, actor 1, the punching ba- er... bear and my list of plugins.

#### Attachments

• Actor.png
134.3 KB · Views: 7
• Enemy.png
121 KB · Views: 7
• Plugin List.png
207 KB · Views: 8
• Skill.png
145.6 KB · Views: 6
Last edited:

#### AfroKat

##### Veteran
I can't figure it out either, it just seems like the damage formula doesn't recognize the enemies level. I've tried alot of various ways and different spellings, but that's just it. It's not recognized as something that the enemy can have.

#### Kagemaru

##### Veteran
So youre saying that its a problem with the engine and/or the plugins?

#### AfroKat

##### Veteran
So youre saying that its a problem with the engine and/or the plugins?

Yeah I just downloaded their demo, added levels to the goblin and tried it out and it's definitely the engine not recognizing the plugin. I did a simple damage formula of a.level and it worked. But b.level / b.lv / b.lvl / b.Level all don't work.

#### Kagemaru

##### Veteran
I see. T.T
Thanks a bunch for comfirming it! I was getting worried that the problem might be on my side.
I guess for now Ill go work on my MV project! I hope they fix that problem soon!

### Latest Profile Posts

I just did some math and... apparently what seemed to be a little fun gimmick turned out to be an 80+ actors project
Yay! the original character contest 3 pack is here!
Both MV and MZ looks very good, congratulation for both RMW and Tkool participant!
I definitely can add these characters to use for my game project.

The worst part of game development has to be marketing. Ugh...
May be starting a new job in a month or so. The thought is both exciting and terrifying.
Not like a rollercoaster though. Rollercoasters are just terrifying.
"Merchants don't sell you a product. They sell you something RIGHT NOW. That's all they're selling, the product of having what you want RIGHT NOW and not having to wait for it."

112,476
Messages
1,068,550
Members
146,143
Latest member
marquez19marissa