MV Counter Control (YEP)

Good morning, first of all I apologize for my English.
You will see I am new to the forum, I had never decided to register, but there is a question that I cannot solve, despite all my attempts.
Specifically, it deals with this condition.

<Counter Condition>
Defender hp <= Defender.mhp * 0.80
</CounterCondition>

In principle everything should be correct, but there is no way to make it work. Someone had the same problem? Thank you very much in advance.
The right-hand side looks like JavaScript, which would mean it is case-sensitive. Try this?

<Counter Condition> Defender hp <= defender.mhp * 0.80 </Counter Condition>
Plugin link, for reference:
thanks for answering!!

It still doesn't work, even though the plugin prompts are fine in theory.
However with other basic conditionals, this is fine.

<Counter Condition>
physical hit
</CounterCondition>

I can't find anyone who talks about it either, so I must be doing something wrong, or maybe few people use this variant of the plugin, or know how to solve it.
but there is no way that it works with % of your life.
It appears to be a bug in the plugin. The regular expression that's getting the condition to be evaluated is flawed.

The function (checkCounterAttacker() and checkCounterDefender()) that parses the parameter and then adds the rest of the condition is looking for the first argument to be "hp," "mp," etc. But what's getting passed in is the parameter and the operator, so "hp <="

This causes the rest of the function to fail because "hp <=" is never equal to "hp".

Unfortunately, I don't know enough about regular expressions to fix the parsing that's done between lines 1227-1235.

Fortunately, it's really easy to ignore the Attacker and Defender conditions. Anything you would type there, you simply enter as an Eval condition instead, e.g.
Code:
Eval: defender.hp<=defender.mhp * .8
Oh, that's interesting. What it should be doing is getting the left side (hp) and the right side (<= defender.mhp * 0.8). However, based on my copy of YEP_X_CounterControl (v1.10), it looks like it is actually passing the same value (left side) for both inputs, yielding the nonsense eval defender.hp hp. [Edit: see follow-up posts!]

Lines 1229 (DEFENDER param eval) and 1234 (ATTACKER param eval) both look like this:
JavaScript:
      var value2 = String(RegExp.$1);
You could try editing them to this:
JavaScript:
      var value2 = String(RegExp.$2);
I.e. the value from the second capture group of the most recently-evaluated regular expression.

Or just use the eval approach ATT_Turan suggested~ 👋
However, based on my copy of YEP_X_CounterControl (v1.10), it looks like it is actually passing the same value (left side) for both inputs, yielding the nonsense eval defender.hp hp.
Interestingly, the first part is not what I'm getting.

I stuck a console.log at the beginning of the function and it is saying the v1 argument is what I mentioned before, the left side and operand.

So your fix doesn't work in my v1.10 - the v1 and v2 do now correctly add up to the entire evaluation, but because the operand is in v1, all of the contains() checks fail.
Oh, I didn't actually test, sorry! 😅

OK, take 2. I think the problem is that by default all regular expression matches are greedy (i.e. longest possible match), so the first capture group (.*) (zero or more *, of "any" character .) captures the entire line.

So, in addition to what I suggested previously, you can also try replacing line 1227:
JavaScript:
    } else if (line.match(/ATTACKER[ ](.*)[ ](.*)/i)) {
...with this ([^\s]* means "zero or more non-space characters"):
JavaScript:
    } else if (line.match(/ATTACKER[ ]([^\s]*)[ ](.*)/i)) {

And line 1232:
JavaScript:
    } else if (line.match(/DEFENDER[ ](.*)[ ](.*)/i)) {
...with this:
JavaScript:
    } else if (line.match(/DEFENDER[ ]([^\s]*)[ ](.*)/i)) {
I still haven't tested this, but hopefully that'll hit the mark. Thanks to @ATT_Turan for pointing that out! 👋
Oh, I didn't actually test, sorry!
Heh, who tests anything?

So, in addition to what I suggested previously, you can also try...
This all works perfectly. Regular expressions are definitely a gap in my knowledge, but they just seem so...tedious.

I know your MV thread has some extension plugins for Yanfly stuff - would you add this anyplace in there, or do you mind if I add it to mine for posterity/reference?
Good morning, thanks for answering, I finally managed to fix it, I have a friend who fixed the problem in five minutes, in my case I have an old version, 1.07, apparently there was a line where I put //line and that caused the error

Anyway, I saw in the patches on the official page, that in version 1.10 this problem was fixed, thanks to all, greetings.
@ATT_Turan - great! Feel free to incorporate it into your own plugin/fix list, I doubt I'll write one myself.
I'm glad it's working for you. However,
in my case I have an old version, 1.07
You really should consider using the current version of everything. Counter Control is not even considered fully compatible with MV version 1.5, which could lead to other glitches. And if you're using a version of MV's scripts older than 1.5, that may cause bugs in your published game.

Anyway, I saw in the patches on the official page, that in version 1.10 this problem was fixed
That's not correct. As you can read above, both myself and caethyril did all of our testing using version 1.10. Your bug is with the Attacker and Defender conditions, not the Counter Hit condition which is what is fixed in the 1.10 patch notes.

Good luck with your project!

Original thread: https://forums.rpgmakerweb.com/threads/counter-control-yep.153509/