Yanfly Custom Counter Conditions Non-functional

Hello. I seem to have stumbled upon an oddity in Yanfly's Counter Control plugin.

Spoiler: Click for pic
46dee77ba1.png

As my game right now is set up, a skill is suppose to grant a passive state, which grants a chance to counter with the skill shown in the pic. As you can see, the custom counter condition simply sets the condition to false, which should mean the counter doesn't occur. However, the counter always occur, regardless of whatever I put between the Custom Counter Condition notetags. I don't even receive an error when I put in garbage between the notetags.

I have a suspicion this is an issue with the plugin itself, and am proficient enough in digging around javascript to be able to fix it if I was told what to do. If there was a way for Counter Condition to check multiple skill types and only need one of them, I could use that and that would solve my problem. Otherwise, it's anyone's guess what's going wrong.

Thank you for your response,
DarkMatt.
Could you please edit your post to include a link to the particular web page on Yanfly's site where you got that plugin. That way, if anyone needs to check something in it, they won't have to go hunting.
Thanks.
I think the first step would be to check a few other points, because yanfly's plugins are usually bug-free but require a few special checks.

1) Please check if your plugin order is EXACTLY the same order as given on Yanfly's website. If you place his plugins in any other order, you'll run the risk of non-functional or strange behaviour.
If you don't know, please post screenshots of your plugin manager and we can check for you.

2) a lot of his plugins create errors or problems if the projects corefiles are too old.
Please go to your project folder, into js and open rpg_core.js with a text editor. What is the version number in the title line? no number means 1.0
I have added a link to the plugin in question to the thread.

I think the first step would be to check a few other points, because yanfly's plugins are usually bug-free but require a few special checks.

I have went and double-checked and though I believe it is in the right order, another pic doesn't hurt.

Spoiler: Click for new pic.
f1903ba1d3.jpg

I have also checked rpg_core.js and its version is 1.5.1. Furthermore, I am using RMMV 1.5.1.
You're missing spaces in your eval. It should be

condition = false;

Yanfly has a bunch of examples for all notetags on the website, including Custom Counter Condition.
"condition=false;" and "condition = false;" is functionally the same. Javascript cares a bit but syntax but not enough to be sensitive about spaces. That case compiles into the same set of commands.

If you don't believe me try it yourself. The default damage formula in skills is a good place to test out "a.atk - b.def" and "a.atk-b.def". They both do the same thing, and whether you include spaces or not is a matter of personal preference.
"condition=false;" and "condition = false;" is functionally the same. Javascript cares a bit but syntax but not enough to be sensitive about spaces. That case compiles into the same set of commands.
Notetags are not exactly javascript.
I agree that it probably would not make a difference in this case, but there are a lot of cases where the correct number of spaces is vital for a notetag, so it can't hurt to test either.

What you've forgotten here is that the notetag is read by the plugin, usually through a regex for identification, before the result of that identification is processed - sometimes directly as an eval, sometimes manually without eval.
Without knowing how a specific plugin works, you can't automatically assume that spaces are not needed, because the regex might need them.

In this case it's extremely likely yanfly pushed it directly into an eval function, yes, but that is not automatically true.
Those are very good points you've brought up, and I believe you. I do believe though that most plugins, if you can plug in javascript into the notetags, is equipped to parse it just like javascript. However, if some other plugin is parsing it there may be exceptions.

Unfortunately that is not the case here. "condition = false;" has the same effect as "condition=false;" for this skill. Though it should never be proccing the way it's configured now, it still is.
The code should be:
condition = user.isStateAffeceted(x);

Where x is the state you want to turn on the condition.

condition = false; in this plugin means the counter isn't going to work at all, while true meanbs it's going to work every singhle time.
You'd use condition = false/true if you need an if/else statement like:
If(user.level > 3 && user.hpRate < 0.3){
condition = true
} else {
condition = false;
}
Ie if the user level is more than 3 and their Hp rate is 30% or lower than this is true, else it's false.
The code should be:
condition = user.isStateAffeceted(x);

Where x is the state you want to turn on the condition.

condition = false; in this plugin means the counter isn't going to work at all, while true meanbs it's going to work every singhle time.
You'd use condition = false/true if you need an if/else statement like:
If(user.level > 3 && user.hpRate < 0.3){
condition = true
} else {
condition = false;
}
Ie if the user level is more than 3 and their Hp rate is 30% or lower than this is true, else it's false.
Uhh, what is this reply even talking about? My issue is that it's still countering when when condition = false; is suppose to make it not work at all.

