Project1

标题: 商店库存脚本提示undefined method ‘[]’ for Nil:nilClass错误 [打印本页]

作者: maotouying    时间: 2017-8-7 18:40
标题: 商店库存脚本提示undefined method ‘[]’ for Nil:nilClass错误
本帖最后由 maotouying 于 2017-8-7 18:49 编辑

在论坛找到的脚本,放到游戏里就提示这样的错误,我以为是脚本冲突,于是放到新建的工程里试,结果还是这样,哪位大佬可以告诉我哪里出错了吗{:2_263:}




出错的截图



商店库存(基础)
  1. =begin
  2. #===============================================================================
  3. Title: Shop Manager
  4. Author: Tsukihime
  5. Date: Mar 29, 2013
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. 1.5 Mar 29
  9.    - added simple shop refreshing on page change. Will need a better solution
  10.      since this does not track the state of a shop on a different page
  11. 1.4 Mar 13
  12.    - fixed bug where common event shops were not handled appropriately when
  13.      called through effects
  14. 1.3 Mar 1
  15.    - Game_ShopGood now determines whether it should be included or enabled
  16.    - Two shop options implemented: hidden, disabled
  17. 1.2 Feb 25
  18.    - fixed issue where common event shops were not handled correctly
  19.    - exposed Shop Good variables as readers
  20. 1.1
  21.    - ShopManager handles shop scene changing depending on the type of shop
  22.    - added handling for different "types" of shops
  23.    - all goods in a shop can be accessed via shop.shop_goods
  24.    - reference to shop added to shop scene
  25.    - added support for adding and removing goods from a shop
  26. 1.0 Feb 22, 2013
  27.    - Initial Release
  28. --------------------------------------------------------------------------------   
  29. ** Terms of Use
  30. * Free to use in commercial/non-commercial projects
  31. * No real support. The script is provided as-is
  32. * Will do bug fixes, but no compatibility patches
  33. * Features may be requested but no guarantees, especially if it is non-trivial
  34. * Credits to Tsukihime in your project
  35. * Preserve this header
  36. --------------------------------------------------------------------------------
  37. ** Description

  38. This script serves as a base for all shop-related scripts.

  39. This script provides functionality for remember a shop's "state".
  40. Each shop is uniquely identified by a shop ID, and if you visit the same
  41. shop repeatedly, you should see the same settings.

  42. For example, if a shop holds 10 potions, and you bought 5, then you can
  43. expect that the next time you visit the shop, it will only have 5 potions
  44. remaining.

  45. Of course, you will need extra plugins to have that kind of functionality.
  46. Several new classes have been defined for working with shops, and in
  47. particular, shop goods.

  48. In summary:
  49.    -more control over your shops
  50.    -simple API for developers to write shop-related scripts

  51. --------------------------------------------------------------------------------
  52. ** Usage

  53. --------------------------------------------------------------------------------
  54. ** Developers

  55. Here are some specifications that I have written.

  56. Have a look through each class to see what is available for use.
  57. If you have any suggestions that will improve the base script (ie: this),
  58. I will consider adding them.

  59. -- Shop Manager --

  60. This module serves are the interface for all shop-related queries. It handles
  61. how shops are stored for you so that it is easy to properly obtain a reference
  62. to a shop.

  63. You should use the Shop Manager whenever possible.

  64. -- Game Shop --

  65. This script treats a shop as a concrete object. A shop is created the first
  66. time it is accessed, and will be stored with the game for the remainder of
  67. the game.

  68. A very basic shop is provided, which manages what items are available for sale.
  69. All shops are stored in a global Game_Shops hash in $game_shops

  70. -- Shop Type --

  71. On top of the basic Game_Shop class, you can define your own shops and
  72. associate them with custom scenes specific to those shops.

  73. The Shop Manager only requires you to be consistent with your shop name.
  74. For example, if your shop type is "CraftShop", then you must define a

  75.    Game_CraftShop  - the shop object that the shop will be instantiated with
  76.    Scene_CraftShop - the scene that will be called when visiting a CraftShop
  77.    
  78. Users will set a @shop_type attribute in Game_Interpreter to determine
  79. what type of shop should be created

  80. -- Managing shops --

  81. This script assumes shops are only called through events or common events.
  82. Troop events are not supported.

  83. A shop is identified by a map ID and an event ID.
  84. Shops that are called via common events will have a map ID of 0.

  85. In order to determine whether a normal event or a common event called the
  86. shop, the "depth" of the interpreter is used.

  87.     When depth = 0, then it is a normal event
  88.     When depth > 0, then it is a common event
  89.    
  90. The shop processing should be handled appropriately depending on the depth

  91. This script assumes that an event is triggered through "normal" interaction;
  92. that is, you can only interact with events within a map. Any events that should
  93. be treated as the same event should be done as a common event call.

  94. --- Shop Goods ---

  95. Rather than storing all goods as a simple array of values, this script
  96. provides a Game_ShopGood class. You can use this to store any additional
  97. information that you want.

  98. All shop related scenes and windows MUST provide support for handling shop
  99. goods. While backwards compatibility is provided for the default scripts,
  100. additional methods have been defined to allow you to retrieve the currently
  101. selected shop good.

  102. --- Shop Options ---

  103. Since there isn't actually a way to setup individual shop goods, external
  104. approaches must be used. There is not much specification here yet, so it
  105. is up to you how you wish to populate your ShopGood objects. I have provided
  106. a "setup_goods" method in Game_Interpreter that you can alias.

  107. --------------------------------------------------------------------------------
  108. ** Compatibility

  109. This script changes the following from the default scripts

  110.    DataManager
  111.      aliased  - create_game_objects   
  112.      aliased  - make_save_contents
  113.      aliased  - extract_save_contents
  114.    Game_Interpreter
  115.      replaced - command_302
  116.    Window_ShopBuy
  117.      replaced - prepare
  118.    Scene_Shop
  119.      replaced - make_item_list
  120. #===============================================================================
  121. =end
  122. $imported = {} if $imported.nil?
  123. $imported["TH_ShopManager"] = 1.5
  124. #===============================================================================
  125. # ** Rest of the Script
  126. #===============================================================================

  127. #-------------------------------------------------------------------------------
  128. # Main shop manager that acts as the interface between shops and other objects
  129. # The main role of the ShopManager is to essentially manage any shop objects
  130. # that exist in the game. In particular, it provides all of the methods for
  131. # creating, retrieving, and deleting shops.
  132. #-------------------------------------------------------------------------------
  133. module ShopManager
  134.   
  135.   #-----------------------------------------------------------------------------
  136.   # Return a reference to a specific shop
  137.   #-----------------------------------------------------------------------------
  138.   def self.get_shop(map_id, event_id)
  139.     return $game_shop[map_id, event_id]
  140.   end
  141.   
  142.   #-----------------------------------------------------------------------------
  143.   # Indicate that a shop needs to be refreshed
  144.   #-----------------------------------------------------------------------------
  145.   def self.refresh_shop(map_id, event_id)
  146.     shop = get_shop(map_id, event_id)
  147.     shop.need_refresh = true if shop
  148.   end
  149.   
  150.   #-----------------------------------------------------------------------------
  151.   # Setup shop if first time visiting
  152.   #-----------------------------------------------------------------------------
  153.   def self.setup_shop(map_id, event_id, goods, purchase_only, shop_type)
  154.     shop = get_shop(map_id, event_id)
  155.     return shop if shop && !shop.need_refresh
  156.     shop = shop_class(shop_type).new(goods, purchase_only)
  157.     $game_shops[map_id, event_id] = shop
  158.     return shop
  159.   end
  160.   
  161.   #-----------------------------------------------------------------------------
  162.   # Return the appropriate shop class given the shop type
  163.   #-----------------------------------------------------------------------------
  164.   def self.shop_class(shop_type)
  165.     shop_type = "Game_" + shop_type.to_s
  166.     return Object.const_get(shop_type.to_sym)
  167.   end
  168.   
  169.   #-----------------------------------------------------------------------------
  170.   # Return the scene associated with this shop.
  171.   # TO DO
  172.   #-----------------------------------------------------------------------------
  173.   def self.shop_scene(shop)
  174.     shop_scene = "Scene_" + shop.class.name.gsub("Game_", "")
  175.     return Object.const_get(shop_scene.to_sym)
  176.   end
  177.   
  178.   #-----------------------------------------------------------------------------
  179.   # Invokes SceneManager.call on the appropriate scene
  180.   #-----------------------------------------------------------------------------
  181.   def self.call_scene(shop)
  182.    
  183.     SceneManager.call(shop_scene(shop))
  184.     SceneManager.scene.prepare(shop)
  185.   end
  186.   
  187.   #-----------------------------------------------------------------------------
  188.   # Invokes SceneManager.goto on the appropriate scene
  189.   #-----------------------------------------------------------------------------
  190.   def self.goto_scene(shop)
  191.     SceneManager.goto(shop_scene(shop))
  192.     SceneManager.scene.prepare(shop)
  193.   end
  194.   
  195.   #-----------------------------------------------------------------------------
  196.   # Returns a good ID, given a shop and an item. If the item is already in
  197.   # the shop, it will return that good's ID. Otherwise, it will return a new ID
  198.   #-----------------------------------------------------------------------------
  199.   def self.get_good_id(shop, item)
  200.     good = shop.shop_goods.detect {|good| good.item == item}
  201.     return good.nil? ? shop.shop_goods.size + 1 : good.id
  202.   end
  203.   
  204.   #-----------------------------------------------------------------------------
  205.   # Returns a good, given a shop and an item. If the shop already has that good
  206.   # just return it. Otherwise, make a new good. If the price is negative, then
  207.   # the price is the default price. Otherwise, it is the specified price.
  208.   #-----------------------------------------------------------------------------
  209.   def self.get_good(shop, item, price=-1)
  210.     good = shop.shop_goods.detect {|good| good.item == item}
  211.     return good if good
  212.     good_id = shop.shop_goods.size + 1
  213.     type = item_type(item)
  214.     if price < 0
  215.       price_type = price = 0
  216.     else
  217.       price_type = 1
  218.     end
  219.     return Game_ShopGood.new(good_id, type, item.id, price_type, price)
  220.   end
  221.   
  222.   #-----------------------------------------------------------------------------
  223.   # Returns the type of an item.
  224.   #-----------------------------------------------------------------------------
  225.   def self.item_type(item)
  226.     return 0 if item.is_a?(RPG::Item)
  227.     return 1 if item.is_a?(RPG::Weapon)
  228.     return 2 if item.is_a?(RPG::Armor)
  229.     return -1
  230.   end
  231. end

  232. #-------------------------------------------------------------------------------
  233. # Shops are stored in a global variable `$game_shops`. This is dumped and
  234. # loaded appropriately.
  235. #-------------------------------------------------------------------------------
  236. module DataManager
  237.   
  238.   class << self
  239.     alias :th_shop_manager_create_game_objects :create_game_objects
  240.     alias :th_shop_manager_make_save_contents :make_save_contents
  241.     alias :th_shop_manager_extract_save_contents :extract_save_contents
  242.   end
  243.   
  244.   def self.create_game_objects
  245.     th_shop_manager_create_game_objects
  246.     $game_shops = Game_Shops.new
  247.   end
  248.   
  249.   def self.make_save_contents
  250.     contents = th_shop_manager_make_save_contents
  251.     contents[:shops] = $game_shops
  252.     contents
  253.   end
  254.   
  255.   #-----------------------------------------------------------------------------
  256.   # Load shop data
  257.   #-----------------------------------------------------------------------------
  258.   def self.extract_save_contents(contents)
  259.     th_shop_manager_extract_save_contents(contents)
  260.     $game_shops = contents[:shops]
  261.   end
  262. end

  263. class Game_Temp
  264.   
  265.   # even if we're not actually calling a shop, it shouldn't affect anything
  266.   # because we are always setting this at each common event call by an event
  267.   attr_accessor :shop_common_event_id
  268.   
  269.   alias :th_shop_manager_reserve_common_event :reserve_common_event
  270.   def reserve_common_event(common_event_id)
  271.     th_shop_manager_reserve_common_event(common_event_id)
  272.     @shop_common_event_id = common_event_id
  273.   end
  274. end

  275. class Game_Event < Game_Character
  276.   
  277.   alias :th_shop_manager_setup_page :setup_page
  278.   def setup_page(page)
  279.     th_shop_manager_setup_page(page)
  280.     ShopManager.refresh_shop(@map_id, @id)
  281.   end
  282. end

  283. class Game_Interpreter
  284.   
  285.   alias :th_shop_manager_clear :clear
  286.   def clear
  287.     th_shop_manager_clear
  288.     clear_shop_options
  289.     @shop_type = nil
  290.   end
  291.   
  292.   #-----------------------------------------------------------------------------
  293.   # New.
  294.   #-----------------------------------------------------------------------------
  295.   def clear_shop_options
  296.     @shop_options = {}
  297.     @shop_options[:hidden] = {}
  298.     @shop_options[:disabled] = {}
  299.   end
  300.   
  301.   #-----------------------------------------------------------------------------
  302.   # New. We are in a common event only if the shop common event ID is set.
  303.   #-----------------------------------------------------------------------------
  304.   def shop_map_id
  305.     $game_temp.shop_common_event_id ? 0 : @map_id
  306.   end
  307.   
  308.   def shop_event_id
  309.     $game_temp.shop_common_event_id ? $game_temp.shop_common_event_id : @event_id
  310.   end
  311.   
  312.   #--------------------------------------------------------------------------
  313.   # Set the shop's common event ID
  314.   #--------------------------------------------------------------------------
  315.   alias :th_shop_manager_command_117 :command_117
  316.   def command_117
  317.     $game_temp.shop_common_event_id = @params[0]
  318.     th_shop_manager_command_117
  319.   end
  320.   
  321.   #-----------------------------------------------------------------------------
  322.   # Replaced. A shop is setup only once, and is retrieved whenever it is
  323.   # called in the future. This assumes the shop is invoked through "normal"
  324.   # event interactions.
  325.   #-----------------------------------------------------------------------------
  326.   def command_302
  327.     return if $game_party.in_battle
  328.     shop_type = @shop_type || :Shop
  329.     good_id = 1
  330.     goods = []

  331.     # setup goods
  332.     good = make_good(@params[0..-1], good_id) # last param is for the shop
  333.     goods.push(good)
  334.     good_id +=1
  335.    
  336.     while next_event_code == 605
  337.       @Index += 1
  338.       good = make_good(@list[@index].parameters, good_id)
  339.       goods.push(good)
  340.       good_id +=1
  341.     end
  342.     # Setup shop if needed
  343.     shop = ShopManager.setup_shop(shop_map_id, shop_event_id, goods, @params[4], shop_type)
  344.    
  345.     # prepare the shop with a reference to the actual shop
  346.     ShopManager.call_scene(shop)
  347.     Fiber.yield
  348.    
  349.     # clear out the shop common event ID.
  350.     $game_temp.shop_common_event_id = nil
  351.   end
  352.   
  353.   #-----------------------------------------------------------------------------
  354.   # New. This is where the goods are setup.
  355.   #-----------------------------------------------------------------------------
  356.   def make_good(goods_array, good_id)
  357.     item_type, item_id, price_type, price = goods_array
  358.     good = Game_ShopGood.new(good_id, item_type, item_id, price_type, price)
  359.    
  360.     # additional setup
  361.     setup_good(good, good_id)
  362.     return good
  363.   end
  364.   
  365.   #-----------------------------------------------------------------------------
  366.   # New. You can do more things with your good here
  367.   #-----------------------------------------------------------------------------
  368.   def setup_good(good, good_id)
  369.     setup_hidden_option(good, good_id)
  370.     setup_disabled_option(good, good_id)
  371.   end
  372.   
  373.   #-----------------------------------------------------------------------------
  374.   # New. Shop options
  375.   #-----------------------------------------------------------------------------
  376.   def hide_good(good_id, condition)
  377.     @shop_options[:hidden][good_id] = condition
  378.   end
  379.   
  380.   def disable_good(good_id, condition)
  381.     @shop_options[:disabled][good_id] = condition
  382.   end
  383.   
  384.   def setup_hidden_option(good, good_id)
  385.     return unless @shop_options[:hidden][good_id]
  386.     good.hidden_condition = @shop_options[:hidden][good_id]
  387.   end
  388.   
  389.   def setup_disabled_option(good, good_id)
  390.     return unless @shop_options[:disabled][good_id]
  391.     good.disable_condition = @shop_options[:disabled][good_id]
  392.   end
  393. end

  394. #-------------------------------------------------------------------------------
  395. # A shop good.
  396. # This is a wrapper around a raw item (RPG::Item, RPG::Weapon, etc).
  397. #-------------------------------------------------------------------------------

  398. class Game_ShopGood
  399.   
  400.   attr_reader :id         # ID of this good
  401.   attr_reader :item_type
  402.   attr_reader :item_id
  403.   attr_reader :price_type
  404.   attr_accessor :hidden_condition
  405.   attr_accessor :disable_condition
  406.   
  407.   def initialize(id, item_type, item_id, price_type, price)
  408.     @id = id
  409.     @item_type = item_type
  410.     @item_id = item_id
  411.     @price_type = price_type
  412.     @price = price
  413.     @hidden_condition = ""
  414.     @disable_condition = ""
  415.   end
  416.   
  417.   def include?
  418.     return false if eval(@hidden_condition)
  419.     return true
  420.   end
  421.   
  422.   def enable?
  423.     return false if eval(@disable_condition)
  424.     return true
  425.   end
  426.   
  427.   def item
  428.     return $data_items[@item_id] if @item_type == 0
  429.     return $data_weapons[@item_id] if @item_type == 1
  430.     return $data_armors[@item_id] if @item_type == 2
  431.   end
  432.   
  433.   def price
  434.     return item.price if @price_type == 0
  435.     return @price
  436.   end
  437. end

  438. #-------------------------------------------------------------------------------
  439. # A shop object. Stores information about the shop such as its inventory
  440. # and other shop-related data
  441. #-------------------------------------------------------------------------------
  442. class Game_Shop
  443.   attr_reader :purchase_only
  444.   attr_reader :shop_goods      # all goods that this shop has.
  445.   attr_accessor :need_refresh  # shop needs to be refreshed
  446.   
  447.   def initialize(goods, purchase_only=false)
  448.     @shop_goods = goods
  449.     @purchase_only = purchase_only
  450.     @need_refresh = false
  451.   end
  452.   #-----------------------------------------------------------------------------
  453.   # Returns true if the goods should be included
  454.   #-----------------------------------------------------------------------------
  455.   def include?(index)
  456.     true
  457.   end
  458.   
  459.   #-----------------------------------------------------------------------------
  460.   # Return a set of goods for sale
  461.   #-----------------------------------------------------------------------------
  462.   def goods
  463.     @shop_goods
  464.   end
  465.   
  466.   #-----------------------------------------------------------------------------
  467.   # Add a new good to the shop
  468.   #-----------------------------------------------------------------------------
  469.   def add_good(good)
  470.     @shop_goods.push(good) unless @shop_goods.include?(good)
  471.   end
  472.   
  473.   #-----------------------------------------------------------------------------
  474.   # Remove the specified good from the shop
  475.   #-----------------------------------------------------------------------------
  476.   def remove_good(good_id)
  477.     @shop_goods.delete_at(good_id - 1)
  478.   end
  479. end

  480. #-------------------------------------------------------------------------------
  481. # A wrapper containing all shops in the game.
  482. #-------------------------------------------------------------------------------
  483. class Game_Shops
  484.   
  485.   #-----------------------------------------------------------------------------
  486.   # Initializes a hash of game shops. Each key is a map ID, pointing to another
  487.   # hash whose keys are event ID's and values are Game_Shop objects.
  488.   #-----------------------------------------------------------------------------
  489.   def initialize
  490.     @data = {}
  491.   end
  492.   
  493.   def [](i, j)
  494.     @data[i] ||= {}
  495.     @data[i][j]
  496.   end
  497.   
  498.   def []=(i, j, shop)
  499.     @data[i] ||= {}
  500.     @data[i][j] = shop
  501.   end
  502. end

  503. #-------------------------------------------------------------------------------
  504. # The shop scene now works with the Shop and ShopGood objects
  505. #-------------------------------------------------------------------------------
  506. class Scene_Shop < Scene_MenuBase
  507.   #--------------------------------------------------------------------------
  508.   # Replaced. The scene now takes a Game_Shop object
  509.   #--------------------------------------------------------------------------
  510.   def prepare(shop)
  511.     @shop = shop
  512.     @goods = shop.goods
  513.     @purchase_only = shop.purchase_only
  514.   end
  515.   
  516.   alias :th_shop_manager_on_buy_ok :on_buy_ok
  517.   def on_buy_ok
  518.     @selected_good = @buy_window.current_good
  519.     th_shop_manager_on_buy_ok
  520.   end
  521. end

  522. #-------------------------------------------------------------------------------
  523. # @shop_goods is now an array of Game_ShopGoods
  524. #-------------------------------------------------------------------------------
  525. class Window_ShopBuy < Window_Selectable
  526.    
  527.   #--------------------------------------------------------------------------
  528.   # New. Returns true if the good should be included in the shop inventory
  529.   #--------------------------------------------------------------------------
  530.   def include?(shopGood)
  531.     shopGood.include?
  532.   end
  533.   
  534.   alias :th_shop_manager_enable? :enable?
  535.   def enable?(item)
  536.     return false unless @goods[item].enable?
  537.     th_shop_manager_enable?(item)
  538.   end
  539.   
  540.   #--------------------------------------------------------------------------
  541.   # New. Get the currently selected good
  542.   #--------------------------------------------------------------------------
  543.   def current_good
  544.     @goods[item]
  545.   end
  546.   
  547.   #-----------------------------------------------------------------------------
  548.   # Replaced. ShopGood takes care of most information. The data still contains
  549.   # a list of RPG items for now since I don't want to change them to goods yet
  550.   # A separate list of goods for sale is used for 1-1 correspondence
  551.   #-----------------------------------------------------------------------------
  552.   def make_item_list
  553.     @data = []
  554.     @goods = {}
  555.     @price = {}
  556.     @shop_goods.each do |shopGood|
  557.       next unless include?(shopGood)
  558.       item = shopGood.item
  559.       @data.push(item)
  560.       @goods[item] = shopGood
  561.       @price[item] = shopGood.price
  562.     end
  563.   end
  564. end
