Successful State Applies State Resistance

I'll try to make this as straightforward as possible. I want bosses to be affected by powerful states like Silence and Paralysis, but I don't want them to be crippled by endless applications of those states. I'd like to make it so when one of these states is successfully applied to an enemy, the skill in question also applies a state that makes them immune for an extended period of time. So whenever an enemy is paralyzed for ~3 turns they become immune to paralysis for ~8 turns.

What's the easiest way to do this? I only really use Yanfly scripts to avoid conflicts, but if necessary I'm open to experimenting with others.
onremove: this.addState(X)

When the stun/whatever is removed, this can apply the "resistant" state. I don't remember which plugin it is, but I'm like 92% certain it's a yanfly one
Thank You. I googled the text and discovered the script was made by Shaz. It's working as intended and I'm not noticing any (immediate) conflicts with Yanfly. Fingers crossed it stays that way!

Original thread: https://forums.rpgmakerweb.com/threads/successful-state-applies-state-resistance.132861/