Refund Item Price when Used

Discussion in 'RGSS3 Script Requests' started by Vis_Mage, Apr 30, 2019.

  1. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    Howdy! :kaohi:

    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! :kaothx:
     
    #1
    Engr. Adiktuzmiko likes this.
  2. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    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 %?
     
    #2
    Vis_Mage likes this.
  3. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    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. :p Having a configurable max for both might not be a bad idea, though.
     
    #3
    Engr. Adiktuzmiko likes this.
  4. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    I see.. Im working on something, though I cant finish it anytime soon as Im at work. xD
     
    #4
    Vis_Mage likes this.
  5. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    Ah, no problem. Thank you for picking up my request! :kaoblush:
     
    #5
    Engr. Adiktuzmiko likes this.
  6. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    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.
     
    Last edited: Apr 30, 2019
    #6
  7. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,453
    Likes Received:
    5,044
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    @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?
     
    Last edited: Apr 30, 2019
    #7
    Vis_Mage and Engr. Adiktuzmiko like this.
  8. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    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.
     
    Last edited: Apr 30, 2019
    #8
    Vis_Mage likes this.
  9. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    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. :p

    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.
     
    #9
    Engr. Adiktuzmiko likes this.
  10. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    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
     
    #10
    Vis_Mage likes this.
  11. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    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 :kaoblush:
     
    #11
  12. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,453
    Likes Received:
    5,044
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    The script may not handle such case, but that is the developer's responsibility to not use it. It's not technically broken.
     
    #12
  13. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    So you have items that isn't consumed when used? I'll add a check for that when I get the time.
     
    #13
  14. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    There's a few, yeah. Completely forgot about seeing how to the would interact until I triggered it be chance while playtesting. :kaoswt: Sorry about that.

    No rush though, whenever you have the time is perfectly fine.
     
    #14
  15. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    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.
     
    #15
    Vis_Mage likes this.
  16. Vis_Mage

    Vis_Mage Novice Magician Veteran

    Messages:
    390
    Likes Received:
    141
    Location:
    Ridge Island
    First Language:
    English
    Primarily Uses:
    RMVXA
    Everything seems to be working perfectly! Thank you for all your help! :kaothx:
     
    #16

Share This Page