设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2307|回复: 7
打印 上一主题 下一主题

[已经过期] 限量商店脚本出错

[复制链接]

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
跳转到指定楼层
1
发表于 2014-10-12 13:47:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
  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.   # Return a reference to a specific shop
  136.   #-----------------------------------------------------------------------------
  137.   def self.get_shop(map_id, event_id)
  138.     return $game_shops[map_id, event_id]
  139.   end

  140.   #-----------------------------------------------------------------------------
  141.   # Indicate that a shop needs to be refreshed
  142.   #-----------------------------------------------------------------------------
  143.   def self.refresh_shop(map_id, event_id)
  144.     shop = get_shop(map_id, event_id)
  145.     shop.need_refresh = true if shop
  146.   end

  147.   #-----------------------------------------------------------------------------
  148.   # Setup shop if first time visiting
  149.   #-----------------------------------------------------------------------------
  150.   def self.setup_shop(map_id, event_id, goods, purchase_only, shop_type)
  151.     shop = get_shop(map_id, event_id)
  152.     return shop if shop && !shop.need_refresh
  153.     shop = shop_class(shop_type).new(goods, purchase_only)
  154.     $game_shops[map_id, event_id] = shop
  155.     return shop
  156.   end

  157.   #-----------------------------------------------------------------------------
  158.   # Return the appropriate shop class given the shop type
  159.   #-----------------------------------------------------------------------------
  160.   def self.shop_class(shop_type)
  161.     shop_type = "Game_" + shop_type.to_s
  162.     return Object.const_get(shop_type.to_sym)
  163.   end

  164.   #-----------------------------------------------------------------------------
  165.   # Return the scene associated with this shop.
  166.   # TO DO
  167.   #-----------------------------------------------------------------------------
  168.   def self.shop_scene(shop)
  169.     shop_scene = "Scene_" + shop.class.name.gsub("Game_", "")
  170.     return Object.const_get(shop_scene.to_sym)
  171.   end

  172.   #-----------------------------------------------------------------------------
  173.   # Invokes SceneManager.call on the appropriate scene
  174.   #-----------------------------------------------------------------------------
  175.   def self.call_scene(shop)

  176.     SceneManager.call(shop_scene(shop))
  177.     SceneManager.scene.prepare(shop)
  178.   end

  179.   #-----------------------------------------------------------------------------
  180.   # Invokes SceneManager.goto on the appropriate scene
  181.   #-----------------------------------------------------------------------------
  182.   def self.goto_scene(shop)
  183.     SceneManager.goto(shop_scene(shop))
  184.     SceneManager.scene.prepare(shop)
  185.   end

  186.   #-----------------------------------------------------------------------------
  187.   # Returns a good ID, given a shop and an item. If the item is already in
  188.   # the shop, it will return that good's ID. Otherwise, it will return a new ID
  189.   #-----------------------------------------------------------------------------
  190.   def self.get_good_id(shop, item)
  191.     good = shop.shop_goods.detect {|good| good.item == item}
  192.     return good.nil? ? shop.shop_goods.size + 1 : good.id
  193.   end

  194.   #-----------------------------------------------------------------------------
  195.   # Returns a good, given a shop and an item. If the shop already has that good
  196.   # just return it. Otherwise, make a new good. If the price is negative, then
  197.   # the price is the default price. Otherwise, it is the specified price.
  198.   #-----------------------------------------------------------------------------
  199.   def self.get_good(shop, item, price=-1)
  200.     good = shop.shop_goods.detect {|good| good.item == item}
  201.     return good if good
  202.     good_id = shop.shop_goods.size + 1
  203.     type = item_type(item)
  204.     if price < 0
  205.       price_type = price = 0
  206.     else
  207.       price_type = 1
  208.     end
  209.     return Game_ShopGood.new(good_id, type, item.id, price_type, price)
  210.   end

  211.   #-----------------------------------------------------------------------------
  212.   # Returns the type of an item.
  213.   #-----------------------------------------------------------------------------
  214.   def self.item_type(item)
  215.     return 0 if item.is_a?(RPG::Item)
  216.     return 1 if item.is_a?(RPG::Weapon)
  217.     return 2 if item.is_a?(RPG::Armor)
  218.     return -1
  219.   end
  220. end

  221. #-------------------------------------------------------------------------------
  222. # Shops are stored in a global variable `$game_shops`. This is dumped and
  223. # loaded appropriately.
  224. #-------------------------------------------------------------------------------
  225. module DataManager

  226.   class << self
  227.     alias :th_shop_manager_create_game_objects :create_game_objects
  228.     alias :th_shop_manager_make_save_contents :make_save_contents
  229.     alias :th_shop_manager_extract_save_contents :extract_save_contents
  230.   end

  231.   def self.create_game_objects
  232.     th_shop_manager_create_game_objects
  233.     $game_shops = Game_Shops.new
  234.   end

  235.   def self.make_save_contents
  236.     contents = th_shop_manager_make_save_contents
  237.     contents[:shops] = $game_shops
  238.     contents
  239.   end

  240.   #-----------------------------------------------------------------------------
  241.   # Load shop data
  242.   #-----------------------------------------------------------------------------
  243.   def self.extract_save_contents(contents)
  244.     th_shop_manager_extract_save_contents(contents)
  245.     $game_shops = contents[:shops]
  246.   end
  247. end

  248. class Game_Temp

  249.   # even if we're not actually calling a shop, it shouldn't affect anything
  250.   # because we are always setting this at each common event call by an event
  251.   attr_accessor :shop_common_event_id

  252.   alias :th_shop_manager_reserve_common_event :reserve_common_event
  253.   def reserve_common_event(common_event_id)
  254.     th_shop_manager_reserve_common_event(common_event_id)
  255.     @shop_common_event_id = common_event_id
  256.   end
  257. end

  258. class Game_Event < Game_Character

  259.   alias :th_shop_manager_setup_page :setup_page
  260.   def setup_page(page)
  261.     th_shop_manager_setup_page(page)
  262.     ShopManager.refresh_shop(@map_id, @id)
  263.   end
  264. end

  265. class Game_Interpreter

  266.   alias :th_shop_manager_clear :clear
  267.   def clear
  268.     th_shop_manager_clear
  269.     clear_shop_options
  270.     @shop_type = nil
  271.   end

  272.   #-----------------------------------------------------------------------------
  273.   # New.
  274.   #-----------------------------------------------------------------------------
  275.   def clear_shop_options
  276.     @shop_options = {}
  277.     @shop_options[:hidden] = {}
  278.     @shop_options[:disabled] = {}
  279.   end

  280.   #-----------------------------------------------------------------------------
  281.   # New. We are in a common event only if the shop common event ID is set.
  282.   #-----------------------------------------------------------------------------
  283.   def shop_map_id
  284.     $game_temp.shop_common_event_id ? 0 : @map_id
  285.   end

  286.   def shop_event_id
  287.     $game_temp.shop_common_event_id ? $game_temp.shop_common_event_id : @event_id
  288.   end

  289.   #--------------------------------------------------------------------------
  290.   # Set the shop's common event ID
  291.   #--------------------------------------------------------------------------
  292.   alias :th_shop_manager_command_117 :command_117
  293.   def command_117
  294.     $game_temp.shop_common_event_id = @params[0]
  295.     th_shop_manager_command_117
  296.   end

  297.   #-----------------------------------------------------------------------------
  298.   # Replaced. A shop is setup only once, and is retrieved whenever it is
  299.   # called in the future. This assumes the shop is invoked through "normal"
  300.   # event interactions.
  301.   #-----------------------------------------------------------------------------
  302.   def command_302
  303.     return if $game_party.in_battle
  304.     shop_type = @shop_type || :Shop
  305.     good_id = 1
  306.     goods = []

  307.     # setup goods
  308.     good = make_good(@params[0..-1], good_id) # last param is for the shop
  309.     goods.push(good)
  310.     good_id +=1

  311.     while next_event_code == 605
  312.      @index += 1
  313.       good = make_good(@list[@index].parameters, good_id)
  314.       goods.push(good)
  315.       good_id +=1
  316.     end
  317.     # Setup shop if needed
  318.     shop = ShopManager.setup_shop(shop_map_id, shop_event_id, goods, @params[4], shop_type)

  319.     # prepare the shop with a reference to the actual shop
  320.     ShopManager.call_scene(shop)
  321.     Fiber.yield

  322.     # clear out the shop common event ID.
  323.     $game_temp.shop_common_event_id = nil
  324.   end

  325.   #-----------------------------------------------------------------------------
  326.   # New. This is where the goods are setup.
  327.   #-----------------------------------------------------------------------------
  328.   def make_good(goods_array, good_id)
  329.     item_type, item_id, price_type, price = goods_array
  330.     good = Game_ShopGood.new(good_id, item_type, item_id, price_type, price)

  331.     # additional setup
  332.     setup_good(good, good_id)
  333.     return good
  334.   end

  335.   #-----------------------------------------------------------------------------
  336.   # New. You can do more things with your good here
  337.   #-----------------------------------------------------------------------------
  338.   def setup_good(good, good_id)
  339.     setup_hidden_option(good, good_id)
  340.     setup_disabled_option(good, good_id)
  341.   end

  342.   #-----------------------------------------------------------------------------
  343.   # New. Shop options
  344.   #-----------------------------------------------------------------------------
  345.   def hide_good(good_id, condition)
  346.     @shop_options[:hidden][good_id] = condition
  347.   end

  348.   def disable_good(good_id, condition)
  349.     @shop_options[:disabled][good_id] = condition
  350.   end

  351.   def setup_hidden_option(good, good_id)
  352.     return unless @shop_options[:hidden][good_id]
  353.     good.hidden_condition = @shop_options[:hidden][good_id]
  354.   end

  355.   def setup_disabled_option(good, good_id)
  356.     return unless @shop_options[:disabled][good_id]
  357.     good.disable_condition = @shop_options[:disabled][good_id]
  358.   end
  359. end

  360. #-------------------------------------------------------------------------------
  361. # A shop good.
  362. # This is a wrapper around a raw item (RPG::Item, RPG::Weapon, etc).
  363. #-------------------------------------------------------------------------------

  364. class Game_ShopGood

  365.   attr_reader :id         # ID of this good
  366.   attr_reader :item_type
  367.   attr_reader :item_id
  368.   attr_reader :price_type
  369.   attr_accessor :hidden_condition
  370.   attr_accessor :disable_condition

  371.   def initialize(id, item_type, item_id, price_type, price)
  372.     @id = id
  373.     @item_type = item_type
  374.     @item_id = item_id
  375.     @price_type = price_type
  376.     @price = price
  377.     @hidden_condition = ""
  378.     @disable_condition = ""
  379.   end

  380.   def include?
  381.     return false if eval(@hidden_condition)
  382.     return true
  383.   end

  384.   def enable?
  385.     return false if eval(@disable_condition)
  386.     return true
  387.   end

  388.   def item
  389.     return $data_items[@item_id] if @item_type == 0
  390.     return $data_weapons[@item_id] if @item_type == 1
  391.     return $data_armors[@item_id] if @item_type == 2
  392.   end

  393.   def price
  394.     return item.price if @price_type == 0
  395.     return @price
  396.   end
  397. end

  398. #-------------------------------------------------------------------------------
  399. # A shop object. Stores information about the shop such as its inventory
  400. # and other shop-related data
  401. #-------------------------------------------------------------------------------
  402. class Game_Shop
  403.   attr_reader :purchase_only
  404.   attr_reader :shop_goods      # all goods that this shop has.
  405.   attr_accessor :need_refresh  # shop needs to be refreshed

  406.   def initialize(goods, purchase_only=false)
  407.     @shop_goods = goods
  408.     @purchase_only = purchase_only
  409.     @need_refresh = false
  410.   end
  411.   #-----------------------------------------------------------------------------
  412.   # Returns true if the goods should be included
  413.   #-----------------------------------------------------------------------------
  414.   def include?(index)
  415.     true
  416.   end

  417.   #-----------------------------------------------------------------------------
  418.   # Return a set of goods for sale
  419.   #-----------------------------------------------------------------------------
  420.   def goods
  421.     @shop_goods
  422.   end

  423.   #-----------------------------------------------------------------------------
  424.   # Add a new good to the shop
  425.   #-----------------------------------------------------------------------------
  426.   def add_good(good)
  427.     @shop_goods.push(good) unless @shop_goods.include?(good)
  428.   end

  429.   #-----------------------------------------------------------------------------
  430.   # Remove the specified good from the shop
  431.   #-----------------------------------------------------------------------------
  432.   def remove_good(good_id)
  433.     @shop_goods.delete_at(good_id - 1)
  434.   end
  435. end

  436. #-------------------------------------------------------------------------------
  437. # A wrapper containing all shops in the game.
  438. #-------------------------------------------------------------------------------
  439. class Game_Shops

  440.   #-----------------------------------------------------------------------------
  441.   # Initializes a hash of game shops. Each key is a map ID, pointing to another
  442.   # hash whose keys are event ID's and values are Game_Shop objects.
  443.   #-----------------------------------------------------------------------------
  444.   def initialize
  445.     @data = {}
  446.   end

  447.   def [](i, j)
  448.     @data[i] ||= {}
  449.     @data[i][j]
  450.   end

  451.   def []=(i, j, shop)
  452.     @data[i] ||= {}
  453.     @data[i][j] = shop
  454.   end
  455. end

  456. #-------------------------------------------------------------------------------
  457. # The shop scene now works with the Shop and ShopGood objects
  458. #-------------------------------------------------------------------------------
  459. class Scene_Shop < Scene_MenuBase
  460.   #--------------------------------------------------------------------------
  461.   # Replaced. The scene now takes a Game_Shop object
  462.   #--------------------------------------------------------------------------
  463.   def prepare(shop)
  464.     @shop = shop
  465.     @goods = shop.goods
  466.     @purchase_only = shop.purchase_only
  467.   end

  468.   alias :th_shop_manager_on_buy_ok :on_buy_ok
  469.   def on_buy_ok
  470.     @selected_good = @buy_window.current_good
  471.     th_shop_manager_on_buy_ok
  472.   end
  473. end

  474. #-------------------------------------------------------------------------------
  475. # @shop_goods is now an array of Game_ShopGoods
  476. #-------------------------------------------------------------------------------
  477. class Window_ShopBuy < Window_Selectable

  478.   #--------------------------------------------------------------------------
  479.   # New. Returns true if the good should be included in the shop inventory
  480.   #--------------------------------------------------------------------------
  481.   def include?(shopGood)
  482.     shopGood.include?
  483.   end

  484.   alias :th_shop_manager_enable? :enable?
  485.   def enable?(item)
  486.     return false unless @goods[item].enable?
  487.     th_shop_manager_enable?(item)
  488.   end

  489.   #--------------------------------------------------------------------------
  490.   # New. Get the currently selected good
  491.   #--------------------------------------------------------------------------
  492.   def current_good
  493.     @goods[item]
  494.   end

  495.   #-----------------------------------------------------------------------------
  496.   # Replaced. ShopGood takes care of most information. The data still contains
  497.   # a list of RPG items for now since I don't want to change them to goods yet
  498.   # A separate list of goods for sale is used for 1-1 correspondence
  499.   #-----------------------------------------------------------------------------
  500.   def make_item_list
  501.     @data = []
  502.     @goods = {}
  503.     @price = {}
  504.     @shop_goods.each do |shopGood|
  505.       next unless include?(shopGood)
  506.       item = shopGood.item
  507.       @data.push(item)
  508.       @goods[item] = shopGood
  509.       @price[item] = shopGood.price
  510.     end
  511.   end
  512. end
