How to make a shop close after the player buys an item?

SST123

Veteran
Veteran
Joined
Sep 23, 2018
Messages
31
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Hey all! So I'm working on a certain post game raid challenge for my project. The player will be able to enter a gauntlet of boss refights from the main story all scaled up to post game standards. The player will be able to choose various difficulties and after they clear all the fights, they'll gain access to a special shop with multiple tiers of rare items. Depending on what level of difficulty the player cleared, they'll have a certain number of credits to buy things from the various tiers(which also cost large chunks of standard gold). There will be tier 1: rare/unbuyable items for 1 credit, tier 2: unique boss drop weapons and armor for 2 credits, and tier 3: ultimate items/armor(only available in this shop) for 3 credits. I have it all layed out with variables and loops for the shops and tier choices. All I need is a way to force the shop menu to close after the player buys something so the event can continue; taking the credits away, seeing if the player has any left, and going back to the start of the shop loop if they do. Does anyone have a way to make this happen? Any kind of parallel process or script call method that would make this possible? Thanks!
 

magnaangemon01

Miles Montgomery
Veteran
Joined
Jun 7, 2014
Messages
476
Reaction score
280
First Language
English
Primarily Uses
RMVXA
I'm guessing that would be conditional branches with maybe self switches? Or a script might do it. Not entirely sure, but maybe one of my suggestions will help you
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,499
Reaction score
531
First Language
English
Primarily Uses
RMVXA
Not sure, but try return_scene. That will cause it to exit the current scene.
 

SST123

Veteran
Veteran
Joined
Sep 23, 2018
Messages
31
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Not sure, but try return_scene. That will cause it to exit the current scene.
That's a good idea and I'd like to try that. Any idea how I could get it to detect if the player buys something?

I'm guessing that would be conditional branches with maybe self switches? Or a script might do it. Not entirely sure, but maybe one of my suggestions will help you
I've tried poking around with some of that, and the main issue is conditional branches can only detect if the player has an armor/weapon/item. If they want another of an accessory for instance, that wouldn't work. I'm trying to figure out how I can make the player's action of purchasing something during the shop trigger an event or script to make it close.

I made a test event for this shop in my debug world. It's all there except a way to detect when the player makes a purchase during shop processing and a way to make the shop close. Here's a screenshot for anyone curious: 1596346161701.png
Edit: the conditional branch to break the loop is copied at both the top and bottom of the choices, just realized that was cut off.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,930
Reaction score
13,567
First Language
English
Primarily Uses
RMMV
You can set a variable to the number of that item in inventory before doing the shop processing, and then set a different variable to the number of that item in inventory after the shop processing. If the newer number is higher, they purchased.
 

SST123

Veteran
Veteran
Joined
Sep 23, 2018
Messages
31
Reaction score
0
First Language
english
Primarily Uses
RMVXA
You can set a variable to the number of that item in inventory before doing the shop processing, and then set a different variable to the number of that item in inventory after the shop processing. If the newer number is higher, they purchased.
That's really good, I'll look into it and probably use something akin to that if nothing else works. The only roadblock I can think of is the player can make multiple purchases before exiting shop processing. I'm trying to think of a way to force it to close after the first purchase, no matter what it is.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
Err, what about storing credits in a variable and just checking if that variable is not the same as your current amount of credits?

Then use "exit event processing" command.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,930
Reaction score
13,567
First Language
English
Primarily Uses
RMMV
If you want it to close after the first purchase, you'll need a script.
 

SST123

Veteran
Veteran
Joined
Sep 23, 2018
Messages
31
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Err, what about storing credits in a variable and just checking if that variable is not the same as your current amount of credits?

Then use "exit event processing" command.
That's great, but the credits won't be taken away until after the player exits the shop. Or I'd need an event/script to take the credit(s) away on purchase as well as the gold.

Edit: Wait a minute, that might be it! I'm going to see if I can store gold in a variable and detect the decrease with an event.
 

SST123

Veteran
Veteran
Joined
Sep 23, 2018
Messages
31
Reaction score
0
First Language
english
Primarily Uses
RMVXA
If you want it to close after the first purchase, you'll need a script.
Yeah, that's what I need help figuring out. I tried return_scene like someone else said and it didn't recognize the less gold until after the shop closed(an idea i was testing for) and when it did notice, return_scene just caused an error about an undefined variable. I'd really like to make this work, I just need help with this one hurdle. It's so frustratingly close but so far...
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
659
Reaction score
427
First Language
English
Primarily Uses
RMVXA
Here's a little snippet that should help:

Ruby:
class Scene_Shop < Scene_MenuBase
  # if switch is set to TRUE, the shop will close after purchase
  SHOP_CLOSE_SWITCH = 2 # ID of the switch
 
  # variable for storing the last item purchased
  ITEM_ID_VARIABLE = 4 # ID of the variable
 
  alias amn_closeshop_sceneshop_dobuy do_buy
  def do_buy(number)
    amn_closeshop_sceneshop_dobuy(number)
    if ITEM_ID_VARIABLE > 0
      type = case @item
      when RPG::Weapon then "W"
      when RPG::Armor then "A"
      else "I"
      end
      $game_variables[ITEM_ID_VARIABLE] = "#{type}#{@item.id}"
    end
    return_scene if SHOP_CLOSE_SWITCH > 0 && $game_switches[SHOP_CLOSE_SWITCH]
  end
 
end
Paste that in its own slot below Materials and above Main.

Set the switch to TRUE before opening the shop. If you purchase an item, the shop window will close directly after, so long as the switch is TRUE. The last item purchased is stored in the ITEM_ID_VARIABLE like so: "I1" would be item 1 (e.g. potion in the default), "A1" would be armour 1 and "W1" would be weapon one. Then you can set up a conditional branch after the shop scene that checks if the variable is equal to "A1", etc.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,930
Reaction score
13,567
First Language
English
Primarily Uses
RMMV
It needs an update to the scripts, not just a script call in an event. Events don't run while menus (including shop) are open.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
I recall how I managed to let the shop event stay open after the shop menu was closed by editing a specific method in the Interpreter class in XP. In other versions it'd be Game_Interpreter. This way it wouldn't stop processing the event allowing you to even set a custom goodbye message afterwards.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,137
Reaction score
8,417
First Language
English
Primarily Uses
RMMV

I've moved this thread to Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.

 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Hello I buyed RPG Maker VX Ace a long ago and I want to use it again but in the meantime I changed my pc but I lost the paper with my product key on so I can't use RPG maker again... someone can help me please ? or there is no hopes ?:'( ( I have a bad english I'm sorry )
I was away this days here in the forum but it was for a good cause!
The trailer of the demo of Luke Inn is on youtube and I am so happy!
I need to see the bugs of the game but I am happy that I have new content to show!

The last part of the modern interior will be ready soon. This will be a B-tile. With interior items for the kitchen, bathroom, toilet and storage room.
This frantic shooting ARPG plugin for MZ looks really great. Here is the link to a post from the official Japanese RPG Maker forum.

Forum statistics

Threads
102,941
Messages
996,125
Members
134,397
Latest member
Harwin
Top