MV [Help with Yanfly's Critical Hit Effects] The paste code seems to be not working.

I want to introduce passive states that can be obtained through out the game that give different benefits, ranging from stats to unique effects and one of those I want to do is Critical Hit Effects and I found yanfly's example and for some reason it is not working.

Other codes from his tips&tricks work just fine, but for some reason this is the only one that seems to do nothing. I am not an expert at all at Java script, I just know the basics to edit these things to suite my own needs, but the thing is the base code that he provides doesn't even work for me.

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) {
// Create an ATK buff that lasts 5 turns.
var param = 2;
var turns = 5;

// Create an AGI buff that lasts 5 turns.
user.addBuff(param, turns);
var param = 6;
var turns = 5;
user.addBuff(param, turns);

// Check if target is alive.
if (target.isAlive()) {

// Create a DEF debuff that lasts 5 turns.
var param = 3;
var turns = 5;

// Create an AGI debuff that lasts 5 turns.
target.addDebuff(param, turns);
var param = 6;
var turns = 5;
target.addDebuff(param, turns);
}
}


I just want to get it working and thats it, from there I can figure things out myself as I just wanted to make passives that give like +1 ATK or +1/DEF then getting crits or applying states.

If anyone has a solution to this thank you!
Are you pasting that whole thing in there? It looks like it's missing the "<" at the start

It should look like this I think.

<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) {
// Create an ATK buff that lasts 5 turns.
var param = 2;
var turns = 5;

// Create an AGI buff that lasts 5 turns.
user.addBuff(param, turns);
var param = 6;
var turns = 5;
user.addBuff(param, turns);

// Check if target is alive.
if (target.isAlive()) {

// Create a DEF debuff that lasts 5 turns.
var param = 3;
var turns = 5;

// Create an AGI debuff that lasts 5 turns.
target.addDebuff(param, turns);
var param = 6;
var turns = 5;
target.addDebuff(param, turns);
}
}
</Custom Establish Effect>

So an example would maybe be

Code:
<Custom Establish Effect>
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
 if (target.isAlive()){
 target.addDebuff(3,5);
 }
}
</Custom Establish Effect>

Something like that possibly, Someone could please check my work as I just started teaching myself js pretty much yesterday
Edit: I think I missed a part, fixed, and then there is spacing stuff I'm still learning\

but yeah that's just Params, which is basic stats, if you wanted to do something that added States you would use target.addState which I think is easier to make states with all the debuffs/buffs you want for special situations instead of coding them in individually
Are you pasting that whole thing in there? It looks like it's missing the "<" at the start

It should look like this I think.

<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) {
// Create an ATK buff that lasts 5 turns.
var param = 2;
var turns = 5;

// Create an AGI buff that lasts 5 turns.
user.addBuff(param, turns);
var param = 6;
var turns = 5;
user.addBuff(param, turns);

// Check if target is alive.
if (target.isAlive()) {

// Create a DEF debuff that lasts 5 turns.
var param = 3;
var turns = 5;

// Create an AGI debuff that lasts 5 turns.
target.addDebuff(param, turns);
var param = 6;
var turns = 5;
target.addDebuff(param, turns);
}
}
</Custom Establish Effect>

So an example would maybe be

Code:
<Custom Establish Effect>
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
 if (target.isAlive()){
 target.addDebuff(3,5);
 }
}
</Custom Establish Effect>
OH now this make more sense! Thank you! I knew something was wrong and I just realised the copypaste thingy on his site is actualy flawed, as it is missing < thingy and it should have "Custom Establish Effect" instead of just Establish effect as I just added those both and it works now!
Something like that possibly, Someone could please check my work as I just started teaching myself js pretty much yesterday
Edit: I think I missed a part, fixed, and then there is spacing stuff I'm still learning\
Welp it helped me so it looks fine!
but yeah that's just Params, which is basic stats, if you wanted to do something that added States you would use target.addState which I think is easier to make states with all the debuffs/buffs you want for special situations instead of coding them in individually
Oh cool, that just makes it easier, as one of the things that I want to make is like a stacking system. a passive ability which gives you a state, while you have it, every time you crit, you gain a stack, and for each stack you get +20% critical damage but it also reduces your critical chance for that battle.
Oh cool, that just makes it easier, as one of the things that I want to make is like a stacking system. a passive ability which gives you a state, while you have it, every time you crit, you gain a stack, and for each stack you get +20% critical damage but it also reduces your critical chance for that battle.

If it's from the same skill you'll have to make it check for states so you can progressively add the new state or replace it with a higher tier version of it.

But if all you want is for your criticals to increase your own critical power and lower your critical chance. You might just want parameters with that, or maybe utilize a bit of the YEP Critical Control plugin

And you're welcome. I'm glad it worked I'm still not confident in my coding.
Just as a quick note for both posters above - you should always use the CODE tags (the </> in the edit bar) when posting code.

Otherwise, as you can see, indenting is not kept and anything inside brackets can be interpreted as BBCode (see how the OP's code turned italic).

Original thread: https://forums.rpgmakerweb.com/threads/help-with-yanflys-critical-hit-effects-the-paste-code-seems-to-be-not-working.154476/