Can i create a skill absorbing an active state?

Hello everyone! I hope you all are having a good day.
I was wondering if i can make a skill that would "absorb" a state.
For example, the all enemies has a status effect named like Poison
The skill that i want to create will remove all their poison but will recover the user's MP depending on the amount of the enemies that has the poison debuff.
This is inspired and based with the "Avatar of Fire" ability by the Pyro Knight in the game
Elsword.
I'm fine with it if it can be only done via plugin, please do recommend me stuff that can do such a thing!

Thank you so much in advance.

This is my first time posting a thread, please notify me if i have done any errors or if i'm posting in the wrong area.

The version of my RPG Maker MV is 1.6.2 by the way!
In other words, you want a skill that recover some MP based on numbers of states enemy have, right?
If yes then it's pretty easy to do, it's 4 lines of JS code 😛
Yep! Also removing said state (like just one, which is poison) of the enemy. Is it possible if it can only be just one state? Like it's only going to count the amount of inflicted poison towards enemies in the current battle? Sorry if i'm asking alot, but thank you in advance!
Give me a 5min, I'm already finishing and polishing code for you 🙂
Hey, you need this Plugin http://www.yanfly.moe/wiki/Skill_Core_(YEP)

And then, there's something called Lunatic Mode, that allows you to add Javascript. Basically, you add this JS Code into the Skill's notetag. The code should be something like this:

JavaScript:
<Post-Damage Eval>
   if (target.isStateAffected(1)) {
     target.removeState(1);
     user.gainMp(20);
   } 
</Post-Damage Eval>

Replace the numbers 1 and 20 with your desired ones. Tell me if this snippet works for you, I haven't tried it yet.
Thank you sooooooo much! Please do take your time for it!
@SteveTheHuman01
Ok, I'm ready:

Save this code as plugin in your game and add it to plugin manager:
Spoiler
Code:
magicDevour = function(caster, target){
    //We need first to know how many states has target
    var targetStatesNum = target._states.length;
 
    //Here you can set how much MP you want recover per state
    var mpRecoverValue = 15;
 
    //Now we need to check if target has any state to run code
    if (targetStatesNum > 0){
     
        //if target has more than 1 state then recover MP
        for (var i = 0; i <= targetStatesNum; i++){
         
            //MP is recovered here, you can add more stuff if you wish
            caster.gainMp(i * mpRecoverValue);
        }
     
        //now remove states from target
        target.clearStates();
    }
 
    //because it's a function then we need to return some value
    //better to leave it as is, zero, because setting a damage type
    //in database will cause to loose target either MP or HP or
    //recover MP or HP, so leave it as zero.
    return 0;
}

2. Create a skill in your project that will do you wanted and in skill formula type, or I'll show you on image: - https://prnt.sc/trn8bw

other parameters as MP / TP cost and scope you can set whatever you like.

I took liberty of calling this spell "Magic Devour" because its my favourite skill from Warcraft 3 😛 (Undead destroyer has the same spell to increase it's attack and recover MP )
no plugins or .js editing required

enemy group target skill with damage formula
b.isStateAffected(X) ? a.gainMp(Y) : 0; formula
effects: remove state X

replace X with ID of the poison state
replace Y with formula or flat number for the MP recovery
if the skill is supposed to do damage at the same time replace formula with the the desired damage formula otherwise leave that area blank
Hey, you need this Plugin http://www.yanfly.moe/wiki/Skill_Core_(YEP)

And then, there's something called Lunatic Mode, that allows you to add Javascript. Basically, you add this JS Code into the Skill's notetag. The code should be something like this:

JavaScript:
<Post-Damage Eval>
   if (target.isStateAffected(1)) {
     target.removeState(1);
     user.gainMp(20);
   }
</Post-Damage Eval>

Replace the numbers 1 and 20 with your desired ones. Tell me if this snippet works for you, I haven't tried it yet.

It works! Am using most of Yanfly's Plugins, however i encounter a bug where it doesn't work if the skill has the Action Sequence Pack notes with it, but maybe it's just me.

Thank you for showing me this though!
no plugins or .js editing required

enemy group target skill with damage formula
b.isStateAffected(X) ? a.gainMp(Y) : 0; formula
effects: remove state X

replace X with ID of the poison state
replace Y with formula or flat number for the MP recovery
if the skill is supposed to do damage at the same time replace formula with the the desired damage formula otherwise leave that area blank
Yes, that's the way to go! Much easier than my approach!
Please note you guys gave him codes that will work with only one state, he wants to work it on currently active states on enemy. Just a reminder
Thank you all for the taking your time specially @Soulrender for creating a short script plugin for it , i tested all of these solutions and it works!

I'm glad to say that i got it working now.
Please note you guys gave him codes that will work with only one state, he wants to work it on currently active states on enemy. Just a reminder
Oh then I miss-understood the request, I thought it should work on poison only. Then I think your snippets fits best. If the thread starter (or anybody else visiting this thread) wants to stick on Yanfly, the code would look like this:

Code:
<Post-Damage Eval>
   for (var i = 0; i < 99; i++) {
     if (target.isStateAffected(i)) {
       target.removeState(i);
       user.gainMp(20);
     }
   }
</Post-Damage Eval>
OP never implied this skill needing to work for more then 1 state. in fact the wording and example are for 1 state only
My initial read was that OP wanted the state removed from *all* enemies with the state in question, regardless of who the skill target was. Is that right?
my initial read was "remove poison from all enemies while restoring caster MP based on number of enemies that were poisoned"

edit: assumed skill might also do something extra "like damage" at the same time
my initial read was "remove poison from all enemies while restoring caster MP based on number of enemies that were poisoned"

That's what I meant. None of the solutions posted so far accomplish that.

Edit: missed that yours said to make it target all enemies, so your one does.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-create-a-skill-absorbing-an-active-state.124768/