Original Source
- Original title: MV Calculating Hit Accuracy and Critical Chance Before Attack Lands
- Original author: LansingWolverine
- Original date: May 26, 2021
- Source thread: https://forums.rpgmakerweb.com/threads/calculating-hit-accuracy-and-critical-chance-before-attack-lands.136844/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Javascript/Plugin Support
Summary
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...
Archived First Post
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):
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:
<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
if (eval(BattleManager.SergeofBIBEKIfArray[2]))
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.
Features Mentioned
- Here's what I put in as the action command:
- Code:
- 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
- add state 23: target
Downloads / Referenced Files
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadCreator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
Topic Summary
Loading summary...