Collect & Inject Ailments (Yanfly Tips & Tricks)

Link to the page here!

Hey, everyone!

For my game, I make use of these two pieces of code provided by Yanfly. The first sets up an attack that collects a status ailment, whereas the second injects it into an enemy. The way I intend things to work, the inject portion of this setup is meant to target all enemies. Therefore, the scope of the associated skill is set to 'all enemies'. Now, while the skill is indeed used on all targets, only one of them receives the status ailment.

<Custom Requirement>
// Default the current collected ailment for the user.
user._collectedAilment = user._collectedAilment || 0;
// Make sure the ailment ID is above 0.
value = user._collectedAilment > 0;
</Custom Requirement>

<Before Eval>
// Get the user's current collected ailment.
var stateId = user._collectedAilment;
// Add that ailment to the target.
target.addState(stateId);
// Remove the collected ailment from the user.
user._collectedAilment = 0;
</Before Eval>

I wonder if there is a simple solution to only have the status ailment be removed from the user's memory after all enemies have been afflicted with the status ailment. I have been playing around with the code some, but sadly this is not my strong point.

I am thankful for every bit of help or suggestions!

Original thread: https://forums.rpgmakerweb.com/threads/collect-inject-ailments-yanfly-tips-tricks.118171/