查看: 2447|回复: 1

[已经解决] 求助,物品價格比例腳本問題

[复制链接]
梦石
0
星屑
2116
在线时间
950 小时
注册时间
2015-7-16
回帖
692

开拓者

发表于 2016-5-1 11:06:36 | 显示全部楼层 |阅读模式

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

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

×
先上個圖
未命名.png

然後上腳本
  1. #==============================================================================
  2. # ** 物品價格比例
  3. #  作者:影月千秋
  4. #  适用:VA
  5. #------------------------------------------------------------------------------
  6. # * 简介
  7. #    提供物品交易时对價格的一系列处理,比如全体物品售价增加20%、全体物品回收
  8. # (販賣)價格增加原价的35%、某物品的販賣價格占原价的70%等等。
  9. #    Github:[url]https://github.com/ShadowMomo/Smomo-RGSS-Scripts[/url]
  10. #==============================================================================
  11. # * 使用方法
  12. #   将此脚本插入到其他脚本以下,Main以上
  13. #   在下方设定脚本所使用的开关及变量ID
  14. #   数据库中,在物品的备注栏按照下方的正则式来填写匹配备注
  15. #   游戏中可以通过操作开关和变量来进行價格处理
  16. #
  17. #  * 说明
  18. #   買價:从商店买商品的價格
  19. #   賣價:卖给商店的商品價格
  20. #
  21. #  * 物品的备注
  22. #   在备注中按照正则式填写,默认格式为 <販賣 XX> ,XX为任意数字,表示这个物品
  23. #  的買價将会是原价的 XX%
  24. #   例:
  25. #    <販賣 65>
  26. #
  27. #  * Buying变量
  28. #   游戏中更改这个变量的值,则物品買價将为:原价 乘以(1 + 变量值 %)
  29. #
  30. #  * Selling变量
  31. #   改变所有物品賣價占買價的比例,新比例 = 原比例 + 变量值
  32. #   如果物品备注栏做了上述设置(脚本第21行),则原比例即为设置的比例;如果没有,
  33. #  则原比例为50。
  34. #
  35. #  * 其他可选功能
  36. #   见设定区内置说明。
  37. #==============================================================================
  38. # * 更新
  39. #   V 1.2 2014.09.07 新增功能 新功能依赖虚拟日历
  40. #   V 1.1 2014.08.15 新增功能 并规范化
  41. #   V 1.0 2013.12.15 新建
  42. #==============================================================================
  43. # * 声明
  44. #   本脚本来自"影月千秋", 使用/修改/转载请保留此信息。
  45. #==============================================================================

  46. $smomo ||= {}
  47. if $smomo["ItemPriceRate"].nil?
  48. $smomo["ItemPriceRate"] = true

  49. #===============================================================================
  50. # ** Smomo
  51. #===============================================================================
  52. module Smomo
  53.   #=============================================================================
  54.   # ** Smomo::ItemPriceRate
  55.   #=============================================================================
  56.   module ItemPriceRate
  57.     Using = 38
  58.     # 开关ID:启用/禁用脚本功能
  59.     Buying = 32
  60.     # 变量ID:控制 从商店购买物品时 價格增加的比例
  61.     Selling = 33
  62.     # 变量ID:控制 在商店卖出物品时 賣價占原价比例的增量
  63.     Match_Reg = /<販賣\s+(\d+)>/
  64.     # 匹配物品备注栏的正则式,如果懂的话可以自己改(不建议)
  65.     # 默认: /<販賣\s+(\d+)>/   匹配举例: <販賣 21>  其中21可以替换为任意数字
  66.     # 以下是可选功能
  67.     OPTIONAL = {
  68.       profiteer: 1,
  69.       # 在販賣商品时,如果商店中没有有你要卖的商品(你拥有商品 而商店没有)
  70.       # 你的賣價相对你原賣價的倍数
  71.       # 即:实际賣價 = 賣價 * 该值
  72.       # 设为1 则此功能停用
  73.       limitForCalendar: {
  74.       # 配合虚拟日历系统([url]http://tinyurl.com/psamf9t[/url])使用
  75.       # 欲使此功能生效,请将虚拟日历系统置于此系统上方
  76.       # 使某物品被买了特定数目之后会停售 直到第二天才恢复
  77.       # 仅对物品有效 对武器和防具无效
  78.         # 物品ID => 限制数目,
  79.         3 => 4,
  80.         6 => 158,
  81.       },
  82.     }
  83. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+#
  84. #-------------                     --------------------------------------------#
  85.                "请勿跨过这块区域"
  86. #-------------                     --------------------------------------------#
  87. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=#
  88.     if $smomo["Calendar"]
  89.       OPTIONAL[:lfcalendar] = OPTIONAL[:limitForCalendar].clone
  90.       met = ->{OPTIONAL[:lfcalendar].each_key{|i| OPTIONAL[:lfcalendar][i] = 0}}
  91.       Smomo::Calendar.routine.push met
  92.       met.call
  93.     end
  94.   end
  95. end
  96. #==============================================================================
  97. # ** Window_ShopBuy
  98. #==============================================================================
  99. class Window_ShopBuy
  100.   alias :item_price_rate_price :price
  101.   def price(item)
  102.     return item.price unless @price[item]
  103.     if $game_switches[Smomo::ItemPriceRate::Using]
  104.       @price[item] * (100 + $game_variables[Smomo::ItemPriceRate::Buying]) / 100
  105.     else
  106.       item_price_rate_price item
  107.     end
  108.   end
  109.   alias :item_price_rate_make_item_list :make_item_list
  110.   def make_item_list
  111.     item_price_rate_make_item_list
  112.     sio = Smomo::ItemPriceRate::OPTIONAL
  113.     @data.reject!{|item|
  114.       i = item.id
  115.       item.is_a?(RPG::Item) && sio[:lfcalendar][i] &&
  116.       sio[:lfcalendar][i] >= sio[:limitForCalendar][i]
  117.     }
  118.   end
  119. end
  120. #==============================================================================
  121. # ** Scene_Shop
  122. #==============================================================================
  123. class Scene_Shop
  124.   alias :item_price_rate_selling_price :selling_price
  125.   def selling_price
  126.     (if $game_switches[Smomo::ItemPriceRate::Using]
  127.       rate = Smomo::ItemPriceRate::Match_Reg =~ @item.note ? $1.to_i : 50
  128.       rate += $game_variables[Smomo::ItemPriceRate::Selling]
  129.       @buy_window.make_item_list
  130.       prc = @item.price * rate / 100
  131.       prc > buying_price ? buying_price : prc
  132.     else
  133.       item_price_rate_selling_price
  134.     end * (@goods.none?{|g| g[1] == @item.id} ?
  135.     Smomo::ItemPriceRate::OPTIONAL[:profiteer] : 1)).round
  136.   end
  137.   alias :item_price_rate_do_buy :do_buy
  138.   def do_buy(number)
  139.     item_price_rate_do_buy number
  140.     sio = Smomo::ItemPriceRate::OPTIONAL
  141.     if @item.is_a?(RPG::Item) && sio[:lfcalendar][@item.id]
  142.       sio[:lfcalendar][@item.id] += number
  143.     end
  144.   end
  145.   alias :item_price_rate_max_buy :max_buy
  146.   def max_buy
  147.     sio = Smomo::ItemPriceRate::OPTIONAL
  148.     if @item.is_a?(RPG::Item) && sio[:lfcalendar][@item.id]
  149.       new_max = sio[:limitForCalendar][@item.id] - sio[:lfcalendar][@item.id]
  150.       [item_price_rate_max_buy, new_max].min
  151.     else
  152.       item_price_rate_max_buy
  153.     end
  154.   end
  155. end

  156. else
  157.   msgbox "请不要重复加载此脚本 : )\n【物品價格比例 ItemPriceRate】"
  158. end
  159. #==============================================================================#
  160. #=====                        =================================================#
  161.            "脚 本 尾"
  162. #=====                        =================================================#
  163. #==============================================================================#
