MV Calculating Hit Accuracy and Critical Chance Before Attack Lands

I'm genuinely surprised this question hasn't popped up more often on here but here we are. Just want to warn anyone reading this, it's almost 5 a.m. where I live when I posted this and there's a solid chance there will be spelling errors, things overexplained and left out details. I'll give this thread a look over later in the the day so there may be major edits here in case I miss anything.

Basically, I'm creating a simple little jRPG from my small group of friends since they enjoy playing them. A lot of them are really big fans of Persona and Fire Emblem so I wanted to add in the character cut-in similar to some of the games in those franchises. In case anyone needs a quick example of what I'm talking about (Spoilers for both P5R and FE:A here):

Spoiler: Character Cut-ins Examples


So in my game, my plan was to make it so when a character is about to land a critical hit, the action cut-in would appear for about 90 frames, you would hear a voice line, and the character would hit the enemy. Fairly simple, right?

Only problem is that RPG Maker MV natively checks when an attack is a critical hit, a normal hit, or a miss when the hit lands, not before. Thankfully enough, I have all the Yanfly plugins from before 2017 so I had the idea of running my critical hit formula before the attack happens, then forcing the crit to either come out or not with the action cut-in popping in if it's a guaranteed critical hit. Which I got working wonderfully... however, now this means that I can have critical misses where the cut-in plays and they would have landed a critical hit but instead it misses. Then I thought maybe I'll just add the hit accuracy formula into the action sequence and make it check that first, then roll for crits if it's gonna hit.

I used SergeofBIBEK's Action Sequence Nested if else plugin to set this up and... well now every skill that has this code will hit a crit no matter what? I also experimented with adding states to make the hit a guaranteed hit or miss in case that also becomes a problem but no matter what it doesn't seem to work. Is there an easier way I can do about this? Anyone had success with getting the cutins to happen before crits? I would appreciate any form of help with figuring out how to calculated hit rate and critical rate of a skill before it lands.

Here's what I put in as the action command:

Code:
<setup action>
display action
eval: htr = Math.randomInt(100)
if (100 * ((user.hit + (user.agi / 300)) - (target.eva + (target.agi / 495)))) >= hrt
add state 24: user
eval: crt = Math.randomInt(100)
if (user.cri + (user.luk / 660)) * (1 - (target.cev + (target.luk / 1100))) * 100 >= crt
FORCE CRITICAL
Action Cutin User
se: Crit, 100, 100, 0
wait: 90
else
FORCE NO CRITICAL
end
else
add state 23: target
end
</setup action>
<target action>
motion attack: user
wait: 10
attack animation: target
wait for animation
action effect
remove state 23: target
remove state 24: user
</target action>

Should note that the state 23 boosts the evasion rate to max, while 24 boosts the hit rate to the highest possible.
The cut-in is still working, these formulas have been the same ones I've been using since I started this little project.
The plug-ins I've been using are Yanfly's Battle Engine Core (along with Hit Accuracy, Critical Control, and the Action Sequences packs), Irina's Action Cut-In plugin and SergeofBIBEK's Action Sequence Nested if else plugin. Also, I've noticed this plugin will not work and stops my playtesting almost instantly. I was able to fix it by changing line 200 from
JavaScript:
        if (eval(BattleManager.SergeofBIBEKIfArray[2]))
to
JavaScript:
        if (eval(BattleManager.SergeofBIBEKIfArray[1]))

I apologize if this is formatted poorly as I very rarely post on forums nowadays, I will be more than happy to make edits or provide any screenshots/videos if need be.
Old thread, but I wanted to make this a thing, too. If you're not using Yanfly's Battle plugins, then you can look into using Victor Engine's Critical Hit Effects. It does a lot if you can get it going, but being that it's no longer supported, you're basically screwed if you start running into issues.

