查看: 3292|回复: 6

[已经解决] 转职道具

[复制链接]
梦石
0
星屑
2245
在线时间
1015 小时
注册时间
2015-10-17
回帖
1077
发表于 2019-2-10 22:06:34 | 显示全部楼层 |阅读模式

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

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

×
下面这个脚本是道具加上备注转职的,问下要是加些条件转职能实现吗,例如到一定等级才能使用这个道具转职
或者只有特定的角色使用才能转职,或者是某种职业的前提下用该道具才能转职
知道的告诉下,谢谢

[pre lang="ruby"]
class RPG::Item
  def transfer_index
    /<TRANSFER\s*(\d+)>/ =~ note ? $1.to_i : 0
  end
end


class Scene_ItemBase
  
  #--------------------------------------------------------------------------
  # ● 对角色使用物品
  #--------------------------------------------------------------------------
  def use_item_to_actors
    item_target_actors.each do |target|
      item.repeats.times {
        target.item_apply(user, item)
        use_transfer_item(target, item.transfer_index) if item.transfer_index > 0
      }
    end
  end
  
  def use_transfer_item(user, index)
    user.change_class(index, true)
  end
  
end[/pre]
梦石
10
星屑
39550
在线时间
1919 小时
注册时间
2010-11-14
回帖
3214

R考场第七期纪念奖

发表于 2019-2-11 00:28:50 | 显示全部楼层
在原脚本下面插入这个脚本
[pre lang="ruby"]#  使用方法
#  物品备注中写<condition>xxx</condition> 支持多行
#  用user代表使用者,s[n]和v[n]分别代表n号开关和变量
#
#  例 <condition>user.level > 9</condition> # 使用者等级大于9才能用
#     <condition>s[1] && v[1] > 5</condition> # 1号开关开启且1号变量大于5才能用
#     其他用法参考伤害公式

class Game_Actor
  #--------------------------------------------------------------------------
  # ● 技能/物品的应用测试
  #    如果使用目标的 HP 或者 MP 全满时,禁止使用恢复道具。
  #--------------------------------------------------------------------------
  alias item_test_for_class_transfer item_test
  def item_test(user, item)
    if item.transfer_index != 0
      return false unless item.transfer_ok?(self)
    end
    item_test_for_class_transfer(user, item)
  end
end

class RPG::Item
  def transfer_ok?(user)
    s = $game_switches
    v = $game_variables
    self.note =~ /<condition>((?:.\s?)+)<\/condition>/mi ? eval($1) : true
  end
end

[/pre]

具体用法见注释及范例。
Project1.zip (1.43 MB, 下载次数: 75)

点评

关于楼主需要的条件,这里提供几个思路。把n换成对应的数字。①user.level > n ②user == $game_actors[n] ③user.class_id == n  发表于 2019-2-11 00:31

评分

参与人数 2星屑 +40 赞 +1 收起 理由
VIPArcher + 40 认可答案
fjm + 1 认可答案

查看全部评分

用头画头像,用脚写脚本
回复

使用道具 举报

梦石
0
星屑
2245
在线时间
1015 小时
注册时间
2015-10-17
回帖
1077
 楼主| 发表于 2019-2-11 12:21:41 | 显示全部楼层
KB.Driver 发表于 2019-2-11 00:28
在原脚本下面插入这个脚本
#  使用方法
#  物品备注中写xxx 支持多行

非常感谢,可以用了
回复

使用道具 举报

梦石
0
星屑
2245
在线时间
1015 小时
注册时间
2015-10-17
回帖
1077
 楼主| 发表于 2019-2-11 13:56:22 | 显示全部楼层
KB.Driver 发表于 2019-2-11 00:28
在原脚本下面插入这个脚本
#  使用方法
#  物品备注中写xxx 支持多行

刚才试了下战斗的时候,放全体回复技能会报错,这个可以解决吗
回复

使用道具 举报

梦石
10
星屑
39550
在线时间
1919 小时
注册时间
2010-11-14
回帖
3214

R考场第七期纪念奖

发表于 2019-2-11 14:12:50 | 显示全部楼层
本帖最后由 KB.Driver 于 2019-2-11 14:25 编辑
fjm 发表于 2019-2-11 13:56
刚才试了下战斗的时候,放全体回复技能会报错,这个可以解决吗


麻烦截图发一下报错的窗口,如果有完整工程最好。
不过我大致猜到了,应该是因为RPG::Skill没有定义transfer_index方法。
你把范例工程里的222脚本换成这个

[pre lang="ruby"]#  使用方法
#  物品备注中写<condition>xxx</condition> 支持多行
#  用user代表使用者,s[n]和v[n]分别代表n号开关和变量
#
#  例 <condition>user.level > 9</condition> # 使用者等级大于9才能用
#     <condition>s[1] && v[1] > 5</condition> # 1号开关开启且1号变量大于5才能用
#     其他用法参考伤害公式

class Game_Actor
  #--------------------------------------------------------------------------
  # ● 技能/物品的应用测试
  #    如果使用目标的 HP 或者 MP 全满时,禁止使用恢复道具。
  #--------------------------------------------------------------------------
  alias item_test_for_class_transfer item_test
  def item_test(user, item)
    if item.is_a?(RPG::Item) && item.transfer_index != 0
      return false unless item.transfer_ok?(self)
    end
    item_test_for_class_transfer(user, item)
  end
end

class RPG::Item
  def transfer_ok?(user)
    s = $game_switches
    v = $game_variables
    self.note =~ /<condition>((?:.\s?)+)<\/condition>/mi ? eval($1) : true
  end
end
[/pre]

另外,好像发现这个只对菜单中使用物品有效。
你把转职道具设置成只有菜单能用就没问题了。
用头画头像,用脚写脚本
回复

使用道具 举报

梦石
0
星屑
2245
在线时间
1015 小时
注册时间
2015-10-17
回帖
1077
 楼主| 发表于 2019-2-11 14:31:23 | 显示全部楼层
KB.Driver 发表于 2019-2-11 14:12
麻烦截图发一下报错的窗口,如果有完整工程最好。
不过我大致猜到了,应该是因为RPG::Skill没有定义trans ...

非常感谢,现在战斗时没问题了
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部