MV Track Elemental Damage

Heyho!
After a long break I am back working on our game again and of course I immediately stumbled upon something I can't solve myself ...

I would like to trigger a battle event after a certain amount of elemental damage has been dealt to the enemy. Say, after it lost 100 HP due to fire damage a switch turn on and the event is triggered.

I figured it's best to use Yanfly's Buffs & States Core to create a state with a Custom Respond Effect that somehow tracks all damage done by the element and triggers a switch, when it reaches a certain number ... but that's all I came up with so far.

Thanks in advance 🙂
You said you would use Buffs & States Core, so let's do just that.
Just make a state and input these notetags:

If you use a passive state via YEP_AutoPassiveStates:

Spoiler: Code
JavaScript:
<Custom Battle Effect>
user._damageTracker = 0;
</Custom Battle Effect>

<Custom Deselect Effect>
if (target.result().hpDamage > 0 && this.item().damage.elementId == 1) {
   target._damageTracker += target.result().hpDamage;
   if (target._damageTracker >= 100) {
      $gameSwitches.setValue(X, true);
   };
};
</Custom Deselect Effect>

If you apply the state manually:

Spoiler: Code
JavaScript:
<Custom Apply Effect>
user._damageTracker = 0;
</Custom Apply Effect>

<Custom Remove Effect>
user._damageTracker = undefined;
</Custom Remove Effect>

<Custom Deselect Effect>
if (target.result().hpDamage > 0 && this.item().damage.elementId == 1) {
   target._damageTracker += target.result().hpDamage;
   if (target._damageTracker >= 100) {
      $gameSwitches.setValue(X, true);
   };
};
</Custom Deselect Effect>

NOTE: Make sure you change all the important numbers though.
Namely;
- The element ID
( I used 1 here )
- The required damage (I used 100 here)
- The Switch that you want to activate (Marked by the X)

Also, you can replace "$gameSwitches.setValue(X, true)" with any other code you want
to execute when the threshold is reached.

Lastly, a warning; don't use the name "damageTracker" in another state at the same time since these variables will overwrite each other. Make sure to give each variable a unique name.
Perfect! Thank you su much 😀

Original thread: https://forums.rpgmakerweb.com/threads/track-elemental-damage.146507/