MZ Creating a Method to use in Skill Damage Formula

Hello all!

I'm looking to make some "easy of access" methods for the Skill Damage Formula. The damage formula I'm planning on using are based a lot of D&D, so there are a lot of "dice rolls" rather than calculating a direct number and just varying it by a certain percentage.

Rather than writing out Math.round(rand() * 6) for a d6 every time (I know that's probably wrong, just pseudocode), it would be easier if I could just write out d6() to get a random number between 1-6. Anyone know how I could do that.

I should clarify, it's not the contents of the function I need help with (i.e. I know how to get a random number), it's actually being able to access the method from the Skill Damage Formula section.
If you want to be able to use the user/target information conveniently, define it inside Game_Battler so you can say

Code:
a.yourMethod
b.yourMethod

If you just need to be able to reference it as a global function, you can just define it in global space

Code:
function d(num) {
   return Math.round(rand() * num)
}

And then you can just use it in your formula.

Code:
d(4) - b.def
It's just a JS eval after all.
If you just need to be able to reference it as a global function, you can just define it in global space

Code:
function d(num) {
   return Math.round(rand() * num)
}

And then you can just use it in your formula.

Code:
d(4) - b.def
It's just a JS eval after all.
That was exactly what I was looking for! Thank you kindly 🙂

Original thread: https://forums.rpgmakerweb.com/threads/creating-a-method-to-use-in-skill-damage-formula.126700/