State Resist Help

Hello,

I've been using a script with the help of Tsukihime (it was requested a while ago) that when a user hits an enemy weakness, the user is applied with a buff, and the enemy is given a debuff. This is working perfectly, however I want to add a new element to it. Basically, if the enemy has a natural resistance to the debuff, the debuff won't be applied.

However, I haven't been able to apply that to the "if" statement properly. Can anyone help with this?

Code:
Code:
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) {
            if (Math.random() < 1 ) {
          target.addState( 20 );
      this.subject().addState( 12 )
       }
     }

Basically, I want to add a line that says, if the target resists state 20, don't add it. Thanks for the help!

Original thread: https://forums.rpgmakerweb.com/threads/state-resist-help.109414/