Remove Random Status Effect

I am not sure if there is already a plugin out there that handles this sort of thing, or if someone would be willing to build it on a commission, but here it goes! In our game we are looking to have four tiers of a specific type of item that is used to remove status effects from a party member. The lowest tier is capable of removing all status effects in the game, there might be a few exceptions, but only 1 at a time. The next tier would remove 3 effects. The third tier would remove 5, and finally the last tier would remove all.


Example: Party member Bob has the status effect (state) of poison, sleep, and confusion. Party member Jill uses a tier 1 nullifier on Bob. The nullifier removes confusion. Bob is still poisoned and asleep. The next round Jill uses another tier 1 nullifier on Bob. The nullifier now removes the poison.


We are open to the idea that the effects may be removed at random, or by the order that they were applied to the target. I have been looking around to see if there is anything like this but haven't come across anything. This could also be used on "Cleansing" skills as well. Any help in the right direction would be much appreciated!
I saw a similar effect on a Yanfly Tips and Tricks video recently: http://yanfly.moe/2017/01/23/tips-tricks-daring-padawan-star-wars-galaxy-of-heroes-rpg-maker-mv/ The code for the Custom React Effect might be interesting for you as a starting point, although in a slightly different context. So, no need for a new plugin, it can be handled with the so-called "Lunatic Mode" of Yanfly's plugins (basically, Javascript coding in a notetag).


With Yanfly's Skill Core installed, use a piece of code like this in your item/skill notebox (for a random state):


<Pre-Damage Eval>
// List all the states the item can remove (change to your state IDs)
// If there a lots of them in consecutive order, you can also use a loop to add them more conveniently.
var removeStates = [3, 4, 5, 6, 7];
// Make an empty pool of states
var currentStates = [];
// Loop through each of the padawan states
for (var i = 0; i < removeStates.length; ++i) {
// Get the currently looped state
var current = removeStates;
// Check if the target is affected by that state
if (target.isStateAffected(current)) {
// If it is, add it to the pool of states
currentStates.push(current);
}
}
// Run the following code 3 times (or five times, or however many times you want - just change the number)
// For the tier 1 items, when it should run only once, you can remove the loop (this line and the very last curly bracket).
for (var j = 0; j < 3; j++) {
// Check if the pool of states isn't empty
if (currentStates.length > 0) {
// Get a random state from that pool
var removedState = currentStates[Math.floor(Math.random() * currentStates.length)];
// Remove the random state
target.removeState(removedState);
// Remove the state from the list of current states
currentStates.splice(currentStates.indexOf(removedState), 1);
}
}
</Pre-Damage Eval>


A little warning: I haven't tested the code - most of it is directly taken from the Tips and Tricks video linked above, which limits the number of possible mistakes 😉 - so it might give you an error or simply not work the way it should. If that is the case, let me know what exactly happens and I'll try to fix it.
Thank you very much! I will try this out today and let you know how it all went. Much appreciated!
So I have tried both versions, one with the lines you suggested should be removed and without removing them. In either case, no state is removed from the targeted actor. I don't receive any errors, but it states that the target is unaffected.


Should the item have any effects listed on it, such as the states that it can remove? I didn't think so since it has it in the notebox of the item. I also wanted to mention I have YEP_SkillCore and YEP_BuffStatesCore installed.

Screen Shot 2017-01-30 at 10.50.10 AM.png
Ah, my bad - the Pre-Damage Eval and Post-Damage Eval tags only run when the skill/item actually does damage. (Overlooked that part in the Help file.) Change "Pre-Damage" to "Before" or "After" in the notetags, then it should work.
Prefect, that did the trick. Thank you very much!
You're welcome 🙂

Original thread: https://forums.rpgmakerweb.com/threads/remove-random-status-effect.74282/