MV critical hit effect, but only if attack has certain skill.

I have been playing with yanfly's critical hit effect : http://www.yanfly.moe/wiki/Critical_Hit_Effects_(MV_Plugin_Tips_&_Tricks)

I managed to get it to work as shown, ( you just have to add the right header as it got chopped off in copy/ paste)

however I only want it to trigger if an actor has learned a certain skill,
so i added a little bit on the end of the line :


if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical && user.hasSkill(176)) {

and now it is not working at all.

is there a resource that i can read up on what code i should put and where?
thank you in advance
That's valid code.

Try pasting the entire notetag, see if there's an error someplace. Please use the CODE tags (the </> in the edit bar).
sorry it took so long to respond I just got back home.

I tried putting it into a new project again to see if it was some thing else stopping it rather than just my bad code, but all i added to it was the (has skill) bit and it's obviously the only thing stopping it because it works fine without it but it works /all/ the time even when i don't want to.

Code:
<Custom Establish Effect>
// Check if the attack is a physical attack that dealt HP damage from a critical hit.
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
if user.hasSkill(20)) {
  if (target.isAlive()) {
      target.addDebuff(3, 5);
    target.addDebuff(6, 5);
  }
}
}
</Custom Establish Effect>

the only lines I added was : user.hasSkill(20)) { , and an extra } .

thanks again for helping me with this

(p.s) I made sure I added it into the auto state plug in as well obviously, or it wouldn't have worked at all, but I felt like mentioning this as I am likely to get asked otherwise lol

(p.p.s.) never mind, I made sure no one in the party has skill 20 and it is still working anyway. so obviously that line means nothing
sorry it took so long to respond I just got back home.

I tried putting it into a new project again to see if it was some thing else stopping it rather than just my bad code, but all i added to it was the (has skill) bit and it's obviously the only thing stopping it because it works fine without it but it works /all/ the time even when i don't want to.

Code:
<Custom Establish Effect>
// Check if the attack is a physical attack that dealt HP damage from a critical hit.
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
if user.hasSkill(20)) {
  if (target.isAlive()) {
      target.addDebuff(3, 5);
    target.addDebuff(6, 5);
  }
}
}
</Custom Establish Effect>

the only lines I added was : user.hasSkill(20)) { , and an extra } .

thanks again for helping me with this

(p.s) I made sure I added it into the auto state plug in as well obviously, or it wouldn't have worked at all, but I felt like mentioning this as I am likely to get asked otherwise lol

(p.p.s.) never mind, I made sure no one in the party has skill 20 and it is still working anyway. so obviously that line means nothing


never mind lol.


I tried it with a.has skill instead of user and it works like a charm.

thank you anyway
I tried it with a.has skill instead of user and it works like a charm.
that shouldnt be the case. both "a" and "user" refer to the exact same battler within the function that executes that code. if it works with a, it should also work with user

Spoiler
Code:
Game_Action.prototype.customEffectEval =
function(target, stateId, type, side, value) {
    var state = $dataStates[stateId];
    if (!state) return value;
    if (state.customEffectEval[type] === '') return value;
    var attacker = this.subject();
    var defender = target;
    var a = this.subject();
    var b = target;
    var user = this.subject();
    var origin = side.stateOrigin(stateId);
    var s = $gameSwitches._data;
    var v = $gameVariables._data;
    var code = state.customEffectEval[type];
    try {
      eval(code);
    } catch (e) {
      Yanfly.Util.displayError(e, code,
        'CUSTOM STATE ' + stateId + ' CODE ERROR');
    }
    return value;
};

i was going to point out that you were missing an open parentheses for the line you added, but if it works now it works now
if user.hasSkill(20)) {
ahhhhhh, I knew it would be something stupid like that.

I must have unconsciously put it in when I swapped to a. and fixed it lol

I say "something stupid" but syntax is always important, GIGO and all that.

that is actually helpful though as at least now I know what I was doing wrong thanks again
That doesn't explain why the original conditional you had in your first post wouldn't work just fine.

But if you have it working now, then whatever, I suppose.

Original thread: https://forums.rpgmakerweb.com/threads/critical-hit-effect-but-only-if-attack-has-certain-skill.169516/