Gain status upon hitting enemy resist?

Hello,


I came upon this snippet made by Tsukihime... It allows you to have a chance to inflict a status, in this case stun, on an enemy once you hit their weakness. What I want to add to the code is an else case, where if you hit them with a weakness they resist, you have a chance of stunning, or inflicting a state on yourself.


Essentially, both the enemy and player can benefit for hitting weaknesses, and can be punished for hitting resistances.


Here's the original thread:




and here's the code:

Code:
[COLOR=rgb(0,0,0)]var TH_GameAction_calcElementRate = Game_Action.prototype.calcElementRate;
Game_Action.prototype.calcElementRate = function(target) {
    var rate = TH_GameAction_calcElementRate.call(this, target);
    if (rate > 1) {
       // random number between 0 and 1
       if (Math.random() < 0.35) {
         target.addState( 30 )
      }
    }
    return rate;
};[/COLOR]
Bumping to get some help.
var TH_GameAction_calcElementRate = Game_Action.prototype.calcElementRate;
Game_Action.prototype.calcElementRate = function(target) {
var rate = TH_GameAction_calcElementRate.call(this, target);
// Hit a weakness
if (rate > 1) {
// random number between 0 and 1
if (Math.random() < 0.35) {
target.addState( 30 )
}
}
// Hit a resist
else if (rate < 1) {
// 50% chance to inflict state 30 on target, or 50% chance to inflict state 31 on attacker
if (Math.random() < 0.5) {
target.addState( 30 );
}
else {
this.subject().addState( 31 );
}
}
return rate;
};


Something like that
This works perfectly.


Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/gain-status-upon-hitting-enemy-resist.63989/