MV "Passive Ability" which subtracts the current TP from all incoming damage and removes said TP if possible.

I'm working on a game with a large roster of characters, and each one has several MP and TP moves, however, I want one of these characters, one who primarily uses MP attacks, to have a special trait in which they take TP damage before starting to lose HP, for example, if a default attack hits them for 40 damage, and they have 20 TP in storage, they would only take 20 damage, and lose their 20 points of T. (not accounting for any other modifiers such as DEFENSE)
If this is possible the help would be greatly appreciated!
If this IS possible, would it be possible for defense to also affect the TP loss?
Hmmm something like this with Yanfly States:

<Custom React Effect>
if (value <= user.tp) {
user.gainTp(value * -1);
value = 0;
} else {
value -= user.tp;
user.gainTp(user.tp * -1);
}
</Custom React Effect>

EDIT: Switched the order of lines
Hmmm something like this with Yanfly States:

<Custom React Effect>
if (value <= user.tp) {
user.gainTp(value * -1);
value = 0;
} else {
value -= user.tp;
user.gainTp(user.tp * -1);
}
</Custom React Effect>

EDIT: Switched the order of lines
Where do I put this? I've tried placing this in the notes of a new state and the actor themselves and neither have the expected result.
Hmmm replace all 'user' with 'target' (I though it was other way around for Yanfly)

EDIT: put it in state notetag
I got it working! Tysm 😀
Hmmm replace all 'user' with 'target' (I though it was other way around for Yanfly)

EDIT: put it in state notetag

Original thread: https://forums.rpgmakerweb.com/threads/passive-ability-which-subtracts-the-current-tp-from-all-incoming-damage-and-removes-said-tp-if-possible.181656/