Yanfly Critical Control Formula

I'm trying to use Yanfly's Critical Control with this formula as my Critical Hit Rate:


rate = user.cri + Math.max(user.hit/(target.eva+1)-1, 0) - target.cev;


(What I'm trying to do here is make any extra accuracy turn into critical chance)


Thing is, is I don't think it's working at all. I haven't researched too much into this one, but I seem to get critical hits, just not nearly as often as I should be.


I was wondering if either I made some sort of error in my typing, or if I'm unable to use Hit Rate and Evasion in the Critical Rate formula since they're also Ex-Parameters.
Let's see...I'll do a math check here. Assuming to hit is 95%, eva is 5% (defaults), and CRI is 0% by default (same with CEVA), we get:


0 + max(0.95/(0.05 + 1) - 1, 0) - 0, 0.05 + 1 is 1.05, so you have:


max(0.95/1.05 - 1, 0) + 0, 0.95/1.05 is 0.90 (the / takes priority over the - by order of operations rules), now,so 0.90 - 1 is -0.10, which would be no chance for a critical hit. So with defaults it sounds like it is working perfectly, as you should never get a critical hit with this formula under the default to hit and to eva rates, unless you give the person CRI.
Heh, yeah, I probably should have specified more. Sorry about that, I was in a bit of a rush when I originally made this post.


I do not use the basic parameters(such as 95% Hit, 5% Eva). On average, each character has 100% Hit and 0% Eva when they have no equipment at all. When I tested this I gave my Archer a Bow that had around +1000% Hit (I gave it +100% Hit a lot of times, for testing purposes).


The Critical Rate seems to be actually pretty accurate, ignoring the Hit Rate part.


My theory on why I think is happening (specifically) is that RPG Maker cannot find the Hit Rate and Evasion Rate because they are Ex-Parameters, and Critical Rate is also an Ex-Parameter. Because of that, it marks those as just '0' since it can't find them. Although I'm not too good/knowledgeable at coding, so I wouldn't know for sure if that was the issue, or if it would work if I typed it out differently. 


Personally, I don't really care if there's an alternative to doing this, I just want the Actor's Accuracy to increse their Critical Chance(or something), cause it's annoying when you have a 140% Chance to hit someone, but that extra 40% is kind of going into nothing...
Hmmm....I think the problem might be that in traits it will ignore the extra +100%? Any way to confirm that the actor really has 1000% to hit?


Otherwise, the problem might be the choice of user.hit and user.cri. There are times I've noticed the program requires it to be self instead of user (not sure when or why, my JavaScript knowledge is low), but see if it works better with self.cri and self.hit (or maybe combination of the two?)
I think the problem might be that in traits it will ignore the extra +100%? Any way to confirm that the actor really has 1000% to hit?

I know for a fact that it stacks, cause I can see the percentages and all that sort of stuff from Yanfly's StatusMenuCore, and it's saying that I have 5100% when equipping my new testing weapon.


Also, I just did another test. The enemy had +1000% Evasion 4 times, and the Actors in my party could never hit it. After equipping the Bow with +1000% 5 times, she always hit.


She never did any Critical Hits in that battle, but I wasn't doing that battle for that reason anyway.


I went around and fought other enemies that have no Evasion or Critical Evade Rate, but still didn't get any Critical Hits.


I didn't think it was because I was using user.stat rather than self.stat, but I thought it was worth a try, at least, so I changed the Critical Rate formula to this, for my next test:


rate = user.cri + self.cri + Math.max((user.hit+self.hit)/(target.eva+1)-1, 0) - target.cev;


(I put the self.cri and self.hit in places where the system could use both user.stat and self.stat for the formula and use whichever one is right.)


I still didn't get any Critical Hits on any enemies.


For this entire test, my Archer had 5100% Hit Rate (because of the testing item), and 0% Critical Rate(since I was testing for Hit Rate to give criticals).


All the enemies I fought had 0% Evasion and 0% Critical Evasion Rates.


Thanks for responding so quickly, by the way.
You can't have both user.hit and self.hit in the formula, as one of them will probably not work, and turn the formula to garbage. When that happens, it always returns 0. So one of them isn't right. The problem is, I don't know which one, so you may have to experiment and see.


I also did the calculations on your example of 140% to hit, 0% eva, 0% Cri and 0% CEVA, I came up with about 33% chance of a critical hit, and your case of 5100% should be hitting all the time.
You can't have both user.hit and self.hit in the formula, as one of them will probably not work, and turn the formula to garbage. When that happens, it always returns 0. So one of them isn't right. The problem is, I don't know which one, so you may have to experiment and see.

I had thought originally that it was turning the variables that it didn't recognize as 0(not all of the equation), cause the Critical Rate part of it was still working. But after you said that, I thought more about it, even tested it, and now I realize that it's not turning those variables to 0, but it's not turning the formula directly to 0 either- it's actually just reverting to the default Critical Rate formula.


I'm glad I made that mistake regardless, cause now I understand the system ever so slightly more. Or at least the plug-in, if not the system.

I also did the calculations on your example of 140% to hit, 0% eva, 0% Cri and 0% CEVA, I came up with about 33% chance of a critical hit....

That calculation wasn't necessary, I was just putting that out there for the concept.


But wait... With the formula I gave you, wouldn't it be 40%? 😳

...your case of 5100% should be hitting all the time.

Exactly, which is just proof that the formula isn't working correctly.


Okay, I changed the formula to this:


rate = self.cri + Math.max((self.hit)/(target.eva+1)-1, 0) - target.cev;


And then tested it. And it got the same results- A normal amount of Criticals (this time I tested with 10% Critical Rate along with my 5100% Hit Rate), but it was only about 10%, which I expected it to be.


I just don't think there's any self.stat things here, especially since the default formula for the plug-in is:


rate = user.cri * (1 - target.cev);
Ok, strange idea. What happens if you give the target 5% EVA on your original formula? Does it start to work then? If so then form some reason it is doing target.eva + 1 - 1, which is division by 0 with 0 evasion. That shouldn't happen with the formula as you posted it, but if you have an extra ) in your formula it will do it.


Try it with 5% EVA and let me know. If that works, then we found the problem.


Though...the math is a little screwy with that \ step once the targets get evasion. You might wish to change the formula inside the Math.max to this:


user.hit - target.eva - 1.00


And yes, it needs to be 1.00, else it will convert your final answer to an integer, which would make 1.4 - 0 - 1 = 0 in the end (which is not what you want).
Ok, strange idea. What happens if you give the target 5% EVA on your original formula? Does it start to work then? If so then form some reason it is doing target.eva + 1 - 1, which is division by 0 with 0 evasion. That shouldn't happen with the formula as you posted it, but if you have an extra ) in your formula it will do it.


Try it with 5% EVA and let me know. If that works, then we found the problem.

I did a direct Ctrl+C and Ctrl+V and turned its font to Courier New, the formula I'm using is not any different than shown above.


And I coincidentally did fight an enemy with 100% Evasion with my 5100% Hit Rate Bow and it still did not do any Critical Hits.


And if you need to know, I'm using Yanfly's HitAccuracy plug-in to have all of my abilities' accuracy go as follows:


((userHitRate+(skillHitRate*100/24)-1) / ( 1 + targetEvadeRate ))

Though...the math is a little screwy with that \ step once the targets get evasion. You might wish to change the formula inside the Math.max to this:


user.hit - target.eva - 1.00

I don't see how that / is screwy... it simply uses multiplication/division which is a ton easier to balance than addition/subtraction, and it's been working very well up till I used it in the Critical Rate Formula (which you know how that's going), but I dought that's the reason why it's messing up.

And yes, it needs to be 1.00, else it will convert your final answer to an integer, which would make 1.4 - 0 - 1 = 0 in the end (which is not what you want).

Hm... I didn't know the system worked like that. I'm unsure if the system does that with multiplication/division as well, so I changed my formula to: 


rate = user.cri + Math.max((user.hit)/(target.eva+1.00)-1.00, 0.00) - target.cev;


Basically the same as my original, but with decimal points.


After testing this formula, (just to make sure), I still couldn't get any Critical Hits.


Know any alternatives to affect Critical Rate in any way using other Ex-Parameters? Cause I don't think that Yanfly's Critical Control Plug-In is gonna work for this, but I'm unsure what WOULD work for affecting Ex-Parameters with other Ex-Parameters. I'm open to any suggestions. 
The reason the / is screwy is if you have 140% to hit and 5% EVA, it is not 35% to critical like it sounds you want, but 33% (due to 1.4/1.05). It gets worse if you ever have someone with 100% EVA, as your to hit is halved now before the bonus is figured out. But if you're ok with that, then leave it.


I think you have something else messing with it at this point. The formula should not have a problem. I may have to download the plug-in and test it at this point (as I mainly use ACE as you can probably see). But that formula should work in both ACE (with a little tweaking, as ACE doesn't use Math.max) and MV.
The reason the / is screwy is if you have 140% to hit and 5% EVA, it is not 35% to critical like it sounds you want, but 33% (due to 1.4/1.05).

As I said before, the general stats that I use are 100% Hit Rate, 0% Evasion, and 0% Critical, so having 140% Hit Rate should generally give 40% Critical Chance, since most enemies do not have/use evasion.

It gets worse if you ever have someone with 100% EVA, as your to hit is halved now before the bonus is figured out.

Rarely will someone actually ever have that much evasion, but a few enemies do if they're supposed to be really fast and/or hard to defeat. And your Accuracy being halved is exactly the intention of 100% Evasion, as it would basically double the length that that actor/enemy is in battle for. That way, weaker people can have more realistic health while still lasting as long as I want them to.

But if you're ok with that, then leave it.

Yup! Everything works exactly how I want it to, and the Critical Rate Formula would work as well, if it actually- well, you know- worked.

I think you have something else messing with it at this point. The formula should not have a problem. I may have to download the plug-in and test it at this point (as I mainly use ACE as you can probably see). But that formula should work in both ACE (with a little tweaking, as ACE doesn't use Math.max) and MV.

Alright. I still think the problem is that Ex-Parameters are modifying other Ex-Parameters, but then again, I'm not too good at coding, so I wouldn't know.


Anyway, thanks for trying to help. Here's where I downloaded the plug-in at, if/when you wanna try it yourself:


http://yanfly.moe/2015/11/08/yep-26-critical-control/

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-critical-control-formula.66155/