【VX release】The store purchase

This is one for the store to purchase the script, function as I said just now, when you go into a store will determine your belongings, if the number of items to the limit, so congratulations you, you can't buy this kind of goods.

Method of use: directly replace the first script "shop" system script, then second scripts are independent, the number is limited, read equipment well, now you can note in the remarks column in a number of items, such as bombs? A person can only carry one?

By the way, Amy knows there are other game forum? One of my foreign friends he was studying in Berlin, he once told me that he had a great game in the UK production of the forum, but I don't know where to

  1. #==============================================================================
  2. # ■ Scene_Shop
  3. #------------------------------------------------------------------------------
  4. #  处理商店画面的类。
  5. #==============================================================================
  6.  
  7. class Scene_Shop < Scene_Base
  8.   #--------------------------------------------------------------------------
  9.   # ● 开始处理
  10.   #--------------------------------------------------------------------------
  11.   def start
  12.     super
  13.     create_menu_background
  14.     create_command_window
  15.     @help_window = Window_Help.new
  16.     @gold_window = Window_Gold.new(384, 56)
  17.     @dummy_window = Window_Base.new(0, 112, 544, 304)
  18.     @buy_window = Window_ShopBuy.new(0, 112)
  19.     @buy_window.active = false
  20.     @buy_window.visible = false
  21.     @buy_window.help_window = @help_window
  22.     @sell_window = Window_ShopSell.new(0, 112, 544, 304)
  23.     @sell_window.active = false
  24.     @sell_window.visible = false
  25.     @sell_window.help_window = @help_window
  26.     @number_window = Window_ShopNumber.new(0, 112)
  27.     @number_window.active = false
  28.     @number_window.visible = false
  29.     @status_window = Window_ShopStatus.new(304, 112)
  30.     @status_window.visible = false
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● 结束处理
  34.   #--------------------------------------------------------------------------
  35.   def terminate
  36.     super
  37.     dispose_menu_background
  38.     dispose_command_window
  39.     @help_window.dispose
  40.     @gold_window.dispose
  41.     @dummy_window.dispose
  42.     @buy_window.dispose
  43.     @sell_window.dispose
  44.     @number_window.dispose
  45.     @status_window.dispose
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ● 更新画面
  49.   #--------------------------------------------------------------------------
  50.   def update
  51.     super
  52.     update_menu_background
  53.     @help_window.update
  54.     @command_window.update
  55.     @gold_window.update
  56.     @dummy_window.update
  57.     @buy_window.update
  58.     @sell_window.update
  59.     @number_window.update
  60.     @status_window.update
  61.     if @command_window.active
  62.       update_command_selection
  63.     elsif @buy_window.active
  64.       update_buy_selection
  65.     elsif @sell_window.active
  66.       update_sell_selection
  67.     elsif @number_window.active
  68.       update_number_input
  69.     end
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 生成命令窗口
  73.   #--------------------------------------------------------------------------
  74.   def create_command_window
  75.     s1 = Vocab::ShopBuy
  76.     s2 = Vocab::ShopSell
  77.     s3 = Vocab::ShopCancel
  78.     @command_window = Window_Command.new(384, [s1, s2, s3], 3)
  79.     @command_window.y = 56
  80.     if $game_temp.shop_purchase_only
  81.       @command_window.draw_item(1, false)
  82.     end
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   # ● 释放命令窗口
  86.   #--------------------------------------------------------------------------
  87.   def dispose_command_window
  88.     @command_window.dispose
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # ● 更新命令窗口
  92.   #--------------------------------------------------------------------------
  93.   def update_command_selection
  94.     if Input.trigger?(Input::B)
  95.       Sound.play_cancel
  96.       $scene = Scene_Map.new
  97.     elsif Input.trigger?(Input::C)
  98.       case @command_window.index
  99.       when 0  # 买入
  100.         Sound.play_decision
  101.         @command_window.active = false
  102.         @dummy_window.visible = false
  103.         @buy_window.active = true
  104.         @buy_window.visible = true
  105.         @buy_window.refresh
  106.         @status_window.visible = true
  107.       when 1  # 卖出
  108.         if $game_temp.shop_purchase_only
  109.           Sound.play_buzzer
  110.         else
  111.           Sound.play_decision
  112.           @command_window.active = false
  113.           @dummy_window.visible = false
  114.           @sell_window.active = true
  115.           @sell_window.visible = true
  116.           @sell_window.refresh
  117.         end
  118.       when 2  # 离开
  119.         Sound.play_decision
  120.         $scene = Scene_Map.new
  121.       end
  122.     end
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 更新买入选择
  126.   #--------------------------------------------------------------------------
  127.   def update_buy_selection
  128.     @status_window.item = @buy_window.item
  129.     if Input.trigger?(Input::B)
  130.       Sound.play_cancel
  131.       @command_window.active = true
  132.       @dummy_window.visible = true
  133.       @buy_window.active = false
  134.       @buy_window.visible = false
  135.       @status_window.visible = false
  136.       @status_window.item = nil
  137.       @help_window.set_text("")
  138.       return
  139.     end
  140.     if Input.trigger?(Input::C)
  141.       @item = @buy_window.item
  142.       number = $game_party.item_number(@item)
  143.       if @item == nil or @item.price > $game_party.gold or
  144.        number == ITEM_CAP::LIMIT
  145.         Sound.play_buzzer
  146.       else
  147.         Sound.play_decision
  148.         max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
  149.         max = [max, ITEM_CAP::LIMIT - number].min
  150.         @buy_window.active = false
  151.         @buy_window.visible = false
  152.         @number_window.set(@item, max, @item.price)
  153.         @number_window.active = true
  154.         @number_window.visible = true
  155.       end
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # ● 更新卖出选择
  160.   #--------------------------------------------------------------------------
  161.   def update_sell_selection
  162.     if Input.trigger?(Input::B)
  163.       Sound.play_cancel
  164.       @command_window.active = true
  165.       @dummy_window.visible = true
  166.       @sell_window.active = false
  167.       @sell_window.visible = false
  168.       @status_window.item = nil
  169.       @help_window.set_text("")
  170.     elsif Input.trigger?(Input::C)
  171.       @item = @sell_window.item
  172.       @status_window.item = @item
  173.       if @item == nil or @item.price == 0
  174.         Sound.play_buzzer
  175.       else
  176.         Sound.play_decision
  177.         max = $game_party.item_number(@item)
  178.         @sell_window.active = false
  179.         @sell_window.visible = false
  180.         @number_window.set(@item, max, @item.price / 2)
  181.         @number_window.active = true
  182.         @number_window.visible = true
  183.         @status_window.visible = true
  184.       end
  185.     end
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● 更新数值输入
  189.   #--------------------------------------------------------------------------
  190.   def update_number_input
  191.     if Input.trigger?(Input::B)
  192.       cancel_number_input
  193.     elsif Input.trigger?(Input::C)
  194.       decide_number_input
  195.     end
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # ● 取消数值输入
  199.   #--------------------------------------------------------------------------
  200.   def cancel_number_input
  201.     Sound.play_cancel
  202.     @number_window.active = false
  203.     @number_window.visible = false
  204.     case @command_window.index
  205.     when 0  # 买入
  206.       @buy_window.active = true
  207.       @buy_window.visible = true
  208.     when 1  # 卖出
  209.       @sell_window.active = true
  210.       @sell_window.visible = true
  211.       @status_window.visible = false
  212.     end
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ● 确认数值输入
  216.   #--------------------------------------------------------------------------
  217.   def decide_number_input
  218.     Sound.play_shop
  219.     @number_window.active = false
  220.     @number_window.visible = false
  221.     case @command_window.index
  222.     when 0  # 买入
  223.       $game_party.lose_gold(@number_window.number * @item.price)
  224.       $game_party.gain_item(@item, @number_window.number)
  225.       @gold_window.refresh
  226.       @buy_window.refresh
  227.       @status_window.refresh
  228.       @buy_window.active = true
  229.       @buy_window.visible = true
  230.     when 1  # 卖出
  231.       $game_party.gain_gold(@number_window.number * (@item.price / 2))
  232.       $game_party.lose_item(@item, @number_window.number)
  233.       @gold_window.refresh
  234.       @sell_window.refresh
  235.       @status_window.refresh
  236.       @sell_window.active = true
  237.       @sell_window.visible = true
  238.       @status_window.visible = false
  239.     end
  240.   end
  241. end
  242.  
Expand to see the code.


  1. module ITEM_CAP
  2.   TEXT = ": %s / %s"
  3.   LIMIT = 20#购买上限
  4. end
Expand to see the code.
This is neat, I can imagine item caps being useful in a lot of games. (Surprised it was never a feature in RM to begin with to be honest).

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78297