I'm using Yanfly's plugins, so that wasn't an option for me. I ended up fiddling around with a lot of the code, and made a solution that ended up working for my purposes. It works on top of Yanfly's Battle Engine Core, and has been working in my tests so far. Definitely a lot harder to figure out than what I expected for something as simple as moving the crit calculation to the start of a turn (mainly because I'm still figuring out how this engine works), but I'm happy with the results.

Put this plugin under the battle plugins, and you're free to use subject._isCritical to check for crits within action sequences. For instance:

JavaScript:
if subject._isCritical
eval: console.log("It's a crit");
else
eval: console.log("It's not a crit");
end

let's you run code depending on whether it's a critical hit or not before the damage calculations actually occur. You can replace the eval lines with common events or whatever else you want to do through action sequences.

Disclaimer: I don't plan on going further with this unless I start running into issues myself, so feel free to modify it as you want. I'm guessing there's already going to be issues if the skill misses, if you're using multi-hit skills, etc. so depending on what you want, this might not be the solution for you.
I'm genuinely surprised this question hasn't popped up more often on here but here we are. Just want to warn anyone reading this, it's almost 5 a.m. where I live when I posted this and there's a solid chance there will be spelling errors, things overexplained and left out details. I'll give this thread a look over later in the the day so there may be major edits here in case I miss anything.

Basically, I'm creating a simple little jRPG from my small group of friends since they enjoy playing them. A lot of them are really big fans of Persona and Fire Emblem so I wanted to add in the character cut-in similar to some of the games in those franchises. In case anyone needs a quick example of what I'm talking about (Spoilers for both P5R and FE:A here):

Spoiler: Character Cut-ins Examples


So in my game, my plan was to make it so when a character is about to land a critical hit, the action cut-in would appear for about 90 frames, you would hear a voice line, and the character would hit the enemy. Fairly simple, right?

Only problem is that RPG Maker MV natively checks when an attack is a critical hit, a normal hit, or a miss when the hit lands, not before. Thankfully enough, I have all the Yanfly plugins from before 2017 so I had the idea of running my critical hit formula before the attack happens, then forcing the crit to either come out or not with the action cut-in popping in if it's a guaranteed critical hit. Which I got working wonderfully... however, now this means that I can have critical misses where the cut-in plays and they would have landed a critical hit but instead it misses. Then I thought maybe I'll just add the hit accuracy formula into the action sequence and make it check that first, then roll for crits if it's gonna hit.

I used SergeofBIBEK's Action Sequence Nested if else plugin to set this up and... well now every skill that has this code will hit a crit no matter what? I also experimented with adding states to make the hit a guaranteed hit or miss in case that also becomes a problem but no matter what it doesn't seem to work. Is there an easier way I can do about this? Anyone had success with getting the cutins to happen before crits? I would appreciate any form of help with figuring out how to calculated hit rate and critical rate of a skill before it lands.

Here's what I put in as the action command:

Code:
<setup action>
display action
eval: htr = Math.randomInt(100)
if (100 * ((user.hit + (user.agi / 300)) - (target.eva + (target.agi / 495)))) >= hrt
add state 24: user
eval: crt = Math.randomInt(100)
if (user.cri + (user.luk / 660)) * (1 - (target.cev + (target.luk / 1100))) * 100 >= crt
FORCE CRITICAL
Action Cutin User
se: Crit, 100, 100, 0
wait: 90
else
FORCE NO CRITICAL
end
else
add state 23: target
end
</setup action>
<target action>
motion attack: user
wait: 10
attack animation: target
wait for animation
action effect
remove state 23: target
remove state 24: user
</target action>

Should note that the state 23 boosts the evasion rate to max, while 24 boosts the hit rate to the highest possible.
The cut-in is still working, these formulas have been the same ones I've been using since I started this little project.
The plug-ins I've been using are Yanfly's Battle Engine Core (along with Hit Accuracy, Critical Control, and the Action Sequences packs), Irina's Action Cut-In plugin and SergeofBIBEK's Action Sequence Nested if else plugin. Also, I've noticed this plugin will not work and stops my playtesting almost instantly. I was able to fix it by changing line 200 from
JavaScript:
        if (eval(BattleManager.SergeofBIBEKIfArray[2]))
to
JavaScript:
        if (eval(BattleManager.SergeofBIBEKIfArray[1]))

I apologize if this is formatted poorly as I very rarely post on forums nowadays, I will be more than happy to make edits or provide any screenshots/videos if need be.

Edit: Slightly misunderstood the initial post, thinking about a solution.
Any chance anyone has figured this out? Been needing to check if an attack will hit before I start the action sequence as I need different animations for hit and miss, which play before the action effect.

Original thread: https://forums.rpgmakerweb.com/threads/calculating-hit-accuracy-and-critical-chance-before-attack-lands.136844/