复制代码
[神性领域扩张:扩张神性领域]
说了等于没说.
梦石
0
星屑
60
在线时间
62 小时
注册时间
2016-5-2
回帖
173
发表于 2016-5-4 07:18:09 | 显示全部楼层
本帖最后由 李牧羊 于 2016-5-4 07:20 编辑

呃...在下斗胆试试了先...
这个没有bug
  1. #==============================================================================
  2. # ■ 物品价格比例
  3. #  作者:影月千秋
  4. #  版本:V 1.0
  5. #  最近更新:2013.12.15
  6. #  适用:VA
  7. #------------------------------------------------------------------------------
  8. # ● 简介
  9. #  提供物品交易时对价格的一系列处理,比如全体物品售价增加20%、全体物品回收(贩卖)价
  10. # 格增加原价的35%、某物品的贩卖价格占原价的70%等等
  11. #==============================================================================
  12. # ● 使用方法
  13. #   将此脚本插入到其他脚本以下,Main以上
  14. #   在下方设定脚本所使用的开关及变量ID
  15. #   数据库中,在物品的备注栏按照下方的正则式来填写匹配备注
  16. #   游戏中可以通过操作开关和变量来进行价格处理
  17. #
  18. #  * 物品的备注
  19. #   在备注中按照正则式填写,默认格式为 <贩卖 XX> ,XX为任意数字,代表着这个物品的
  20. #  售价将会是原价的 XX%
  21. #   例:
  22. #    <贩卖 65>
  23. #  * Buying变量
  24. #   游戏中更改这个变量的值,则物品售价(你付出的)将为【原价 乘以(1 + 变量值 %)】
  25. #  * Selling变量
  26. #   改变所有物品贩卖价格占售价的比例,新比例 = 原比例 + 变量值
  27. #   如果物品备注栏做了上述设置(脚本第18行) 则原比例即为设置的比例 如果没有
  28. #  则原比例为50
  29. #==============================================================================
  30. # ● 更新
  31. #   V 1.0 2013.12.15 新建
  32. #==============================================================================
  33. # ● 声明
  34. #   本脚本来自【影月千秋】,使用、修改和转载请保留此信息
  35. #==============================================================================

  36. $smomo ||= {}
  37. if $smomo["ItemPriceRate"].nil?
  38. $smomo["ItemPriceRate"] = true

  39. #===============================================================================
  40. # ■ Smomo
  41. #===============================================================================
  42. module Smomo
  43.   #=============================================================================
  44.   # ■ Smomo::ItemPriceRate
  45.   #=============================================================================
  46.   module ItemPriceRate
  47.     Using = 6
  48.     # 开关ID:启用/禁用脚本功能
  49.     Buying = 7
  50.     # 变量ID:控制 从商店购买物品时 价格增加的比例
  51.     Selling = 8
  52.     # 变量ID:控制 在商店卖出物品时 售价占原价比例的增量
  53.     Match_Reg = /<贩卖\s+(\d+)>/
  54.     # 匹配物品备注栏的正则式,如果懂的话可以自己改(不建议)
  55.     # 默认: /<贩卖\s+(\d+)>/   匹配举例: <贩卖 21>  其中21可以替换为任意数字
  56.    
  57. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+#
  58. #------------------------------------------------------------------------------#
  59. #                               请勿跨过这块区域                                #
  60. #------------------------------------------------------------------------------#
  61. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=#
  62.   end
  63. end
  64. #==============================================================================
  65. # ■ Window_ShopBuy
  66. #==============================================================================
  67. class Window_ShopBuy
  68.   alias :item_price_rate_price :price
  69.   def price(item)
  70.     return item.price unless @price[item]
  71.     if $game_switches[Smomo::ItemPriceRate::Using]
  72.       @price[item] * (100 + $game_variables[Smomo::ItemPriceRate::Buying]) / 100
  73.     else
  74.       item_price_rate_price(item)
  75.     end
  76.   end
  77. end
  78. #==============================================================================
  79. # ■ Scene_Shop
  80. #==============================================================================
  81. class Scene_Shop
  82.   alias :item_price_rate_selling_price :selling_price
  83.   def selling_price
  84.     if $game_switches[Smomo::ItemPriceRate::Using]
  85.       rate = Smomo::ItemPriceRate::Match_Reg =~ @item.note ? $1.to_i : 50
  86.       rate += $game_variables[Smomo::ItemPriceRate::Selling]
  87.       @buy_window.make_item_list
  88.       prc = @item.price * rate / 100
  89.       prc > buying_price ? buying_price : prc
  90.     else
  91.       item_price_rate_selling_price
  92.     end
  93.   end
  94. end

  95. else # if $smomo
  96.   msgbox "请不要重复加载此脚本 : )\n【物品价格比例 ItemPriceRate】"
  97. end
  98. #==============================================================================#
  99. #=====                        =================================================#
  100.            "■ 脚 本 尾"
  101. #=====                        =================================================#
  102. #==============================================================================#
复制代码


1.  新开工程
2.  前置脚本
3.  设置备注

三项经过【控制变量法】的测试,均如楼主一样报错,因此在下猜测这应该是个bug,使用前面的版本就可以了
已测,可行

评分

参与人数 2星屑 +10 梦石 +1 收起 理由
丿梁丶小柒 + 1 认可答案
duzine + 10 感謝,雖然後來還是無效,但我發現替代物了.

查看全部评分

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部