Apply a State when a Critical Hit connects?

Hello! I've been scratching my head over this but I can't find an answer. Maybe you can help?


I want a certain state (actually one of many states at random) to be applied to the target upon a critical hit (sort of an extra effect rather than just multiplying damage).


Similarly, I would like a certain state to be applied to the battler when they have a critical miss or a fumble.


Is there any chance of doing this (with or without plugins)? How can I check the moment a "critical" or "fumble" happens? If I could get a switch to activate I could go from there, but how?
It helps if you know scripting for this kind of thing.


Here's the method for making the damage once the hit has been detected:

Code:
Game_Action.prototype.makeDamageValue = function(target, critical) {
    var item = this.item();
    var baseValue = this.evalDamageFormula(target);
    var value = baseValue * this.calcElementRate(target);
    if (this.isPhysical()) {
        value *= target.pdr;
    }
    if (this.isMagical()) {
        value *= target.mdr;
    }
    if (baseValue < 0) {
        value *= target.rec;
    }
    if (critical) {
        value = this.applyCritical(value);
    }
    value = this.applyVariance(value, item.damage.variance);
    value = this.applyGuard(value, target);
    value = Math.round(value);
    return value;
};

Note that we have an "If critical" code block where we can do things to the "target" that was passed into this method:

Code:
    if (critical) {
        value = this.applyCritical(value);
    }

I would probably insert an "add state" line to this method in order to achieve what you're looking for:

Code:
    if (critical) {
        value = this.applyCritical(value);
		target.addState(11);
    }

Replace 11 with whatever State ID you want to apply.


This all assumes that you want to globally apply the state whenever a battler gets Critted.  If you want to do it only for a single skill, I think you can do that in the skill's Formula box instead.  I think the formula would be something like " if (critical) {b.addState(11);}; (damage calculation here); " but I'm not totally sure.
If you want to have a chance of applying the state add a notetag like this to the skill (remove the "if" case if you want the state to be always applied):


<custom critical code>
 if (Math.random() < 0.5) {
     b.addState(5);
 }
</custom critical code>


@Wavelength


The "critical" local variable is not available at the function that calculates the damage, so it wouldn't work on the damage formula.
@Victor Sant


Thanks, that looks like what I was looking for! I'll give that a try. I have a question:


Is there a way I can check whether the attack is a HIT or a MISS before applying the effect (using Early Critical)?


I want a different effect if it misses (I want to have critical misses).
@Bahamut20


If the attack misses, it skips the whole part of the code that handles the critical (this is why I had to add the 'Never Miss Critical' to avoid those skips). So basically if the attack misses, it ignores the plugin.
@Bahamut20


If the attack misses, it skips the whole part of the code that handles the critical (this is why I had to add the 'Never Miss Critical' to avoid those skips). So basically if the attack misses, it ignores the plugin.



Any way I can make the damage be 0? Let's say, on a critical I do 50% chance it deals no damage whatsoever and 50% it deals double damage.


This is what I have so far (ignore the die variable, it's there for later use when I define all the possible states):

Code:
<custom critical code>
var d2 = Math.randomInt(2) + 1;
if (d2 == 2) {
 var die = Math.randomInt(1) + 1;
 if (die = 1) {
     b.addState(5);
 }
} else {
 var die = Math.randomInt(1) + 1;
 if (die = 1) {
     a.addState(5);
 }
 //set damage to 0
}
</custom critical code>
Any way I can make the damage be 0? Let's say, on a critical I do 50% chance it deals no damage whatsoever and 50% it deals double damage.

If you want the action to be always critical when it don't miss, you can do it by making the action have 100% critical (or more since critical evasion is still considered) and make the action success rate to be = 50% (set on the database, between the action speed and repeat)


Or, if you are using 'Critical Never Miss'. set the action sucess to 0% and the critical rate to 50%.
If you want the action to be always critical when it don't miss, you can do it by making the action have 100% critical (or more since critical evasion is still considered) and make the action success rate to be = 50% (set on the database, between the action speed and repeat)


Or, if you are using 'Critical Never Miss'. set the action sucess to 0% and the critical rate to 50%.



What I want to do is, on a critical, to have a 50% chance of a miss.
What I want to do is, on a critical, to have a 50% chance of a miss.

Then that is not possible with the plugin, as the only influence it have on the hit/miss is to make critical always hit. Other than all interactions are made after the hit is already decided.

Original thread: https://forums.rpgmakerweb.com/threads/apply-a-state-when-a-critical-hit-connects.59067/