Damage Formulas 101

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
You should enclose what happens when the "if" is true in {}

Also, using + between each "action" means it will try to add the result of .addState() to the damage value. I dont think thats a good idea and might even cause problems down the line

I suggest to try transforming it into

Code:
if (b.def + b.agi <= (Math.randomInt(20) + 1 + a.mdf + a.mat)) {b.addState(43); Math.randomInt(8) + 1 + a.mdf}; else {0};
See if it works or not.
 

Commanderty

Warper
Member
Joined
Sep 19, 2017
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
You should enclose what happens when the "if" is true in {}

Also, using + between each "action" means it will try to add the result of .addState() to the damage value. I dont think thats a good idea and might even cause problems down the line

I suggest to try transforming it into

Code:
if (b.def + b.agi <= (Math.randomInt(20) + 1 + a.mdf + a.mat)) {b.addState(43); Math.randomInt(8) + 1 + a.mdf}; else {0};
See if it works or not.
This solved one of my problems, the spell is no longer applying the status on a miss. The problem is, that the spell no longer 'hits' anymore, always dealing 0 damage, and never applying the state. It would seem I still have work to do. (I even tried setting the enemy stats to 1's, and the battler's stats to never be low enough to miss, so it's not just bad RNG.)

Thank you for helping, it's nice to see a supportive community :)
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
If it always do 0, its probable that the formula has an error because the damage formula evaluation code is set to do 0 damage if an error occurs
 

Commanderty

Warper
Member
Joined
Sep 19, 2017
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
I hadn't actually figured that out. I changed the else to do 2 dmg, yet the spell still did 0, so it's just an error through and through. Unfortunately I haven't been able to fix it, but I found a neat trick using Yanfly's plug-in for damage over time, and put the damage formula into the state instead of the skill, and that seems to work. Thankfully it was a state set to only last for one round, so it works.

Thank you again for the help :)
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
533
First Language
English
Primarily Uses
N/A
What about an attack that gets stronger if any other party member is below 50% Hp or dead?

Or an attack that crits if a variable is a certain number?
 
Last edited:

MetalKing11417

Veteran
Veteran
Joined
Jul 7, 2018
Messages
81
Reaction score
54
First Language
english
Primarily Uses
RMMV
Okay, so you can use a variable to alter a damage formula, but can you use a formula to change a variable? Also, do a skill's effects occur before or after a formula is executed (so you can use the newly changed variable in say a common event)?
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
Just found this, thank you so much for sharing, this makes my life as person with Syntax Problems so much easier.
++good
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
What about an attack that gets stronger if any other party member is below 50% Hp or dead?

Or an attack that crits if a variable is a certain number?
The first part is easily manageable using the array function .some

Code:
if (a.friendsUnit().members().some(function(member) {return member.hpRate() < 0.5})) 50; else 30;
Where the 0.5 represents the 50% health. The 50 is the increased damage value, and the 30 is the reduced damage value.

To address if any allies are dead you could use something like this (again, 50 is increased damage, 30 is reduced).

Code:
if (a.friendsUnit().deadMembers().length > 0) 50; else 30;
Whether an attack is critical or not is decided Before the damage value is evaluated so would be difficult to control from the damage formula. You may want to look into a plugin to do this for you.

Okay, so you can use a variable to alter a damage formula, but can you use a formula to change a variable? Also, do a skill's effects occur before or after a formula is executed (so you can use the newly changed variable in say a common event)?
You can use this function to control the value of your variables

Code:
$gameVariables.setValue(x, y); damageFormula
Where x = variable id
y = value to be assigned
damageFormula = your normal damage formula

Providing you don't have any plugins altering things your common events should execute after the damage formula is evaluated.
 

bigrockwall

Warper
Member
Joined
Sep 10, 2019
Messages
1
Reaction score
0
First Language
english
Primarily Uses
RMMV
Having some issues getting the if/then in the damage formula to apply state. I want basically the same thing as an earlier post. If (1d20 + a.atk) >= (10 + b.def), apply state to defender.

