Chance to Refund Item in Battle

Hey! 👋

I was wondering if anyone could help me with a (hopefully simple) script request.

Pretty much, I'm hoping for a script that a % chance (possibly stored in a variable to allow for mid-game % changing) to have an item used within battle to be refunded (not used up), ideally with a message in the battle log saying "Got a Freebie!" or something of the nature.

A couple other cool features might be allowing to have items with different refund % (as notetags or listed in the script itself), or having equipment that could raise the odds, but I wouldn't worry about it if it proves to be difficult.

Thank you!😤
To put it simple
> You use a heal pot in battle
> There's 50% chance that the item is refunded after battle
> You got the chance
> After battle, you get the item back?

Not sure why anyone would want that and what kind of concept that need it. But it should be doable.
To put it simple
> You use a heal pot in battle
> There's 50% chance that the item is refunded after battle
> You got the chance
> After battle, you get the item back?

Not sure why anyone would want that and what kind of concept that need it. But it should be doable.

Just about, only difference being that the refund (and text) would happen directly after using the item in battle, before the next action.

Mostly wanting to use it for a Scavenger-esque class, and to give a little extra incentive to the often overlooked consumable items. It's kinda like a critical hit, but with items! 😤
At one level, it would be easy because the Game_Party's consume_item is simply a lose_item, so it is possible to put in the similarly structured gain_item with a rand < 0.5 (example chance) and in_battle (switch for checking battle mode). Just as it is easy (for some of us) to make the notetag to make our own chances.

However, I'd had to work out the message part, so perhaps put that part around the call to the battle log or activate a switch.
Bump
Here you go. Let me know if there's anything missing.
Here you go. Let me know if there's anything missing.

Thank you, it works great! 🙏

Only ran into one thing that might be worth looking into. If you have the message style set to :log, the "Player recovered the Potion" text overwrites the item's effect ( such as"Player recovered 20 HP").

Original thread: https://forums.rpgmakerweb.com/threads/chance-to-refund-item-in-battle.97060/