I'd like to make a "sacrificial" type class that consumes hp when mp is not enough

The title is a bit self explanatory. I want to create a class that casts magic, but with the gimmick that the cost of spell is with mp, but when there isn't enough or mp is 0, it begins to consume hp equaling the difference between the cost of the spell and the current hp. For example, I want to cast a spell that costs 20 mp, but I have only 15, and as such I will consume 5 hp to cast the spell along with the mp. Any ideas?
you'll need a plugin for advanced skill mechanics, where you use javascript code to process that.
and in javascript you check if there is enough MP and if not calculate the added HP-cost and reduce that.

you would need that for every skill used by that actor, which means he needs his own skill list.

Original thread: https://forums.rpgmakerweb.com/threads/id-like-to-make-a-sacrificial-type-class-that-consumes-hp-when-mp-is-not-enough.164596/