MZ Hit Accuracy Formula

Howdy, gonna keep it short and sweet. Using MZ.

Basically trying to overwrite the default accuracy formula in how it's calculated for everything.

Code:
If DMG >= DEF = 100% Accuracy, Certain Hit, no chance to miss
Same for crits/magic, no critical/magic evasion, if your attack crits, it crits
All rolling against the EVA stat only if DEF > DMG

The only way accuracy/evasion kicks in and takes into effect is when Attacker's Damage is less than Target's Defense.

For example:
Code:
Attack deals 50 Damage with Skill A
Target has 100 Defense
(DEF - DMG) = 50 pt DIFF
Increase evasion by = DIFF / (DIFF + 99)
50 / (50+99) = 33.56% Evasion Rate

Attack deals 50 Damage with Skill A
Target has 51 Defense
(51 - 50) = 1 pt DIFF
1 / (1 + 99) = 1% Evasion Rate

Attack deals 1 Damage with Skill B
Target has 999 Defense
(DEF - DMG) = 998 pt DIFF
998 / (998 + 99) = 90.98% Evasion Rate
So even with an almost 1000 pt difference in Defense and Damage, the Attacker will still have a 9.02% chance to hit

Something like?
Code:
const def = target.def;
const diff = def - damage
if (diff <= 0) {
     return 0;  // 100% hit chance if damage is greater than or equal to defense
} else {
     return diff / (diff + 99);  // Evasion rate calculation
}

That's pretty much it. I thought there was a way to edit there accuracy formula using VS plugins like you could with Yanfly's but maybe I'm overlooking it.



I think this would probably be a plugin request. As now that I'm thinking more about it, this would be fundamentally changing how hits are determined. Since this would technically be calculating your damage then rolling for accuracy check, rather than rolling for accuracy and then damage. But maybe it's simpler to achieve than I'm thinking.
The issue i see what that is that it goes against the default order of things. damage isnt calculated until after the hit check is performed, and is only done if it passes.

That's pretty much it. I thought there was a way to edit there accuracy formula using VS plugins like you could with Yanfly's but maybe I'm overlooking it.
you could go into the rmmz_objects js file, copy the Game_Action.apply, Game_Action.itemHit, and any other functions relating to this, and change them to be more more in line with what youre trying to (running makeDamageValue() before running itemHit(), but still not executing the damage until unless it hit, changing itemHit() to factor in def, removing CEV from the crit chance formula, etc.).

modifying itemHit is already more or less what the yanfly hit accuracy plugin does, it just lets you do so thorough parameters. i dont think that plugin let you run damage calc before hit chance is rolled, but regardless, you can do it yourself.
For what it's worth, I have a Hit Formula plugin for MZ linked to in my signature, and caethyril also has one in her MZ collection.

But @Robro33 is correct, it's weird to claim you're using the damage to affect the chances of hitting - that's the point of the hit formula, if it fails you don't hit to do any damage.

Unless your damage formulae aren't actually formulae but flat numbers, so you're using them as a sort of hit modifier.
For what it's worth, I have a Hit Formula plugin for MZ linked to in my signature, and caethyril also has one in her MZ collection.

But @Robro33 is correct, it's weird to claim you're using the damage to affect the chances of hitting - that's the point of the hit formula, if it fails you don't hit to do any damage.

Unless your damage formulae aren't actually formulae but flat numbers, so you're using them as a sort of hit modifier.

Yeah, I'm trying to do some weird stuff with the formulas.
For now I've been playing and tweaking with it in a google spreadsheet.
Now I'm trying to put it into practice in the engine.
Appreciate yall!

It's kinda like a pseudo armor class from DND.
Where if your damage roll is greater than or equal to the target's ARC then the attack always lands.
Otherwise, if the target's ARC is greater than the damage roll, instead of completely missing like DND, there is instead the Evasion formula that takes into effect.

Hope that helps explain it better!
It's kinda like a pseudo armor class from DND.
Hope that helps explain it better!
Not super much...D&D still has discrete rolls for hitting and damage isn't rolled if they're not successful.

