MV Modifying the Damage Pop Up critical effect trigger conditions

Hi All,

I'm trying to utilize the critical effect in the damage popups to trigger when someone also attacks a targets elemental weakness. I feel like I am al most there. I am working with this bit of code:

JavaScript:
Sprite_Damage.prototype.setup = function(target) {
    this._result = target.shiftDamagePopup();
    var result = this._result;
    if (result.missed || result.evaded) {
      this.createMiss();
    } else if (result.hpAffected) {
      this.createDigits(0, result.hpDamage);
    } else if (target.isAlive() && result.mpDamage !== 0) {
      this.createDigits(2, result.mpDamage);
    }
    if (result.critical || target.elementRate(this._action.item().damage.elementId) > 1) {
      this.setupCriticalEffect();
    }
};

The part I can't quite figure out is how to use this bit correctly:

JavaScript:
target.elementRate(this._action.item().damage.elementId) > 1

It works if I put in a hard number for the element ID like this:
JavaScript:
target.elementRate(2) > 1

But I don't know how to properly call for the currently used skill's element id here. If anyone can help me out I would greatly appreciate it.
The part I can't quite figure out is how to use this bit correctly:

JavaScript:
target.elementRate(this._action.item().damage.elementId) > 1
I'm not at a computer so I can't currently test it, but try changing it to this to see if it works:
JavaScript:
target.elementRate(BattleManager._action.item().damage.elementId) > 1
The damage sprite does not have access to the source action: this._action will be undefined.

When an action starts, it is removed from the subject's action queue (BattleManager.startAction). So I don't think @bass2yang's suggestion will work, but you could always try it~

Instead of target.elementRate(etc), I would try this:
JavaScript:
BattleManager._action.calcElementRate(target)
calcElementRate also accounts for Element: Normal Attack, and will probably interface correctly with any related plugins.

Edit: also, you could patch the method instead of overriding it, e.g. in a plugin:
JavaScript:
;void (function() {  // private scope
'use strict';
  const alias = Sprite_Damage.prototype.setup;
  Sprite_Damage.prototype.setup = function(target) {
    // do the usual thing
    alias.apply(this, arguments);
    // then check for additional crit effect trigger
    if (BattleManager._action.calcElementRate(target) > 1) {
      this.setupCriticalEffect();
    }
  };
})();
The damage sprite does not have access to the source action: this._action will be undefined.

When an action starts, it is removed from the subject's action queue (BattleManager.startAction). So I don't think @bass2yang's suggestion will work, but you could always try it~

Instead of target.elementRate(etc), I would try this:
JavaScript:
BattleManager._action.calcElementRate(target)
calcElementRate also accounts for Element: Normal Attack, and will probably interface correctly with any related plugins.

Edit: also, you could patch the method instead of overriding it, e.g. in a plugin:
JavaScript:
;void (function() {  // private scope
'use strict';
  const alias = Sprite_Damage.prototype.setup;
  Sprite_Damage.prototype.setup = function(target) {
    // do the usual thing
    alias.apply(this, arguments);
    // then check for additional crit effect trigger
    if (BattleManager._action.calcElementRate(target) > 1) {
      this.setupCriticalEffect();
    }
  };
})();
That worked perfectly. Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/modifying-the-damage-pop-up-critical-effect-trigger-conditions.172776/