I can easily code up whatever I want if the plugin itself worked, but if it can't even do what you thought "condition = false;" would do, then I may have a bit more of an issue then just javascript not working as intended.
Out of curosity, does the person who's using the skill have the ability to counter? ie the actor has CNT parameter set to some percent?
I've been busy since then but after reading this code correctly I have found the issue.

Spoiler: Clik for pic (It's a pic of Yanfly's Counter Control plugin
836f8d7e61.png

That line marked "Problem line." is always returning true, ending the function early without evaluating the code in the notetag. Far as I can tell, this is because the plugin itself is having difficulties reading the code in the notetag. Further testing shows that the plugin properly reads the code for custom counter condition when reading the notetag, but the stored code is no longer there when the Problem line is parsed. This can, far as I know, mean a few things: the plugin isn't properly storing the custom code, or the plugin is referencing the wrong variable, or something else I might not know of.

If you want more snippets of the code behind custom counter conditions, lemme know and I'll post them.

I have figured out what's going wrong: there was a missing "return false;" in the code. Not in the pic, but in the function immediately before, that called this function. So I fixed that.

Now I've found an oddity. The function in that pic looks at the skill triggering the counter, not the target's counter skills. That means it evaluates the condition on the triggering skill instead. I don't know if this is intended behavior or not, but if it's supposed to be looking at the counter skill instead of the triggering skill, how can I change the code in that pic to reference the counter skill instead?
how did you fix this?? it's so hard to debug yanfly's code by myself
how did you fix this?? it's so hard to debug yanfly's code by myself
Enough experience to interpret javascript and enough time reading the plugin itself to understand what it's doing. Honestly I cheat because I've read enough code to learn how to write my own, but I wouldn't call myself no coder. I just know how to furiously debug and test code to get to the bottom of issues.

Now, I didn't fix the problem at the time of that post, but I have now. If I recall correctly, for people who know this sort of stuff, line 1098 of this plugin is missing "return false;" at the end of its if condition check. What this means is that, even if it's true, nothing happens, and this is a big deal because the function that line's in checks to see if the custom counter conditions are met or not. To fix this, you need to add in "return false;" at the end of that line.

I might be wrong because I'm going off memory instead of reproducing the problem. (Laziness is also why I'm not a coder.) But it should be something like that. Honestly this error's solvable by someone like me because it's a clerical error.

Oh those clerks.

If you can talk to yanfly please let him know of this bug. Til then, there's your solution.
glad that you have fixed it however mine still didn't work even after adding the return false. i tried putting a custom counter condition in the skill notetag with just "condition = false;" it still returned true and continued casting the counter skill. i'll try debugging this with my best shot it's delaying my game making.

edit: i found out that "<counter condition>" has a regexp issue thats why some notetag lines doesn't work. I can't find the solution for the lunatic conditioning so i think this will be better i have a fix for it that suits my need but i don't guarantee its 100% working.
glad that you have fixed it however mine still didn't work even after adding the return false. i tried putting a custom counter condition in the skill notetag with just "condition = false;" it still returned true and continued casting the counter skill. i'll try debugging this with my best shot it's delaying my game making.
I might've done more than that, if that isn't fixing it. Now that I've stopped being lazy and have cross-referenced my edits with the plugin available online, I've noticed something else I've had to do.

Replace line 1105 with this line: "if (skill.counterConditionEval === '') return true;"
Also, replace line 1115 with this line: "var code = skill.counterConditionEval;"

What I recall learning is that those two lines originally didn't reference the skill's notetag and referenced something else entirely. I think I proved that back then, but I didn't leave the debug commands in to keep the proof around, so you and I have just gotta take my word for it. Lemme know if that fixes it.

Also disclaimer in advance, I am not entirely certain if these edits work completely fine without any unforseen consequences.
HAHAHA why just now :kaosalute:! it worked thank you so much dude. ill be posting if there are errors that might happen in the future. silly me the error's right in front of my face. i've done also another fix but regarding the <counter condition> notetag. if u try using "Attacker hp > 0" or similar it won't work.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-custom-counter-conditions-non-functional.91416/