But you do not need my understanding to make your game work the way you want 😀

You could use notetags from VisuStella Battle Core or my Eval Tags to do calculations and change the hit result after damage is calculated but before it's inflicted.
Not super much...D&D still has discrete rolls for hitting and damage isn't rolled if they're not successful.

But you do not need my understanding to make your game work the way you want 😀

You could use notetags from VisuStella Battle Core or my Eval Tags to do calculations and change the hit result after damage is calculated but before it's inflicted.

Yer, it's pretty much just combining the two, Attack Rolls and Damage Rolls, together. Instead of rolling for hit and then damage, just roll for damage. If DMG > DEF = HIT; otherwise, follow the EVA formula.

It's more of a 'Deflection' rather than an accuracy miss in my game. Where if your DEF outmatches their damage output, you have a chance to deflect the attack completely.



That's what I've been trying to do but I think I'm not entering the right js and using the correct reference calls/syntax. Mostly have been using the forums, Trihans Tips & Tricks, youtube, etc. on implementing VS/action seq/notetags for custom effects. But I've been unsuccessful in my attempts at getting it to work so far.


Spoiler: Resources
You would start by using a plugin like my Hit Formula to get rid of the original hit roll in the engine. Make all attacks hit by default.

Then:
If DMG >= DEF = 100% Accuracy, Certain Hit, no chance to miss
Your Actors/Enemies have:
Code:
<JS Pre-Damage as User>
if (value < target.def)
{
// (DEF - DMG) = 50 pt DIFF
   let diff = target.def - value;
// Increase evasion by = DIFF / (DIFF + 99)
    if (Math.random() < target.eva + (diff / (diff + 99)))
    {
        value = 0;
        target.result().evaded = true;
    }
}
</JS Pre-Damage as User>
Code:
<JS Pre-Damage as User>
if (value < target.def)
{
// (DEF - DMG) = 50 pt DIFF
   let diff = target.def - value;
// Increase evasion by = DIFF / (DIFF + 99)
    if (Math.random() < target.eva + (diff / (diff + 99)))
    {
        value = 0;
        target.result().evaded = true;
    }
}
</JS Pre-Damage as User>

You sexy bastard you. I was kinda close!
I'm always getting confused vs vars, let, and const.
My original attempt:
Code:
<hitformula>
const def = target.def;
const diff = def - damage
if (diff <= 0) {
     return 0;
} else {
     return diff / (diff + 99);
}
</hitformula>
I'm always getting confused vs vars, let, and const.
There's really not much difference in the context of a notetag. The salient thing is if you say const you can't then change that variable's value with any math.

If you don't understand the three, there's really no reason not to simply use var all the time. It doesn't matter.

My original attempt:
The problem is this is doing exactly what Robro and I said you couldn't do.

Rolling to hit occurs before damage is calculated, so there's no way you could use a hit formula plugin that incorporates the damage into it.

And you're including this damage variable that my documentation doesn't tell you exists.

You're also using return statements, which don't function in notetags.

Good luck with your project!
There's really not much difference in the context of a notetag. The salient thing is if you say const you can't then change that variable's value with any math.

If you don't understand the three, there's really no reason not to simply use var all the time. It doesn't matter.


The problem is this is doing exactly what Robro and I said you couldn't do.

Rolling to hit occurs before damage is calculated, so there's no way you could use a hit formula plugin that incorporates the damage into it.

And you're including this damage variable that my documentation doesn't tell you exists.

You're also using return statements, which don't function in notetags.

Good luck with your project!

Appreciate it king.
Yer, I try and make do with what I can and turn to forums when I really have a question.
Just getting back into the swing of things after a bit of a break so I'm a lil rusty.
Got that summer time sunshine motivation to work on something 🙂



Thanks again! Just finished a bunch of testing and it works! Appreciate y'alls help and input.

Now if Enemy has 999 Defense and Actor has an 10 Attack;
Enemy Evasion will increase by 90.09%;
Actor still has a roughly 10% chance to land an attack to still do 10 damage

My armor deflection system is in working order now 😀
Topic can be closed <3

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/hit-accuracy-formula.168285/