Making a skill do critical damage while a status is applied to an enemy.

So, I want to make a "frozen" status. While frozen, the enemy cannot take actions and when struck by a physical attack, they take guaranteed critical damage, but then are no longer frozen. I've been unable to figure out how to do this, though. I have nearly every VisuStella plugin, so if I need them to use commands or script calls, it's fine. I just can't seem to figure out how to do it.

Essentially: Player deals frozen to enemy > Player hits frozen enemy with physical attack > Enemy takes critical hit damage > Enemy no longer is frozen.
If no one provides you with some VisuStella note tag code to do this between now and the weekend, I can knock this out for you via a very small plugin that you can just add to your project.
I figured out how to edit it in BattleCore. So, I added this line of code under the "Create Base Crit Rate" section but before the notetags, and it worked!
JavaScript:
// Guarantee Phys Crit on Frozen Target
if (target.isStateAffected(19) && this.isPhysical) {
    target.removeState(19);
    return 1;
}
I mentioned this in your other thread, but for anyone who sees this and wants to use it as reference - I don't know how this is working.

isPhysical() is a function, so without the parentheses you should be getting false for checking it as a member variable.
It's a quirk of JS type-coercion: this.isPhysical, a function reference, is truthy. I'm guessing they did not test with a different Hit Type.

Suggestions:
  1. "If target is affected by state 19 and skill/item is Physical Hit":
    JavaScript:
    if (target.isStateAffected(19) && this.isPhysical()) {
  2. "If target is affected by state 19" (this is what your current code does):
    JavaScript:
    if (target.isStateAffected(19)) {
You may also want to separate the removal of the state from the actual crit rate calculation. Partly for neatness (calculating a value is usually a "read-only" operation), and partly for mechanics. E.g. if any actor gets an Auto Battle trait, they will decide which action to use by evaluating each available skill formula against each valid target. Perhaps VisuStella Battle Core has a parameter for "when damage is received" or something like that.

Incidentally, I believe it is possible to do this without a plugin, e.g.
  • Damage formula:

    const r = a.atk * 4 - b.def * 2; if (!b.result().critical && b.isStateAffected(19)) { b.result().critical = true; this.applyCritical(r); } else r;
    I.e. "calculate formula (whatever you like); if not already a crit and the target is affected by state 19, mark this as a crit and return the scaled-up damage; otherwise return the damage as-is".

  • Effect: Remove State 19.
It's a quirk of JS type-coercion: this.isPhysical, a function reference, is truthy.
Oh, it's true because the function exists? As opposed to correctly calling the function and receiving an evaluated result of true. Oh JavaScript 🤣
That was exactly the issue! Oh JavaScript. Thanks for all the help, everyone!
There are situations where it is helpful to have a reference to a function itself, without evaluating it, e.g. checking existence or as a return value for another function. The rule is actually pretty simple, too: JS has few falsy values and everything else is truthy.

Good to hear it's working now! Happy RPG Making~

Original thread: https://forums.rpgmakerweb.com/threads/making-a-skill-do-critical-damage-while-a-status-is-applied-to-an-enemy.159980/