I tried, and failed, using the following. And a couple variations where I removed some of the () and spaced out the +1.

if (a.atk + (Math.randomint(20)+1)) >= (b.def + 10) {b.addstate(3)} ; else{0} ;

Where state 3 is a stun. Tried it with (3) and (0003) as listed in the database.

That didnt work, just kept rolling 0 damage and not applying the state (had a.atk stat set to 20 and b.def set to 1, so should always apply). Tried both with and without using the semicolons. Any help appreciated.

Edit - is it possible to use note tag instead of damage formula box to accomplish the desired effect?
 
Last edited:

xcom

Veteran
Veteran
Joined
Mar 13, 2013
Messages
241
Reaction score
59
First Language
English
Primarily Uses
Hello!

I can do just about anything with MV, but this combat coding has me feeling like my 6 year old trying to understand how algebra works....

I am trying to turn (for fun) a old Grail Quest: Choose Your Own Adventure RPG book into a free to play MV game. I would like the combat in the game to mimic how it worked in the RPG book.

So like this:

1) Roll 2D6 (so generate a random number between 2 to 12)
2) To HIT you opponent you need to roll higher than the weapon ATK value. (So if the ATK is 6, to hit you need to get a number higher than 6.)
3) The DAMAGE done is equal to the DMG value of the weapon plus every point above the ATK value of what your just rolled. (So if the ATK value of the weapon used was a 6, and you rolled an 8, and the weapon has a DMG value of the weapon is 2, then you did 4 points of DMG.)
4) Then deduct the DEFENSE value of any armor worn (if any at all) from the damage, to get the final damage done. (So if 4 DMG was done from the weapon, but the opponent has a DEFENSE value of 1, then only 3 points of total DMG is done!)

So basically:
IF ROLLED RESULT < ATTACK VALUE then MISSED
IF ROLLED RESULT > ATTACK VALVE then ((ROLLED RESULT - ATTACK VALUE) + WEAPON DAMAGE) - DEFENSE VALUE = FINAL DAMAGE DONE

EXAMPLE:
Rolled a 8 ((8 rolled - 6 ATK) + 2 DMG) - 1 DEF = 3 total damage to opponent

I was thinking of just eventing the combat if I couldn't figure out how to make it work through the normal combat system.
 

J-G

Veteran
Member
Joined
Oct 4, 2019
Messages
605
Reaction score
139
First Language
English
Primarily Uses
RMMV
I'm having issues with my formula. No matter what I do they always yield me 0 damage.
Example of formula used
((8/16) * (level+a.mat)) * 6
I've used variations of this with and without the brackets as well and still a 0
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
@J-G in your formula, you've written "level".
Whose level? a or b?
 

J-G

Veteran
Member
Joined
Oct 4, 2019
Messages
605
Reaction score
139
First Language
English
Primarily Uses
RMMV
Sorry I left that out. It's a's level
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
If it's a's level then you need to write "a.level" otherwise it doesn't know who's level.

So the formula would be
Code:
(a.level + a.mat) * 3
Because of course "(8/16) * 6" simplifies to just 3
 

J-G

Veteran
Member
Joined
Oct 4, 2019
Messages
605
Reaction score
139
First Language
English
Primarily Uses
RMMV
Yeah, just tried it lol didn't realize I was leaving the "a." Part out haha now it works. Thanks so much
 

Nofx670

Villager
Member
Joined
Oct 13, 2019
Messages
6
Reaction score
3
First Language
English
Primarily Uses
RMMV
Hi I'm after 2 things one has already been asked but didn't get a reply

Is it possible to change a variable with a damage formula so I can make a skill that gets stronger the more it's used?

Also is it possible to make a formula that does damage to an enemy and inflicts a state on the party aswell? I tried

A. Addstate(poison) ; && a. Atk * 4 - b. Def * 2

Any help would be much appreciated
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
@Nofx670 -

1) Yes, if its a game variable just do

