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

Project1

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

[已经解决] 多货币脚本出错了,请帮忙…………

[复制链接]

Lv1.梦旅人

梦石
0
星屑
168
在线时间
45 小时
注册时间
2012-9-4
帖子
30
跳转到指定楼层
1
发表于 2012-9-23 13:55:19 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
  1. module Currency
  2. #==============================================================================
  3. #   设定部分
  4. #==============================================================================
  5. # 货币名称 -- 在金钱窗口里使用
  6. @name = ["金", "银", "币", "款", "汇"]

  7. # 货币名称 -- 在商店里选择时使用
  8. @iname =["金币", "银币", "铜币", "存款", "汇票"]

  9. # 货币汇率 -- 计算价钱用
  10. @rate = [ 1, 0.5, 0.25, 1, 1]
  11. # 无法使用的货币
  12. @cannot_use = [3, 4]
  13. # 不在金钱窗口显示的货币
  14. @do_not_show = [4]
  15. # 货币文字 -- 商店画面选项理所显示的文字
  16. def self.word
  17. return "选择货币"
  18. end
  19. # 只能用特定货币购买时显示的文字
  20. # %s代表该货币
  21. One_Currency = "只能用%s来购买!"

  22. # 金钱窗口设置:是否在菜单显示新的金钱窗口
  23. SHOW_NEW_CURRENCY = true
  24. #==============================================================================
  25. #  设定部分结束
  26. #==============================================================================
  27. #==============================================================================
  28. #   使用方法
  29. #==============================================================================
  30. =begin
  31. 在事件中使用脚本:
  32. gain_currency(类型, 数量)增加该类型货币
  33. lose_currency(类型, 数量)减少该类型货币
  34. convert(类型, 变量ID) 将该变量内的数值转换为该类型并返回
  35. currency_type(类型, 变量ID) 将该类型货币金额代入该变量
  36. 在物品(武器、防具亦可,技能尚未测试)的备注栏打上
  37. [currency 类型]
  38. 则该物品只能使用该类型货币购买
  39. 在物品(武器、防具亦可,技能尚未测试)的备注栏打上
  40. [n_currency 类型]
  41. 则该物品只能使用该类型以外的货币购买
  42. 两个同时定义时,会互相抵销
  43. (例如:同一个物品同时定义了[currency 1] 和[n_currency 1]
  44. 也就是同时「只能使用1号货币」和「只能除用除1号以外的货币」
  45. 那麽就变成了全部都能使用)
  46. 类型为数字代号,就是在脚本中所设定好的顺序(从0开始算)
  47. 0为默认金钱(直接用事件命令就行了)
  48. ☆只能用特定货币购买的商店 设定方法
  49. 在召唤商店画面的NPC事件指令内容使用:
  50. 脚本:$special_currency = n # <== n 为货币类型
  51. 商店处理:商品列表
  52. 脚本:call_new_shop
  53. 设定後,该商店的「货币选择」选项无效
  54. =end
  55. #==============================================================================
  56. #  使用方法结束
  57. #==============================================================================
  58. attr_accessor :name
  59. attr_accessor :rate
  60. def self.get_g_rate(i)
  61. if $game_party.gold != 0
  62. p = @rate[i] * $game_party.gold
  63. return p.to_i == 0? 1 : p.to_i
  64. else
  65. return 0
  66. end
  67. end
  68. def self.get_n_rate(i, number)
  69. if number != 0
  70. p = @rate[i] * number
  71. return p.to_i == 0? 1 : p.to_i
  72. else
  73. return 0
  74. end
  75. end
  76. def self.number
  77. return @name.size
  78. end
  79. def self.name(i)
  80. return @name[i]
  81. end
  82. def self.id(i)
  83. return @iname[i]
  84. end
  85. def self.show?(id)
  86. return !(@do_not_show.include?(id))
  87. end
  88. def self.can_use?(id, item=nil)
  89. return false if @cannot_use.include?(id)
  90. unless item == nil
  91. if item.get_currency_use != nil
  92. return true if item.get_currency_use.include?(id)
  93. elsif item.get_currency_not_use != nil
  94. return false if item.get_currency_not_use.include?(id)
  95. else return true
  96. end
  97. else return true
  98. end
  99. end
  100. end
  101. class Game_Party < Game_Unit
  102. attr_accessor :curr
  103. alias c_ini initialize
  104. def initialize
  105. c_ini
  106. @curr = []
  107. for i in 0...Currency.number
  108. if @curr[i] == nil
  109. @curr[i] = 0
  110. end
  111. end
  112. @curr[0] = @gold
  113. end
  114. # 获得和失去金钱
  115. def gain_curr(type, amount)
  116. @curr[type] = [[@curr[type] + amount, 0].max, 9999999].min
  117. @gold = @curr[0]
  118. end
  119. def lose_curr(type, amount)
  120. gain_curr(type, -amount)
  121. end
  122. def gain_gold(n)
  123. gain_curr(0, n)
  124. end
  125. def curr(n)
  126. return @curr[n] == nil ? 0 : @curr[n]
  127. end
  128. end
  129. class Game_Interpreter
  130. # 获取货币
  131. def gain_currency(type, amount)
  132. $game_party.gain_curr(type, amount)
  133. end
  134. # 失去货币
  135. def lose_currency(type, amount)
  136. $game_party.lose_curr(type, amount)
  137. end
  138. # 货币兑换
  139. def convert(type, vid)
  140. return Currency.get_n_rate(type, $game_variables[vid])
  141. end
  142. # 获取货币持有量
  143. def currency_type(type, vid)
  144. $game_variables[vid] = $game_party.curr(type)
  145. end
  146. # 召唤商店画面
  147. alias old_command_302 command_302
  148. def command_302
  149. if $special_shop != -1
  150. $game_temp.shop_goods = [@params]
  151. $game_temp.shop_purchase_only = @params[2]
  152. loop do
  153. @index += 1
  154. if @list[@index].code == 605
  155. $game_temp.shop_goods.push(@list[@index].parameters)
  156. else
  157. return false
  158. end
  159. end
  160. else
  161. old_command_302
  162. end
  163. end
  164. def call_new_shop
  165. $scene = Scene_Shop.new($special_shop)
  166. $special_shop = -1
  167. end
  168. end
  169. class Scene_Menu < Scene_Base
  170. alias c_menu_start start
  171. def start
  172. c_menu_start
  173. if Currency::SHOW_NEW_CURRENCY
  174. @gold_window.dispose
  175. @gold_window = Window_SGold.new(0, 0)
  176. @gold_window.y = 416-@gold_window.height
  177. end
  178. end
  179. end
  180. class RPG::BaseItem
  181. def get_currency_use
  182. e = []
  183. self.note.split(/[\r\n]+/).each { |line|
  184. if line =~ /\[currency \d+\]/
  185. a = line.split(/ /)[1]
  186. d = ""
  187. while ((c = a.slice!(/./m)) != nil)
  188. d += c if c != ">"
  189. end
  190. e.push(d.to_i)
  191. end
  192. }
  193. return e==[] ? nil : e
  194. end
  195. def get_currency_not_use
  196. e = []
  197. self.note.split(/[\r\n]+/).each { |line|
  198. if line =~ /\[ncurrency \d+\]/
  199. a = line.split(/ /)[1]
  200. d = ""
  201. while ((c = a.slice!(/./m)) != nil)
  202. d += c if c != ">"
  203. end
  204. e.push(d.to_i)
  205. end
  206. }
  207. return e==[] ? nil : e
  208. end
  209. end
  210. #==============================================================================
  211. # ■ Window_SGold
  212. #------------------------------------------------------------------------------
  213. #  新的显示金钱窗口,可以显示多重货币。
  214. #==============================================================================
  215. class Window_SGold < Window_Base
  216. def initialize(x, y, c=-1)
  217. a = 1
  218. @money = []
  219. for i in 0...Currency::number
  220. @money.push(i) if Currency.show?(i)
  221. end
  222. a = @money.size if c == -1
  223. super(x, y, 160, a * WLH + 32)
  224. @currency = c
  225. refresh
  226. end
  227. def refresh
  228. self.contents.clear
  229. if @currency == -1
  230. for i in @money
  231. draw_scurrency_value(i, 4, i*WLH, 120)
  232. end
  233. else
  234. draw_scurrency_value(@currency, 4, 0, 120)
  235. end
  236. end
  237. def draw_scurrency_value(i, x, y, width)
  238. cx = contents.text_size(Vocab::gold).width
  239. self.contents.font.color = normal_color
  240. self.contents.draw_text(x, y, width-cx-2, WLH, $game_party.curr(i), 2)
  241. self.contents.font.color = system_color
  242. self.contents.draw_text(x, y, width, WLH, Currency.name(i), 2)
  243. end
  244. end
  245. #==============================================================================
  246. # ■ Window_ShopBuy
  247. #------------------------------------------------------------------------------
  248. #  商店画面、浏览显示可以购买的商品的窗口。
  249. #==============================================================================
  250. class Window_ShopBuy < Window_Selectable
  251. #--------------------------------------------------------------------------
  252. # ● 初始化对像
  253. # x : 窗口 X 座标
  254. # y : 窗口 Y 座标
  255. # c : 货币类型
  256. #--------------------------------------------------------------------------
  257. def initialize(x, y, c=0)
  258. super(x, y, 304, 304)
  259. @shop_goods = $game_temp.shop_goods
  260. @currency = c
  261. refresh
  262. self.index = 0
  263. end
  264. #--------------------------------------------------------------------------
  265. # ● 绘制商品
  266. # index : 商品索引
  267. #--------------------------------------------------------------------------
  268. def draw_item(index)
  269. item = @data[index]
  270. number = $game_party.item_number(item)
  271. price = Currency.get_n_rate(@currency, item.price)
  272. gold = Currency.get_g_rate(@currency)
  273. enabled = Currency.can_use?(@currency, item)
  274. enabled = ( price <= gold and number < 99) if enabled
  275. rect = item_rect(index)
  276. self.contents.clear_rect(rect)
  277. draw_item_name(item, rect.x, rect.y, enabled)
  278. rect.width -= 4
  279. self.contents.draw_text(rect,price, 2)
  280. end
  281. end
  282. class Window_ShopStatus < Window_Base
  283. alias curr_refresh refresh
  284. def refresh
  285. curr_refresh
  286. currency = []
  287. money = ""
  288. if @item != nil
  289. for i in 0...Currency::number
  290. currency.push(i) if Currency.can_use?(i, @item)
  291. end
  292. for i in currency
  293. money += "、" if i>0 and i<=currency.size
  294. money += Currency.name(i)
  295. end
  296. string = sprintf(Currency::One_Currency, money)
  297. self.contents.draw_text(4, 24, 200, WLH, string,1)
  298. end
  299. end
  300. end
  301. #==============================================================================
  302. # ■ Scene_Shop
  303. #------------------------------------------------------------------------------
  304. #  处理商店画面的类。
  305. #==============================================================================
  306. class Scene_Shop < Scene_Base
  307. def initialize(c=nil)
  308. if c==nil
  309. @special_currency = false
  310. @currency = 0
  311. else
  312. @special_currency = true
  313. @currency = c
  314. end
  315. end
  316. #--------------------------------------------------------------------------
  317. # ● 开始处理
  318. #--------------------------------------------------------------------------
  319. alias c_start start
  320. def start
  321. c_start
  322. @command = []
  323. for i in 0...Currency::number
  324. if Currency.can_use?(i)
  325. @command.push(Currency::id(i))
  326. end
  327. end
  328. @currency_window = Window_Command.new(160, @command, 1, 3)
  329. @currency_window.x = 384
  330. @currency_window.y = 56
  331. @currency_window.active = false
  332. @currency_window.visible = false
  333. @gold_window = Window_SGold.new(384, 56, @currency)
  334. end
  335. #--------------------------------------------------------------------------
  336. # ● 结束处理
  337. #--------------------------------------------------------------------------
  338. alias c_term terminate
  339. def terminate
  340. c_term
  341. @currency_window.dispose
  342. end
  343. #--------------------------------------------------------------------------
  344. # ● 更新画面
  345. #--------------------------------------------------------------------------
  346. def update
  347. super
  348. update_menu_background
  349. @help_window.update
  350. @command_window.update
  351. @gold_window.update
  352. @dummy_window.update
  353. @buy_window.update
  354. @sell_window.update
  355. @number_window.update
  356. @status_window.update
  357. @currency_window.update
  358. if @command_window.active
  359. update_command_selection
  360. elsif @buy_window.active
  361. update_buy_selection
  362. elsif @sell_window.active
  363. update_sell_selection
  364. elsif @number_window.active
  365. update_number_input
  366. elsif @currency_window.active
  367. update_currency_selection
  368. end
  369. end
  370. #--------------------------------------------------------------------------
  371. # ● 生成命令窗口
  372. #--------------------------------------------------------------------------
  373. def create_command_window
  374. s1 = Vocab::ShopBuy
  375. s2 = Vocab::ShopSell
  376. s3 = Vocab::ShopCancel
  377. s4 = Currency.word
  378. @command_window = Window_Command.new(384, [s1, s2, s4, s3], 4)
  379. @command_window.y = 56
  380. @command_window.draw_item(2, false) if @special_currency
  381. if $game_temp.shop_purchase_only
  382. @command_window.draw_item(1, false)
  383. end
  384. end
  385. #--------------------------------------------------------------------------
  386. # ● 更新命令窗口
  387. #--------------------------------------------------------------------------
  388. def update_command_selection
  389. if Input.trigger?(Input::B)
  390. Sound.play_cancel
  391. $scene = Scene_Map.new
  392. elsif Input.trigger?(Input::C)
  393. case @command_window.index
  394. when 0 # 买入
  395. Sound.play_decision
  396. @command_window.active = false
  397. @dummy_window.visible = false
  398. @buy_window.active = true
  399. @buy_window.visible = true
  400. @buy_window.refresh
  401. @status_window.visible = true
  402. when 1 # 卖出
  403. if $game_temp.shop_purchase_only
  404. Sound.play_buzzer
  405. else
  406. Sound.play_decision
  407. @command_window.active = false
  408. @dummy_window.visible = false
  409. @sell_window.active = true
  410. @sell_window.visible = true
  411. @sell_window.refresh
  412. end
  413. when 3 # 离开
  414. Sound.play_decision
  415. $scene = Scene_Map.new
  416. when 2 # 货币
  417. unless @special_currency
  418. Sound.play_decision
  419. @currency_window.active = true
  420. @currency_window.visible = true
  421. @command_window.active = false
  422. @gold_window.visible = false
  423. else
  424. Sound.play_buzzer
  425. end
  426. end
  427. end
  428. end
  429. #--------------------------------------------------------------------------
  430. # ● 更新货币选择窗口
  431. #--------------------------------------------------------------------------
  432. def update_currency_selection
  433. if Input.trigger?(Input::B)
  434. Sound.play_cancel
  435. @currency_window.active = false
  436. @currency_window.visible = false
  437. @command_window.active = true
  438. @gold_window.visible = true
  439. elsif Input.trigger?(Input::C)
  440. Sound.play_decision
  441. @currency_window.active = false
  442. @currency_window.visible = false
  443. @command_window.active = true
  444. @currency = @currency_window.index
  445. @buy_window.dispose
  446. @buy_window = Window_ShopBuy.new(0, 112, @currency)
  447. @buy_window.active = false
  448. @buy_window.visible = false
  449. @gold_window.dispose
  450. @gold_window = Window_SGold.new(384, 56, @currency)
  451. end
  452. end
  453. #--------------------------------------------------------------------------
  454. # ● 更新买入选择
  455. #--------------------------------------------------------------------------
  456. def update_buy_selection
  457. @status_window.item = @buy_window.item
  458. if Input.trigger?(Input::B)
  459. Sound.play_cancel
  460. @command_window.active = true
  461. @dummy_window.visible = true
  462. @buy_window.active = false
  463. @buy_window.visible = false
  464. @status_window.visible = false
  465. @status_window.item = nil
  466. @help_window.set_text("")
  467. return
  468. end
  469. if Input.trigger?(Input::C)
  470. @item = @buy_window.item
  471. number = $game_party.item_number(@item)
  472. price = Currency.get_n_rate(@currency, @item.price)
  473. gold = Currency.get_g_rate(@currency)
  474. enabled = Currency.can_use?(@currency, @item)
  475. enabled = ( price <= gold and number < 99) if enabled
  476. unless enabled
  477. Sound.play_buzzer
  478. else
  479. Sound.play_decision
  480. max = price == 0 ? 99 : gold / @item.price
  481. max = [max, 99 - number].min
  482. @buy_window.active = false
  483. @buy_window.visible = false
  484. @number_window.set(@item, max, @item.price)
  485. @number_window.active = true
  486. @number_window.visible = true
  487. end
  488. end
  489. end
  490. #--------------------------------------------------------------------------
  491. # ● 确认数值输入
  492. #--------------------------------------------------------------------------
  493. def decide_number_input
  494. Sound.play_shop
  495. @number_window.active = false
  496. @number_window.visible = false
  497. case @command_window.index
  498. when 0 # 买入
  499. gold = @number_window.number * @item.price
  500. $game_party.lose_curr(@currency_window.index, gold)
  501. $game_party.gain_item(@item, @number_window.number)
  502. @gold_window.refresh
  503. @buy_window.refresh
  504. @status_window.refresh
  505. @buy_window.active = true
  506. @buy_window.visible = true
  507. when 1 # 卖出
  508. gold = @number_window.number * (@item.price / 2)
  509. $game_party.gain_curr(@currency_window.index, gold)
  510. $game_party.lose_item(@item, @number_window.number)
  511. @gold_window.refresh
  512. @sell_window.refresh
  513. @status_window.refresh
  514. @sell_window.active = true
  515. @sell_window.visible = true
  516. @status_window.visible = false
  517. end
  518. end
  519. end
复制代码
一打开菜单就显示……

360桌面截图20120923134906.jpg (29.56 KB, 下载次数: 17)

360桌面截图20120923134906.jpg

Lv1.梦旅人

梦石
0
星屑
168
在线时间
45 小时
注册时间
2012-9-4
帖子
30
2
 楼主| 发表于 2012-9-23 14:07:41 | 只看该作者
不过还有一个BUG,就是打不开商店菜单??商店处理是无效的
抱歉抱歉,第一个问题已经解决了,现在就是这个。

点评

此问题另外发贴,如果需要的是多货币商店请参照脚本。  发表于 2012-9-26 22:22
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-16 16:49

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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