复制代码
=begin
#===============================================================================
Title: Shop Stock
Author: Tsukihime
Date: Feb 22, 2013
--------------------------------------------------------------------------------
** Change log
Feb 22, 2013
   - Initial release
--------------------------------------------------------------------------------   
** 使用协议
* 免费用于商业或非商业项目
* 自由使用
* 会有BUG修复,但没有兼容性补丁
* 功能可能没有保证
* Preserve this header
--------------------------------------------------------------------------------
** 必需

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

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

--------------------------------------------------------------------------------
** 用法

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

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

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

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

#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["TH_ShopStock"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
  module Shop_Stock
  end
end
#===============================================================================
# ** Rest of the Script
#===============================================================================
class Game_Interpreter

  alias :th_shop_stock_clear :clear
  def clear
    th_shop_stock_clear
    @shop_stock = []
  end

  alias :th_shop_stock_setup_good :setup_good
  def setup_good(good, id)
    th_shop_stock_setup_good(good, id)
    stock = @shop_stock[id]
    return unless stock
    good.stock = stock
  end
end
class Game_ShopGood
  attr_reader :stock

  alias :th_shop_stock_init :initialize
  def initialize(*args)
    th_shop_stock_init(*args)
    @stock = -1
    @unlimited = ture
  end

  def stock=(amount)
    @stock = amount
   @unlimited = (amount < 0)
  end

  def unlimited?
    @unlimited
  end

  def increase_stock(amount)
    @stock += amount
  end

  def decrease_stock(amount)
    return if @unlimited
    @stock = [@stock - amount, 0].max
  end
