RMMV Damage Formula - ideas and help

YoraeRasante

Veteran
Veteran
Joined
Jun 6, 2014
Messages
1,636
Reaction score
417
First Language
Portuguese
Primarily Uses
RMMV
actually @staf00 if that is all the code you don't need yanfly's plugin. That plugin is more for more complicated code.
you just need to put this in the damage formula box:
JavaScript:
(user.isWtypeEquipped(3)) ? (a.atk + a.atk + a.agi) / 2 : (a.atk + a.atk + a.agi) / 3
That in there is a ternary. it is basically (if's condition) ? (if true) : (if false)
as it is just the pure damage there, that is all you need. for more complicated ones you need to remember that the damage given needs to be the last "line" in the whole box, as in to theright of any final ;s.
 

Gooseb90

Veteran
Veteran
Joined
Apr 5, 2020
Messages
49
Reaction score
15
First Language
French
Primarily Uses
RMMV
What's the most efficient way to calculate how much a monster is worth in Gold? Like let's say weaker enemies gives less gold than a stronger enemy, but how do you calculate how much gold the monsters should give if defeated.
 
Joined
Jun 10, 2020
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hello guys, I have 2 questions:
  1. setHp or setMP: does it automatically floor at 0? can this kill?
  2. addState: can it be resisted?
 

jonthefox

Veteran
Veteran
Joined
Jan 3, 2015
Messages
1,423
Reaction score
585
Primarily Uses
I feel like I asked this question a couple years ago, but couldn't find the answer and couldn't find it in a regular search...

How do I make a damage formula with more than one condition? In other words there are 3 cases...

If a.agi > (b.agi * 2) then do normal damage formula * 2
if b.agi > (a.agi * 2) then do normal damage formula * 0.5
if neither of these are true, then just do the normal damage formula
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
99
Reaction score
44
First Language
English
Primarily Uses
Heya, I'm having trouble with a formula. (honestly i dont even know what half the stuff does. I still dont know what ; means, and what : means)

Im making a formula that makes C the same as the targets mp.
then it makes a formula based on C, and assigns it to D. (I plan to change the targets MP before the damage goes out)
so it checks the mp, damages the mp, and then does hp damage to that target, based on the mp they had before they just lost the mp in this very same attack.

but i only wanted it to deal mp damage, IF the target had a state on them.

so i wrote the formula like this
c=b.mp; d=a.atk-b.def-c; if (b.isStateAffected(21)) b.gainMp(-d); d; else a.atk - b.def

the weird thing is, not only does it not work, dealing only 0 dmg, but when broken down into a simpler formula, taking 1 step out, every step works.
for example, if i remove the if
stateAffected part out, the target loses mp, and loses hp just fine.
so
b.gainMp(-d); d; works as is. If i remove the b.gainMp part out, and go with if (b.isStateAffected(21)) d; else a.atk - b.def it works as is, and deals dmg based on the targets mp with the state, but does normal dmg w/o the state.
if i use the if statement to check the state, and deal mp damage, but no hp dmg, it works just fine as well.
if (b.isStateAffected(21)) b.gainMp(-d); else a.atk - b.def
but all 3? it stops functioning.

i can only assume i need something that tells it to do 2 actions under the same if statement. like a sort of
"this & this"; else this

FINAL EDIT: I figured it out. When doing if statements, you can NOT do 2 things. example, you cant apply a buff, a debuff, and do dmg. you can do only ONE thing after an if statement. (idk why) but in the else part, you can do as many multiple things as you want.
so i changed the formula to simply have if(!b.isStateAffected where the "normal" formula happens after the if(! but the actual 2 things i want to happen, due to the buff, happen in the "else"
So it currently looks like
c=b.mp; d=a.atk-b.def-c; if (!b.isStateAffected(21)) a.atk - b.def; else b.gainMp(-a.atk-b.def); d
(I think theres a small error, but this mostly works now, ill fine tune details later)
This is technically all thanks to the following user, despite them not knowing it.

I feel like I asked this question a couple years ago, but couldn't find the answer and couldn't find it in a regular search...

How do I make a damage formula with more than one condition? In other words there are 3 cases...

If a.agi > (b.agi * 2) then do normal damage formula * 2
if b.agi > (a.agi * 2) then do normal damage formula * 0.5
if neither of these are true, then just do the normal damage formula
I believe someone said the answer to this is
If(x){ if(y){a} else{b} }else{c}
but its more to do with the "else". correct me if im wrong.
With the above ex you have 3 possible outcomes, 2 false, and 1 true. (b, c, and a)
so in your question youre looking to see if ppl meet an agi number, but im saying to instead look to see if they fail it twice. if they fail both checks, you get normal dmg (true), and if they meet the checks, they reach the 2 different else (false)

so something like if(fails equation1){ if(fails equation2){normal dmg} else{ * 0.5 dmg} }else{*2 dmg}

Also, thanks for asking this question, because the solution to this question, ended up being the solution to my own problem. I just had to invert what the if question was asking.
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
FINAL EDIT: I figured it out. When doing if statements, you can NOT do 2 things. example, you cant apply a buff, a debuff, and do dmg. you can do only ONE thing after an if statement. (idk why) but in the else part, you can do as many multiple things as you want.
This is incorrect. If you try to write two things in the else part, the second thing will always be done even if it didn't run the else. The correct way to do multiple things in an if or else is either to enclose them in {curly braces}, or to separate them with a comma ( , ) instead of a semicolon ( ; ). (In the second method you still need a semicolon before the "else".)

so i changed the formula to simply have if(!b.isStateAffected where the "normal" formula happens after the if(! but the actual 2 things i want to happen, due to the buff, happen in the "else"
So it currently looks like
c=b.mp; d=a.atk-b.def-c; if (!b.isStateAffected(21)) a.atk - b.def; else b.gainMp(-a.atk-b.def); d
(I think theres a small error, but this mostly works now, ill fine tune details later)
This is technically all thanks to the following user, despite them not knowing it.
This will always deal d damage no matter whether or not the state is affected. The game parses it like this:

  1. Set the value of c to the opponent MP
  2. Set the value of d to your formula
  3. If opponent is not affected by state 21, do nothing
  4. Else (opponent is affected by state 21), take MP from the opponent
  5. Finally, return d as the HP damage
Note the "do nothing". If you write a formula in an "if", the only thing it does is "store" that value to be returned at the end of the formula. However, anything else you do after that (unless it's in the corresponding "else") will overwrite that stored value, which is what happens in this case with d because it's not in the else (the else only takes one statement).
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
99
Reaction score
44
First Language
English
Primarily Uses
The correct way to do multiple things in an if or else is either to enclose them in {curly braces}, or to separate them with a comma ( , ) instead of a semicolon ( ; ). (In the second method you still need a semicolon before the "else".)
Im a bit confused which part this is addressing, as the quoted part is then mentioned again, but as if talking about a different quoted part.

but, to see if i understand this, things in {these} are the same as just doing , this, correct?
so if(b.isStateAffected(21)) {b.gainMp(-d) d}; else a.atk - b.def is the correct way to do it? (also if (b.isStateAffected(21)) b.gainMp(-d), d; else a.atk - b.def works too?)

you also said it looks at an if statement to store a value, how would i then use that value, if its not from a formula within the if statement? would it be something like
c=b.mp; d=a.atk-b.def-c; e=0; if (!b.isStateAffected(21)) e=c; else b.gainMp(-a.atk-b.def); d+e
Something like that?
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
Im a bit confused which part this is addressing, as the quoted part is then mentioned again, but as if talking about a different quoted part.
I'm not entirely sure what you are confused about, but my intent was to point out that it's not accurate that "if" supports one thing while "else" supports multiple, and to explain why the way you made use of that belief would produce the wrong result.

but, to see if i understand this, things in {these} are the same as just doing , this, correct?
so if(b.isStateAffected(21)) {b.gainMp(-d) d}; else a.atk - b.def is the correct way to do it? (also if (b.isStateAffected(21)) b.gainMp(-d), d; else a.atk - b.def works too?)
Only one problem with your blue version, you need a semicolon before the d for it to work. The green version looks correct, and assuming the added semicolon, both versions are equivalent.

you also said it looks at an if statement to store a value, how would i then use that value, if its not from a formula within the if statement?
I'm not sure how much detail I should go into on this... I'll try to keep it simple. The game splits what you write up into a series of statements. Exactly what makes a statement is a little complicated, so I won't go into details, but I'll try to summarize the most important points:
  • Basically anything ending in a semicolon is a statement.
  • If you separate statements with a comma instead of a semicolon, they are still executed the same way, but the engine treats them as a single statement.
  • You can use {curly braces} to group statements, similar to how (parentheses) group expressions. So basically with curly braces you can make several statements be treated as one statement.
  • An if or else must be followed by exactly one statement, but that statement can be several statements enclosed in {curly braces}.
  • The engine executes the statements in order. With if and else, it skips the one statement that doesn't match the if condition, so that statement never gets executed. This (coupled with the below point) is why something of the form if(a.isStateAffected(4)) a.atk; else a.mat can work, because only one of those two statements is executed.
  • Every time the engine executes a statement, it stores the result of that statement in a special "result" area. If the statement is something that's not an expression (such as a.gainMp(-d)), then it will clear the special result area, like setting it 0! Once it has executed the final statement, the contents of that result area is returned as your damage value. It's like there's an invisible variable that every statement assigns to, which is what's actually returned to the game.
This borders on explaining how JavaScript works, because the formula box is just some JavaScript code that the engine executes to determine the damage value, but hopefully I managed to keep it simple enough?

As a side note (and you can ignore this part if it seems too complicated for you), you can also use a functional if (more like Excel). This looks like (condition ? value_if_true : value_if_false). (The parentheses aren't technically part of the syntax, but they help make it clearer in my opinion.) So that answers your question earlier about what a colon (:) means - it's like a shorthand for "else", while the question mark is like a shorthand for "if".
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
99
Reaction score
44
First Language
English
Primarily Uses
I think I get "enough" of what you're saying.
Thank you, I think i can use what you said to figure out anything else I may need.

I see why you answered in the manner you did, as it said a lot of... what might appear to be"unrelated" information, but was a necessary foundation, to make heads and tails of the language.

It is unfortunate that its more of a language, than it is an... equation. (If that makes sense, since both equally describe eachother...)
Its kind of odd you still need ; to separate paired statements from eachother, when they are already paired with {}. But it makes sense when you use , since the coma isnt at the end like the brackets are.
but thank you!
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
Well, I think the intent was for it to be an equation, and it's fine to think of it as an equation if you don't use any semicolons in your formula. But on a technical level it's actual code you write that the engine just calls into, so theoretically you can do anything JavaScript can do.
 

Nate_Tillern

Villager
Member
Joined
Apr 14, 2019
Messages
8
Reaction score
0
First Language
English
Primarily Uses
RMMV
So I followed glasses guide to get the supposedly proper function names, but my formula is resulting in 0 damage every time so obviously I've got something wrong.
Here's what I thought would work:

Math.max((level + Math.pow(a.atk,1.2) - Math.pow(b.def,1.1)) * (1 + (Math.random() * a.luk) / 100),1)

So if the damage formula actually returns 0 then 1 should be the damage dealt. Otherwise should be dealing more damage than 1, never should return zero. I've got two exponents and one random number call.

Any help is greatly appreciated
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
Just a small error - it should be a.level instead of just level.

If there's an error in the formula, RMMV will make it return 0.
 

Nate_Tillern

Villager
Member
Joined
Apr 14, 2019
Messages
8
Reaction score
0
First Language
English
Primarily Uses
RMMV
Just a small error - it should be a.level instead of just level.

If there's an error in the formula, RMMV will make it return 0.
Thank you Solar_Flare for the quick response! My heroes are now doing damage in what seems like the proper way with the "a.level" edit! I've been testing them against a base enemy with 1 for all stats (except hp), and when it attacks it's still doing 0 damage to my heroes, do you know if I'm specifying the Math.max() function incorrectly as well by any chance? I thought if the first formula in Math.max() did <=0 then following it with ",1" would cause Math.max() to return 1.

Edit: Since monsters don't have a level would that cause an error thus leading to zero?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
Edit: Since monsters don't have a level would that cause an error thus leading to zero?
Yes, that's exactly it. If you want all monsters to be treated as level 1, a quick fix would be to write (a.level || 1) instead of a.level. You could replace 1 with whatever alternate value you want, or even a formula (with an extra set of parentheses, ie (a.level || (some_formula))).

The non-existent level for enemies turns into a special value called NaN that infects everything it touches - NaN + x is always NaN, Nan * x is always NaN, and even Math.max(NaN, x) is always NaN. The || operator however (which means "or") is not affected and returns the right hand side if its left side is NaN (it also returns the right side if its left side is 0 though, so don't use it on something for which 0 is an acceptable value).
 

PauloHPBender

Delirious Storyteller
Veteran
Joined
Oct 16, 2015
Messages
92
Reaction score
22
First Language
Portuguese
Primarily Uses
N/A
Here's my main attack (and most favourite) damage formula:

a.atk * (a.atk/b.def)
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
99
Reaction score
44
First Language
English
Primarily Uses
Here's my main attack (and most favourite) damage formula:

a.atk * (a.atk/b.def)
jooc why did u go with this one?

(For my players, i go with a simple atk-def, but for enemies, i give them different formulas, depending on various factors. the main issue people have with the atk-def is easily solvable with many methods, which is why i make it adjustable on the enemies side. plus other work around, by using stats other than defense for lowering player dmg, if i needed to.)
 

PauloHPBender

Delirious Storyteller
Veteran
Joined
Oct 16, 2015
Messages
92
Reaction score
22
First Language
Portuguese
Primarily Uses
N/A
After many tests, this formula gave me what I wanted; a way multiply (or divide) the base damage according with the stats; a Attack that is twice the Target's defense will deal double damage. A defense that is twice the Attacker's attack will result in half damage. The attacking side remains in numerical advantage, making basic attacks still relevant.

On a unrelated note, what exactly does "jooc" means?
 
Last edited:

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
90
Reaction score
60
First Language
French
Primarily Uses
RMMV
Hi everybody, I'm stumped with trying to find a formula I need for a skill. It's supposed to deal damage to an unpredictable number of enemies that can be not all of them, and the damage is split between the targets affected.
The problem is that I can't find anything to put in the damage formula that would return the number of units affected so I can make the division.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
On a unrelated note, what exactly does "jooc" means?
Just out of curiosity.

CHKNRAVE, I'm at the shops just now but I'll take a look at your request in a bit.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
To the best of my knowledge, the damage formula has no idea how many targets are affected, so I think this will likely require a plugin.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

I guess if you're just going solo dev, minimize features is better choice.
As close as possible, now I draw all of them with little by little needle sticking.
Welp, back to the drawing board...
Ami
--- Overused ---

Hero: (Drink 3 HP Bottle L)
F.Healer: Don't drink too much,or you got sick!
Hero: Nah,i'm okay. it's the way to repleni---
(Hero Collapse)
Hero: (Weak) Ugh...my head (Coughing Then Vomiting)
F.Healer: I told you to don't Drink 3 HP Bottle L or you're Sick. Let's go to Doctor.
Shaking off the dust. Clearing the cobwebs. Time to get back to gam-mak!

Forum statistics

Threads
103,215
Messages
998,048
Members
134,692
Latest member
Matkacharts
Top