State that makes you not lose consumable items

Hello! I would want to know if there exists a plugin or a script that allows to make a special state, in which a party member
can use an item from inventory without losing it. Something like:

- char is inflicted with {this state}
- char uses one of his 10 potions to heal
- restores hp
- still has 10 potions

Thank you on advance.
there are items that can lose items, but gain 1 item upon using it.
but it require YEP_BuffStateCore and a lunatic code.

while I use it for something, I need don't know much of it's coding.
but it very doable with that plugin.

otherwise, there should be a snipped on consume item, that check
the items ID or notetag to not lose items as long you have that state.

there are a few ways to accomplish this, but does using an item lose turns?
as I have consume item with eval, you can create an eval tag on it's state check.
when true, use 1 or do not (only I didn't test this though).
My javascript knowledge isn't good enough to pull this off without looking it up (which I will do after writing this reply, might edit this reply later) but you can use javascript in the items battle formula. Or in this case, healing formula. I mean, I know the steps, but not the code.

You make an if statement to check for the state, then if true, you add the item back into the inventory. Then you do ; and then the actual healing formula.

This will add the item silently, so the player would have no idea that it even left the inventory.

however.... I do not know if the item is removed before, or after the action is performed. If it is after, then there is one kickup: When 10 potions is the max, the item will not be added before it is removed, resulting in the player losing one item only when their inventory is maxed out.

This is set to 99 by befault, so might not be a huge problem, but it will be if the max is low like 10 or even 3, specially if you can only carry 1. (because then you'd lose your last item and it will never be replaced)

I assume the item will be removed first, and then the action is performed. And if that is indeed the case, there is no problem. But just in case, I would test this out before I would build a whole mechanic around it.
I assume the item will be removed first, and then the action is performed. And if that is indeed the case, there is no problem. But just in case, I would test this out before I would build a whole mechanic around it.
the item is consumed first. its at the same place where skill costs are paid that if its an item the party loses the item instead, and skill costs pare paid before the formula is evaluated.

that being said, id suggest using action sequences or the skill core to give all the relevant items an effect to regain the item if the user had the state active. the usual auto battle shenanigans where actors fire off the formula without using it are avoided by this being an item, but the logic to check for the state and give the item back is going to take up all of the visible formula box. imo itd be more readable in the notebox.
Updated
Using YEP_SkillCore this is how I've been doing it:

This code goes in the Notebox of the Item.
1 is the State ID
2 is the temporary Variable used to prevent the code from executing more than once per instance
3 is the Item ID

JavaScript:
<setup action>
 change variable 2 = 0
</setup action>

<After Eval>
 if ($gameVariables.value(2) === 0 && a.isStateAffected(1)) {
  $gameParty.gainItem($dataItems[3], 1); // Gain +1 of Item ID 3
  $gameVariables.setValue(2, 1); // Sets this code to only execute once per use
}
</After Eval>
Using YEP_SkillCore this is how I've been doing it:
just one note which is why i mentioned action sequences as well. Its fine for single target items, but using that tag on an item that targets multiple battlers will give the player a copy of the item per target.
just one note which is why i mentioned action sequences as well. Its fine for single target items, but using that tag on an item that targets multiple battlers will give the player a copy of the item per target.

It's funny I overlooked that considering I actually have a skill with a setup to account for exactly that issue. I updated my previous post. Also I just realized I don't know how to properly quote someone.

Original thread: https://forums.rpgmakerweb.com/threads/state-that-makes-you-not-lose-consumable-items.174862/