end

class Game_Shop

  alias :th_shop_stock_include? :include?
  def include?(index)
    return false if stock(index) == 0
    th_shop_stock_include?(index)
  end

  def stock(index)
    @shop_goods[index].stock
  end
end

class Window_ShopBuy < Window_Selectable

  alias :th_shop_stock_include? :include?
  def include?(shopGood)
    return false if shopGood.stock == 0
    th_shop_stock_include?(shopGood)
  end

  alias :th_shop_stock_draw_item :draw_item
  def draw_item(index)
    th_shop_stock_draw_item(index)
    rect = item_rect(index)
    item = @data[index]
    shopGood = @goods[item]
    draw_text(rect, sprintf("庫存:%d", shopGood.stock), 1) unless shopGood.unlimited?
  end

  alias :th_shop_stock_process_ok :process_ok
  def process_ok
    unless @data[index]
      Sound.play_buzzer
      return
    end
    th_shop_stock_process_ok
  end
end

class Scene_Shop < Scene_MenuBase

  #--------------------------------------------------------------------------
  # Get amount you could buy, compared to the amount in-stock
  #--------------------------------------------------------------------------
  alias :th_shop_stock_max_buy :max_buy
  def max_buy
    party_max = th_shop_stock_max_buy
    @selected_good.unlimited? ? party_max : [party_max, @selected_good.stock].min
  end

  #--------------------------------------------------------------------------
  # Decrease the amount of stock of the selected good
  #--------------------------------------------------------------------------
  alias :th_shop_stock_do_buy :do_buy
  def do_buy(number)
    th_shop_stock_do_buy(number)
    @selected_good.decrease_stock(number)
  end
