Refund Item Price when Used

Howdy! 👋

I'm hoping to create a fun (and hopefully pretty simple) little perk for a merchant character.

What I'm hoping to create is a script that, when the actor has a certain notetag, refunds them a percentage of an item's cost whenever they use an item. Something along the lines of <refund(x,y)> where X is the percentage of the price to refund, and Y is the chance for the refund to happen. So someone with the tag <refund(30,50)> would have a 50% chance to refund 30% of an item's cost upon use.

For future-proof sake (and for anyone else that may want to use this script), having the tag work on actor/class/weapon/armor/state(?) would be really nice. It'd be pretty cool if this could have a message in the battle log too, if that isn't too difficult.

Hopefully that all makes sense. If there's anything you'd like me to clarify or elaborate on, please make sure to ask.

Thank you! 🙏
Sounds interesting, have a question though, how will the effects stack?

Like if I have these:

Actor: Refund 30,50
State: Refund 40,30

Does the chances get simply added? How about the refund %?
Huh, hadn't thought of that.

I'd imagine it would be easiest to understand for players if both values stacked additively. So for your example, it the two notetags would add up to a 80% chance to refund 70% of the cost.

With that said, it should probably cap at 100 for both. Otherwise, you could get to the point where you can buy an expensive potion, and actually make money off of using it. 😛 Having a configurable max for both might not be a bad idea, though.
I see.. Im working on something, though I cant finish it anytime soon as Im at work. xD
Ah, no problem. Thank you for picking up my request! 😊
Here is the script:

Take note though that it shows the refund message in the battlelog before the message for the actual effect of the item.
Code:
So it looks like this:

Actor Uses Item
Refund Message
Item Effect

I wanted to minimize how many methods I alias so I just kept it at that xD

The refund message is skipped if the refund value is 0

Also, I dont know how this goes when it comes to compatibility because its only tested on a blank project. Though since I only aliased 1 method, this should work fine as long as its not above a script that overwrites that method. For safest bet, put it below all other scripts.
@Engr. Adiktuzmiko just a heads up, instead of using nested if, you can actually just use "feature_objects". It includes all the relevant data like actors, classes, equips, states, together.

Edit:
Also, this is just a wild guess, but are u sure it won't be refunded more than once if the scope of the item is area? or at least have repeat more than once?
Ooh I see.. I'm practically used to defining each of the objects individually now, I'll probably try that next time xD

It might be refunded more than once for AoE items, didn't test it but since the current one is hooked to item_apply, it will probably run per target/repeat. Most items in my games were single target potions so I never really thinked about how it goes for aoe items or those with repeat.

Cant test/fix it right now though, maybe tomorrow.
Awesome! I tried it out in both a blank project, and my actual project, and things seem to be working great, with the exception of multi-target items. Like you both theorized, so long as the actor with the tag used the item, it will trigger the refund for each target. 😛

On the bright side though, the inverse doesn't seem to be the case. An actor without the tag targeting an ally with the tag doesn't falsely trigger the refund.
I just updated the script, it now hooks on use_item so it now works only once per item use instead of per target/repeat.

I also shortened it with Theo's suggestion.

So far no problems in my multi-use item test.

PS: Your enemies can't use items right? Coz if they do and they have the tag, it would add the refund to the party xD
Sorry that it took so long to get back to you, been away from the PC for a few days.

Tested it out, and the multi-target refund seems to work properly now! I did find one other thing that should probably be addressed, though. Any items that can be used, but not consumed, can still trigger a refund. Not a huge deal, but something I thought I should bring up.

Also, while I don't have any enemies that use items, that's a good thing to keep in mind. Would look a bit silly 😊
I did find one other thing that should probably be addressed, though. Any items that can be used, but not consumed, can still trigger a refund. Not a huge deal, but something I thought I should bring up.
The script may not handle such case, but that is the developer's responsibility to not use it. It's not technically broken.
So you have items that isn't consumed when used? I'll add a check for that when I get the time.
There's a few, yeah. Completely forgot about seeing how to the would interact until I triggered it be chance while playtesting. 😅 Sorry about that.

No rush though, whenever you have the time is perfectly fine.
I updated the script to not include non-consumables.

@TheoAllen - the problem is that since the refund tags can be used in actors, classes etc there can easily exist a situation where you have a refund tag active and a non-consumable item that the developer cannot really avoid unless he avoid using non-consumables at all.
Everything seems to be working perfectly! Thank you for all your help! 🙏

Original thread: https://forums.rpgmakerweb.com/threads/refund-item-price-when-used.108531/