复制代码





商店库存(核心)


  1. =begin
  2. #===============================================================================
  3. Title: Shop Stock
  4. Author: Tsukihime
  5. Date: Feb 22, 2013
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Feb 22, 2013
  9.    - Initial release
  10. --------------------------------------------------------------------------------   
  11. ** 使用协议
  12. * 免费用于商业或非商业项目
  13. * 自由使用
  14. * 会有BUG修复,但没有兼容性补丁
  15. * 功能可能没有保证
  16. * Preserve this header
  17. --------------------------------------------------------------------------------
  18. ** 必需

  19. -商店库存-基础 以下网址为外站Hime Works,请开在线代理浏览
  20. ([url]http://himeworks.wordpress.com/2013/02/22/shop-manager/[/url])
  21. --------------------------------------------------------------------------------
  22. ** 说明

  23. 这个脚本添加了一个stock到每个商店
  24. 一旦一个商品的stock达到零,它将不能在商店继续售卖

  25. --------------------------------------------------------------------------------
  26. ** 用法

  27. 在你的事件中,在商店处理命令的上面添加以下脚本

  28.    @shop_stock[id] = 数值
  29.    
  30. 名词解用
  31.    id为商店处理中商品列表的id
  32.    第一项商品的id为1,依此类推
  33.    
  34.    数值是该商品有多少存货在该商店
  35.    
  36. --------------------------------------------------------------------------------
  37. ** 作者的话

  38. 一个店的商品存货有多少全取决于stock

  39.    stock < 0, 没有限制
  40.    stock == 0, 没有库存
  41.    stock > 0, 还有那么多库存

  42. #===============================================================================
  43. =end
  44. $imported = {} if $imported.nil?
  45. $imported["TH_ShopStock"] = true
  46. #===============================================================================
  47. # ** Configuration
  48. #===============================================================================
  49. module TH
  50.   module Shop_Stock
  51.   end
  52. end
  53. #===============================================================================
  54. # ** Rest of the Script
  55. #===============================================================================
  56. class Game_Interpreter
  57.   
  58.   alias :th_shop_stock_clear :clear
  59.   def clear
  60.     th_shop_stock_clear
  61.     @shop_stock = []
  62.   end
  63.   
  64.   alias :th_shop_stock_setup_good :setup_good
  65.   def setup_good(good, id)
  66.     th_shop_stock_setup_good(good, id)
  67.     stock = @shop_stock[id]
  68.     return unless stock
  69.     good.stock = stock
  70.   end
  71. end
  72. class Game_ShopGood
  73.   attr_reader :stock
  74.   
  75.   alias :th_shop_stock_init :initialize
  76.   def initialize(*args)
  77.     th_shop_stock_init(*args)
  78.     @stock = -1
  79.    [url=home.php?mod=space&uid=263900]@unlimited[/url] = true
  80.   end
  81.   
  82.   def stock=(amount)
  83.     @stock = amount
  84.     @unlimited = (amount < 0)
  85.   end
  86.   
  87.   def unlimited?
  88.     @unlimited
  89.   end
  90.   
  91.   def increase_stock(amount)
  92.     @stock += amount
  93.   end
  94.   
  95.   def decrease_stock(amount)
  96.     return if @unlimited
  97.     @stock = [@stock - amount, 0].max
  98.   end
  99. end

  100. class Game_Shop
  101.   
  102.   alias :th_shop_stock_include? :include?
  103.   def include?(index)
  104.     return false if stock(index) == 0
  105.     th_shop_stock_include?(index)
  106.   end
  107.   
  108.   def stock(index)
  109.     @shop_goods[index].stock
  110.   end
  111. end

  112. class Window_ShopBuy < Window_Selectable
  113.   
  114.   alias :th_shop_stock_include? :include?
  115.   def include?(shopGood)
  116.     return false if shopGood.stock == 0
  117.     th_shop_stock_include?(shopGood)
  118.   end
  119.   
  120.   alias :th_shop_stock_draw_item :draw_item
  121.   def draw_item(index)
  122.     th_shop_stock_draw_item(index)
  123.     rect = item_rect(index)
  124.     item = @data[index]
  125.     shopGood = @goods[item]
  126.     draw_text(rect, sprintf("庫存:%d", shopGood.stock), 1) unless shopGood.unlimited?
  127.   end
  128.   
  129.   alias :th_shop_stock_process_ok :process_ok
  130.   def process_ok
  131.     unless @data[index]
  132.       Sound.play_buzzer
  133.       return
  134.     end
  135.     th_shop_stock_process_ok
  136.   end
  137. end

  138. class Scene_Shop < Scene_MenuBase
  139.   
  140.   #--------------------------------------------------------------------------
  141.   # Get amount you could buy, compared to the amount in-stock
  142.   #--------------------------------------------------------------------------
  143.   alias :th_shop_stock_max_buy :max_buy
  144.   def max_buy
  145.     party_max = th_shop_stock_max_buy
  146.     @selected_good.unlimited? ? party_max : [party_max, @selected_good.stock].min
  147.   end
  148.   
  149.   #--------------------------------------------------------------------------
  150.   # Decrease the amount of stock of the selected good
  151.   #--------------------------------------------------------------------------
  152.   alias :th_shop_stock_do_buy :do_buy
  153.   def do_buy(number)
  154.     th_shop_stock_do_buy(number)
  155.     @selected_good.decrease_stock(number)
  156.   end
  157. end
复制代码




脚本框加不了,真丢人……{:2_254:}
作者: maotouying    时间: 2017-8-7 21:12
挨个试之后发现其实是和图书馆里的sideview横版战斗冲突了。。请问该如何解决
作者: maotouying    时间: 2017-8-7 22:55
求助呀。。过了好几个小时了,目前我试出了这个脚本应该是和sideview横版战斗的管理那块的脚本冲突,但就是不知道要怎么解决{:2_270:}
作者: 烁灵    时间: 2017-8-8 10:32
本帖最后由 烁灵 于 2017-8-8 14:12 编辑

报错信息是什么?
ctrl+shift+f搜索一下
create_game_objects
看下还有哪里追加定义过




#~
173行那个$game_shop改成$game_shops试试
作者: maotouying    时间: 2017-8-8 14:21
烁灵 发表于 2017-8-8 10:32
报错信息是什么?
ctrl+shift+f搜索一下
create_game_objects

报错信息和一楼的那个截图一样,我按你说的搜索了一下,弹出了那么多……请问大佬哪个是要弄的呢


作者: 烁灵    时间: 2017-8-8 14:25
maotouying 发表于 2017-8-8 14:21
报错信息和一楼的那个截图一样,我按你说的搜索了一下,弹出了那么多……请问大佬哪个是要弄的呢

...

应该是sideview的锅
把商店库存脚本放在sideview系统的下方




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1