end

提示第二个脚本87行       @unlimited = ture  出错  改成false也会出错  求解决

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
2
 楼主| 发表于 2014-10-12 13:48:50 | 只看该作者
第二个脚本:
  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.   alias :th_shop_stock_clear :clear
  58.   def clear
  59.     th_shop_stock_clear
  60.     @shop_stock = []
  61.   end

  62.   alias :th_shop_stock_setup_good :setup_good
  63.   def setup_good(good, id)
  64.     th_shop_stock_setup_good(good, id)
  65.     stock = @shop_stock[id]
  66.     return unless stock
  67.     good.stock = stock
  68.   end
  69. end
  70. class Game_ShopGood
  71.   attr_reader :stock

  72.   alias :th_shop_stock_init :initialize
  73.   def initialize(*args)
  74.     th_shop_stock_init(*args)
  75.     @stock = -1
  76.     [url=home.php?mod=space&uid=263900]@unlimited[/url] = ture
  77.   end

  78.   def stock=(amount)
  79.     @stock = amount
  80.    [url=home.php?mod=space&uid=263900]@unlimited[/url] = (amount < 0)
  81.   end

  82.   def unlimited?
  83.     @unlimited
  84.   end

  85.   def increase_stock(amount)
  86.     @stock += amount
  87.   end

  88.   def decrease_stock(amount)
  89.     return if @unlimited
  90.     @stock = [@stock - amount, 0].max
  91.   end
  92. end

  93. class Game_Shop

  94.   alias :th_shop_stock_include? :include?
  95.   def include?(index)
  96.     return false if stock(index) == 0
  97.     th_shop_stock_include?(index)
  98.   end

  99.   def stock(index)
  100.     @shop_goods[index].stock
  101.   end
  102. end

  103. class Window_ShopBuy < Window_Selectable

  104.   alias :th_shop_stock_include? :include?
  105.   def include?(shopGood)
  106.     return false if shopGood.stock == 0
  107.     th_shop_stock_include?(shopGood)
  108.   end

  109.   alias :th_shop_stock_draw_item :draw_item
  110.   def draw_item(index)
  111.     th_shop_stock_draw_item(index)
  112.     rect = item_rect(index)
  113.     item = @data[index]
  114.     shopGood = @goods[item]
  115.     draw_text(rect, sprintf("庫存:%d", shopGood.stock), 1) unless shopGood.unlimited?
  116.   end

  117.   alias :th_shop_stock_process_ok :process_ok
  118.   def process_ok
  119.     unless @data[index]
  120.       Sound.play_buzzer
  121.       return
  122.     end
  123.     th_shop_stock_process_ok
  124.   end
  125. end

  126. class Scene_Shop < Scene_MenuBase

  127.   #--------------------------------------------------------------------------
  128.   # Get amount you could buy, compared to the amount in-stock
  129.   #--------------------------------------------------------------------------
  130.   alias :th_shop_stock_max_buy :max_buy
  131.   def max_buy
  132.     party_max = th_shop_stock_max_buy
  133.     @selected_good.unlimited? ? party_max : [party_max, @selected_good.stock].min
  134.   end

  135.   #--------------------------------------------------------------------------
  136.   # Decrease the amount of stock of the selected good
  137.   #--------------------------------------------------------------------------
  138.   alias :th_shop_stock_do_buy :do_buy
  139.   def do_buy(number)
  140.     th_shop_stock_do_buy(number)
  141.     @selected_good.decrease_stock(number)
  142.   end
  143. end
