Parameter Based Auto-State Removal

Hello. I'm in the process of game development, and three things that caught my eye is Yanfly's Auto Passive States and Buffs & States Core plugins, as well as the Actor Transformations tips and tricks video.

Speaking of the third video, I'd like to make a variant of the transformation where the "transformed" state is instead a passive that automatically removes itself when the associate actor's MP hits 0%, and then gets re-added when their MP rises back to a specific percentage, let's say 100%.

The problem is, I'm still something of a coding newbie and don't have the skills necessary to go about this efficiently. Anyone have a way to go about this?

Original thread: https://forums.rpgmakerweb.com/threads/parameter-based-auto-state-removal.101768/