查看: 2866|回复: 2

[已经解决] 如何设置道具使用条件?

[复制链接]
梦石
0
星屑
143
在线时间
347 小时
注册时间
2010-7-7
回帖
96
发表于 2013-12-9 17:29:11 | 显示全部楼层 |阅读模式

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

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

×
比如在战斗中,将要使用复活石来复活一名队友,但是使用复活石会消耗100点TP值,如果TP值不足则无法使用该道具,请问如何实现?
梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
回帖
2257

贵宾

发表于 2013-12-9 20:39:55 | 显示全部楼层
本帖最后由 Sion 于 2013-12-9 20:41 编辑
  1. # 设置战斗物品消耗,物品备注中写:
  2. # cost tp:100 消耗使用者 100 TP
  3. # Cost_HP 200 消耗 200 HP
  4. # cost_mp_100 消耗 100 MP
  5. # 大小写和用来隔开的符号随意
  6. # 对应值不足则无法使用,可以设置一个物品消耗多种数值
  7. # 因为平时使用物品根本没有指定使用者,所以非战斗中使用物品时,不计算这些额外消耗。
  8. # [url=home.php?mod=space&uid=95897]@actor[/url]

  9. class Game_Actor
  10.   alias_method :consume_item_s20131209, :consume_item
  11.   def consume_item(item)
  12.     pay_item_cost(item)
  13.     consume_item_s20131209(item)
  14.   end
  15.   def pay_item_cost(item)
  16.     return unless $game_party.in_battle
  17.     note = item.note.downcase
  18.     self.hp -= $1.to_i if note =~ /cost.hp.(\d+)/
  19.     self.mp -= $1.to_i if note =~ /cost.mp.(\d+)/
  20.     self.tp -= $1.to_i if note =~ /cost.tp.(\d+)/
  21.   end
  22.   def enough_item_cost?(item)
  23.     note = item.note.downcase
  24.     return false if note =~ /cost.hp.(\d+)/ && hp <= $1.to_i
  25.     return false if note =~ /cost.mp.(\d+)/ && mp < $1.to_i
  26.     return false if note =~ /cost.tp.(\d+)/ && tp < $1.to_i
  27.     return true
  28.   end
  29. end

  30. class Window_BattleItem
  31.   def actor=(actor)
  32.     return if @actor == actor
  33.     @actor = actor
  34.     refresh
  35.     self.oy = 0
  36.   end
  37.   def enable?(item)
  38.     super && @actor.enough_item_cost?(item)
  39.   end
  40. end

  41. class Scene_Battle
  42.   alias_method :s20131209_command_item, :command_item
  43.   def command_item
  44.     @item_window.actor = BattleManager.actor
  45.     s20131209_command_item
  46.   end
  47. end
复制代码
   
回复

使用道具 举报

梦石
0
星屑
143
在线时间
347 小时
注册时间
2010-7-7
回帖
96
 楼主| 发表于 2013-12-9 20:53:16 | 显示全部楼层
Sion 发表于 2013-12-9 20:39
# 设置战斗物品消耗,物品备注中写:
# cost tp:100 消耗使用者 100 TP
# Cost_HP 200 消耗 200 HP

十分感谢!
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部