$gameVariables.set(ID,value)

or if it isnt a GV, just do variable_name = value

before the actual damage part of the formula.

2) Yes, you are almost right, but the code to add state afaik is a.addState(State ID) not Addstate(state name)

Also dont write && after the ;... You dont need &&
 

Nofx670

Villager
Member
Joined
Oct 13, 2019
Messages
6
Reaction score
3
First Language
English
Primarily Uses
RMMV
@Nofx670 -

1) Yes, if its a game variable just do

$gameVariables.set(ID,value)

or if it isnt a GV, just do variable_name = value

before the actual damage part of the formula.

2) Yes, you are almost right, but the code to add state afaik is a.addState(State ID) not Addstate(state name)

Also dont write && after the ;... You dont need &&
I've tried both of those but they come back with no damage or states inflicted and don't change the variable when I check the debug window
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
399
Reaction score
221
First Language
English
Primarily Uses
RMMV
Your above message may have been typed by phone and I appreciate that predictive keyboards make writing code difficult, but if not you need to be careful of the case your typing in. You have a lot of upper case letters where you should be using lower case - this means that the engine isn't recognising the properties and is instead returning undefined, this won't give you any errors in the console because it's expected behaviour. This is likely the reason there's no damage.

Regarding setting the game variable, the correct code is

Code:
$gameVariables.setValue(id, value);

// eg.

$gameVariables.setValue(1, 200);

// Set variable 1's value to 200
I can see no reason that the state codes should not work, unless there has been an error before hand and the damage formula has stopped evaluating. Ideally you want something that looks like this

Code:
a.addState(4); $gameVariables.setValue(1, 200); a.atk * 4 - b.def * 2;
 

Nofx670

Villager
Member
Joined
Oct 13, 2019
Messages
6
Reaction score
3
First Language
English
Primarily Uses
RMMV
Your above message may have been typed by phone and I appreciate that predictive keyboards make writing code difficult, but if not you need to be careful of the case your typing in. You have a lot of upper case letters where you should be using lower case - this means that the engine isn't recognising the properties and is instead returning undefined, this won't give you any errors in the console because it's expected behaviour. This is likely the reason there's no damage.

Regarding setting the game variable, the correct code is

Code:
$gameVariables.setValue(id, value);

// eg.

$gameVariables.setValue(1, 200);

// Set variable 1's value to 200
I can see no reason that the state codes should not work, unless there has been an error before hand and the damage formula has stopped evaluating. Ideally you want something that looks like this

Code:
a.addState(4); $gameVariables.setValue(1, 200); a.atk * 4 - b.def * 2;
Yea sorry that was predicted txt

When typed in the skills box it is correct but still neither seem to work. If I remove the set variables or add state code it works and does basic damage.

I'm wondering if the add state command isn't working because I'm trying to effect the 2 separate targets with the 1 formula.

Thank you for your help
 

Users Who Are Viewing This Thread (Users: 1, Guests: 3)

Latest Threads

Latest Posts

Latest Profile Posts



So I figured out how to put words and pictures in the screen transition. It even wipes away from both the top and bottom. The possibilities are endless! :LZSexcite: I'm going to devise secret messages now for them because I'm a terrible wonderful person like that. :kaopride:
December has arrived and with that, an ¡update for Aletoir Feast! a game made it for the One Map Challenge. I will use some of the remaining switches, variables, and events from the challenge limit to add more content but keep it within the requirements. ¡Have a nice day Everybody!
What I worked on today. :LZSjoy:

No stream today, make a game in MZ is continuing next week!
It seems MOG Weather only has a "clear" function to instantly erase a given weather effect. Probably works well if weather only changes at map transfer, etc, but looks very abrupt if weather effects are continuously changing. So my next challenge: script a "fade" function to gradually fade the sprites and wait to "clear" the current weather until the opacity of all its sprites hits zero... or something like that! XD

Forum statistics

Threads
105,754
Messages
1,016,165
Members
137,439
Latest member
merpmerp
Top