Method for putting variance directly in Damage Formula?

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
Hi there! I'm making a skill that drains HP and MP at the same time, which is requiring me to use a somewhat complex equation. For now the formula is marked as HP Drain in the dropdown box, and has this formula:

Code:
m = Math.min(a.mat - b.mdf * 2, b.mp); a.gainMp(m); b.gainMp(-m); a.atk * 6 - b.def * 2
It does drain both correctly, the one problem I'm having is that the variance on the skill only applies to the HP drain part of the formula. Is there a way to put in a variance for the MP Drain as part of the formula?

For example, without variance, a given use of the Skill does exactly 24 MP Drain. I want it to instead have a 20% variance and do between 20 and 27 MP Drain. I tried using math formulas to do it, but since the formula only seems to handle integers, I tried multiplying the percent variance by 100 and then divide the whole thing by 100 afterward. It ended up looking like this:

Code:
m = Math.round((Math.min((a.mat - b.mdf * 2) * (Math.floor(Math.random() * 140) + 80)) / 100, b.mp)); a.gainMp(m); b.gainMp(-m); a.atk * 6 - b.def * 2
For the example given above, instead of landing between 20 and 27 like I want, it does 184 without any variance. So either my math is way off, or I'm not using the formulas correctly. Could anyone help me with this?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
If you want it to drain between 20 and 27 damage, you would replace m with 20 + some command which gives a random number between 0 and 7. That will make it between 20 - 27.
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
No, I'm only using that as an example for comparison between what the attack would do with or without variance. It's not doing a set amount of damage, but a.mat - b.mdf * 2, and I just want it to calculate for a 20% variance.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
I see now. The issue was indeed the math. I think you want * 40 instead, not 140, as * 140 is increasing it by 140%, not 40% like you want, as the variance is 40% of the total.
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
Thanks for that correction! I also realized I was accidentally using math.min instead of math.floor, and that i don't really need to use math.round. It still was not working properly, but then I ALSO realized that I had misplaced a parentheses or two in the math functions and adjusted accordingly. My new formula is:

Code:
m = Math.floor(((a.mat - b.mdf * 2) * (Math.floor(Math.random() * 40) + 80)) / 100), b.mp; a.gainMp(m); b.gainMp(-m); a.atk * 6 - b.def * 2
I also realized that as long as I have Math.floor at the end, I don't need to worry about decimals, so I simplified it further:

Code:
m = Math.floor((a.mat - b.mdf * 2) * (Math.random() * 0.4 + 0.8)), b.mp; a.gainMp(m); b.gainMp(-m); a.atk * 6 - b.def * 2
This seems to be working! I've tested it several times and the MP drain seems to be within 20% variance of expected values.

I can summarize this below for anyone else who needs help with this.

Where the original skill formula = [FORM], and the variance you want is x (30% = 0.3), your damage formula will be as follows:

Code:
Math.floor([FORM] * (Math.random() * (2x) + (1-x))
Thanks for your help! I guess I'm good at math, but bad at syntax.
 
Last edited:

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

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top