hit and crit overhaul

My first instinct was to use Yanfly's hit accuracy and crit control plugins, but I don't know if that will work with what I want to do because I want the crit chance calculation to be incorporated into my hit chance calculations.


I have separate but similar formulae I want to use for checking if magic and physical attacks hit and crit.
Physical:
Attacker's luck is multiplied by 1-10.
Defender's agility is multiplied by 1-10.
If the the resulting luck value is equal to or greater than the defender's agility value after each are multiplied by the randomizers, the resulting luck value is equal to or greater than the resulting agility value, the attack hits.
If the resulting luck value is at least 2x the resulting agility value, the hit is a crit.

Magic will follow a similar calculation but use 1/2 m.atk + 1/2 luck vs 1/2 m.def + 1/ agility

I think I could probably figure out how to do most of the hit calculations with the hit accuracy plugin, but I don't know how I could manage to incorporate the rules for crits into that- or whether or not I can, or should go about this a different way entirely.
You can do all of this with the plugins you mentioned.

You'd just want to store the result of the hit roll in a variable so it can be referenced a few steps later in the critical calculation.

Do you know how to write out the formulae?
You can do all of this with the plugins you mentioned.

You'd just want to store the result of the hit roll in a variable so it can be referenced a few steps later in the critical calculation.

Do you know how to write out the formulae?
I think I can define the hit rates, but not 100% on how to define the formula itself.
I've been brushing up on js lately and I THINK it would be
user.luk * (Math.floor(Math.random() * 10))
target.agi * (Math.floor(Math.random() * 10))
to define the hit and evade rate with the randomizers, but I don't know if that's correct, nor do I know how how I would define the actual accuracy formula to say that it hits if user.hit >= target.eva
Instead of doing Math.floor() wrapped around Math.random(), just use Math.randomInt(n). That gives a random number from 0 to n-1, inclusively.

So, going off your first post:

Physical:
Attacker's luck is multiplied by 1-10.
Code:
user.luk * (Math.randomInt(10) + 1)

Defender's agility is multiplied by 1-10.
Code:
target.agi * (Math.randomInt(10) + 1)

If the the resulting luck value is equal to or greater than the defender's agility value...the attack hits. If the resulting luck value is at least 2x the resulting agility value, the hit is a crit.
With those plugged into the plugin parameters for User Physical Hit and Target Physical Evade, when you're doing the actual Accuracy Formula you need to set a switch to track whether it should be a critical later. I'll use switch ID 42, you replace that with whatever ID is available in your project:
Code:
s[42] = userHitRate >= targetEvadeRate * 2; userHitRate >= targetEvadeRate ? 1 : 0

nor do I know how how I would define the actual accuracy formula to say that it hits if user.hit >= target.eva
I used a ternary operator, which has the format if ? then : else

Magic will follow a similar calculation but use 1/2 m.atk + 1/2 luck vs 1/2 m.def + 1/ agility
So User Magical Hit would be
Code:
user.mat * .5 + user.luk * .5 + user.mdf * .5 + 1 / user.agi

I don't know how I could manage to incorporate the rules for crits into that
You'd make the Critical Rate Formula be
Code:
s[42] ? 1 : 0
Instead of doing Math.floor() wrapped around Math.random(), just use Math.randomInt(n). That gives a random number from 0 to n-1, inclusively.

So, going off your first post:


Code:
user.luk * (Math.randomInt(10) + 1)


Code:
target.agi * (Math.randomInt(10) + 1)


With those plugged into the plugin parameters for User Physical Hit and Target Physical Evade, when you're doing the actual Accuracy Formula you need to set a switch to track whether it should be a critical later. I'll use switch ID 42, you replace that with whatever ID is available in your project:
Code:
s[42] = userHitRate >= targetEvadeRate * 2; userHitRate >= targetEvadeRate ? 1 : 0


I used a ternary operator, which has the format if ? then : else


So User Magical Hit would be
Code:
user.mat * .5 + user.luk * .5 + user.mdf * .5 + 1 / user.agi


You'd make the Critical Rate Formula be
Code:
s[42] ? 1 : 0
Thanks for the help.
Just to confirm my understanding:

rondomInt returns a whole number, so I don't need to round it.

s[x]: is that how to call a switch ID defined in the games settings?
It looks like it's formatted as an array, so wouldn't I want the number there to be 1 lower than the actual switch ID, because indexes count from 0?

"s[42] = userHitRate >= targetEvadeRate * 2; userHitRate >= targetEvadeRate ? 1 : 0"
It looks like we're plugging this into the accuracy formala, the first part s[42] = userHitRate >= targetEvadeRate * 2 isn't being touched by the formula to make a calculation, it's just there to grab the numbers created with the randomizer so that it can be called when we plug it into the crit formula later, then after the semi colon is what the acurracy formula is actually working with, right?

then when we plug
s[42] ? 1: 0
into the crit formula, it's saying if userHitRate >= targetEvadeRate * 2 return 1, else return 0?
wouldn't I want the number there to be 1 lower than the actual switch ID, because indexes count from 0?
Its true that array indices start at 0, but if you put something into [42], it goes into [42]. As long as you access [42] when trying to retrieve it, its not going to move.

Also the engine itself uses the variable/switch id when manipulating stuff in the data arrays. Switch 1, despite arrays starting from 0 is [1]
Just to confirm my understanding:

rondomInt returns a whole number, so I don't need to round it.
Yes, that's what an integer is.

s[x]: is that how to call a switch ID defined in the games settings?
Yes, in this context.

It looks like it's formatted as an array, so wouldn't I want the number there to be 1 lower than the actual switch ID, because indexes count from 0?
No, they don't.

1730921591876.png


All of the database categories in MV have a null 0 index and start at 1.

the first part...isn't being touched by the formula to make a calculation, it's just there to grab the numbers created with the randomizer so that it can be called when we plug it into the crit formula later
Mostly yes; it's setting the switch to true or false, not actually grabbing any numbers.

then after the semi colon is what the acurracy formula is actually working with, right?
Correct.

then when we plug
s[42] ? 1: 0
into the crit formula, it's saying if userHitRate >= targetEvadeRate * 2 return 1, else return 0?
Not "return," but yes, produce that value.
awesome, thanks for the clarity.

Original thread: https://forums.rpgmakerweb.com/threads/hit-and-crit-overhaul.173064/