复制代码
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
3
 楼主| 发表于 2014-10-12 13:50:04 | 只看该作者
提示第二个脚本87行:      @unlimited = ture   出错
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
4
 楼主| 发表于 2014-10-12 13:50:42 | 只看该作者
87行    @ unlimited = ture   出错
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
65
在线时间
156 小时
注册时间
2013-11-1
帖子
16
5
发表于 2014-10-15 14:34:23 | 只看该作者
把第一个脚本放到最上面试试……我就这样做的……
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
6
 楼主| 发表于 2014-10-15 23:40:02 | 只看该作者
我想告诉你 发表于 2014-10-15 14:34
把第一个脚本放到最上面试试……我就这样做的……

把第一个脚本放在所有脚本最上方 又会出现274行 错误   可能说我脚本问题,你能把脚本发来我试试吗?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
65
在线时间
156 小时
注册时间
2013-11-1
帖子
16
7
发表于 2014-10-17 13:01:11 | 只看该作者
本帖最后由 我想告诉你 于 2014-10-17 13:07 编辑
qq1014850720 发表于 2014-10-15 23:40
把第一个脚本放在所有脚本最上方 又会出现274行 错误   可能说我脚本问题,你能把脚本发来我试试吗? ...


额……老家稻子成熟我出去了几天……,………………有点长,看样子点评不了。你指的是你的脚本还是我的?如果是你的我是直接复制下来丢进去,第一个最上第二个最下(本人也是脚本盲,能做的只有这么多),之前两个脚本都在最下面的时候出现了你第一次出现的问题。顺便说一下我那时只是初步测试,如果物品被限定买完就没了,如果再卖回去也不会变多……。如果要我的脚本还是免了吧,把名字列出来也是个大工程。顺便提醒一下是不是URL或者mail什么的错误?这两个很常见……
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
532
在线时间
238 小时
注册时间
2011-7-17
帖子
101
8
 楼主| 发表于 2014-10-23 21:43:20 | 只看该作者
我想告诉你 发表于 2014-10-17 13:01
额……老家稻子成熟我出去了几天……,………………有点长,看样子点评不了。你指的是你的脚本还是我的? ...

我逛66论坛发现的   脚本是你写的吗?  能把你现在完成的发给我吗?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-14 10:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表