Method for putting variance directly in Damage Formula?

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
99
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,101
Reaction score
13,596
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
99
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,101
Reaction score
13,596
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
99
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 Posts

Latest Profile Posts

// Looks at Elfkisser, realizes he'd have to either install Windows 10 or compile it for Linux
// Didn't install Elfkisser.
Too much effort for a curiosity. :popcorn:
I was just high-fiving myself for all I've learnt in the engine, and how far I've come, only to forget to remove the Immortal state from a semi-scripted battle. Now the enemy never dies and I feel so smart >.>
Playtest your stuff. Always playtest.
just spent FOREVER troubleshooting an issue with my keyboard... turns out the cord was just loose OTL
I count on someone one time, I let them promise something to me, and one week later it's complete silence as I'm completely let down. I hate everything.
Everytime I need to write dialogues I find myself writing new music pieces... what kind of trick is this?!

Forum statistics

Threads
99,222
Messages
963,194
Members
130,813
Latest member
Gremter
Top