Player damage taken into variable?

I know you can set a variable to the current hp and then check for changes but this will also take into account healing, what i need is to record all damage taken into a variable cumulatively while also ignoring any healing done.

If the player takes 100 dmg, heals 80 then takes 200 and heals 50 the variable should be at 300, ignoring the 130 healing done.

Anything that helps me do this is appreciated 👋
I feel like this was just asked, like, within the past few days...that wasn't you, right? 🤣

Using Yanfly's Buffs and States and Auto Passive States, put a passive state on the actor and give it this notetag:
Code:
<Custom React Effect>
if (this.isDamage())
    target.damTaken+=value;
</Custom React Effect>

Then you can just refer to the battler's damTaken variable wherever you like (e.g. a.damTaken in a damage formula).

At the beginning of your game, include an autorun event that runs this script call:
Code:
for (var i=0; i<$dataActors.length; i++)
    $gameActors.actor(i).damTaken=0;

just to make sure you never accidentally refer to one that's undefined.
I dont have yanfly buff and states core but this seems a simpler approach so i will pop that on my project and test it, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/player-damage-taken-into-variable.153131/