查看: 2065|回复: 9

[已经解决] 请问如何在Scene_ItemBase里进行武器、防具判断?

[复制链接]
梦石
0
星屑
2920
在线时间
713 小时
注册时间
2010-7-25
回帖
659

开拓者

发表于 2017-8-18 12:12:51 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 jianyulei 于 2017-8-18 12:34 编辑

我想在确定物品(determine_item)里加入使用武器或防具后触发公共事件的效果,p过 item ,在里面能找到武器的开头 #<RPG::weapon ,请问我该如何读取这段话并判断它?
梦石
0
星屑
39236
在线时间
11155 小时
注册时间
2009-3-15
回帖
4768
发表于 2017-8-18 12:15:09 | 显示全部楼层
if item.is_a?(RPG::Weapon)
if item.is_a?(RPG::Armor)

点评

你脚本怎么写的?  发表于 2017-8-18 12:40
不对,是weapon和Armor的报错  发表于 2017-8-18 12:30
用过了,一这样写就item NoMethhodError 报错  发表于 2017-8-18 12:29
回复

使用道具 举报

梦石
0
星屑
2920
在线时间
713 小时
注册时间
2010-7-25
回帖
659

开拓者

 楼主| 发表于 2017-8-18 12:45:46 | 显示全部楼层
本帖最后由 jianyulei 于 2017-8-18 12:50 编辑
soulsaga 发表于 2017-8-18 12:15
if item.is_a?(RPG::Weapon)
if item.is_a?(RPG::Armor)


[pre lang="ruby"]#encoding:utf-8
#==============================================================================
# ■ Scene_Item
#------------------------------------------------------------------------------
#  物品画面
#==============================================================================

class Scene_Item < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● 开始处理
  #--------------------------------------------------------------------------
  alias scene_item_start_lx start
  def start         #更新了
    if $game_switches[1] == true
       super
       create_help_window
       create_category1_window
       create_item1_window
    else   
       scene_item_start_lx
    end  
  end
  #--------------------------------------------------------------------------
  # ● 生成分类窗口
  #--------------------------------------------------------------------------
  def create_category1_window  #新的分类
    @category_window = Window_ItemCategory.new
    @category_window.viewport = @viewport
    @category_window.help_window = @help_window
    @category_window.y = @help_window.height
    @category_window.set_handler(:ok,     method(:on_category1_ok))
    @category_window.set_handler(:cancel, method(:return_scene))
  end
  #--------------------------------------------------------------------------
  # ● 生成物品窗口
  #--------------------------------------------------------------------------
  def create_item1_window   #新的物品
    wy = @category_window.y + @category_window.height
    wh = Graphics.height - wy
    @item_window = Window_ItemList.new(0, wy, Graphics.width, wh)
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item1_ok))
    @item_window.set_handler(:cancel, method(:on_item1_cancel))
    @category_window.item_window = @item_window
  end

  def on_category1_ok #新的分类“确定”
    @item_window.activate
    @item_window.select_last
  end
  def on_item1_ok #新的物品“确定”
    $game_party.last_item.object = item
    determine_item
  end
  def on_item1_cancel  #新的物品“取消”
    @item_window.unselect
    @category_window.activate
  end  
  
end

class Window_ItemList < Window_Selectable
  alias enable_hc? enable?
  def enable?(item)     #1号开关打开时所有装备都可以使用
    if $game_switches[1] == true
       return true
    else
       enable_hc?(item)
    end
  end  
end

class Scene_ItemBase < Scene_MenuBase
   
  alias determine_item_hc determine_item
  def determine_item   #确定物品
    if $game_switches[1] == true
      if item.note =~ /<合成 (\d+)>/
         $game_variables[3] += $1.to_i  
      end
           p item
       if item.is_a?(RPG::item) #道具判定
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(2);end
      if item.is_a?(RPG::weapon)  #武器判定
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(3);end
      if item.is_a?(RPG::Armor) #防具判定  
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(4);end
    else
       determine_item_hc
    end  
  end  
end  
[/pre]


只差判断了,这个脚本我是想做成装备使用特效、道具拆解、武器改造等多功能脚本来使用,因为是公共事件里写效果所以很灵活。

点评

原来要打开控制台..  发表于 2017-8-18 13:08
你可以用P么..我用的VA用P无效..何解..  发表于 2017-8-18 13:07
回复

使用道具 举报

梦石
0
星屑
39236
在线时间
11155 小时
注册时间
2009-3-15
回帖
4768
发表于 2017-8-18 13:16:49 | 显示全部楼层
jianyulei 发表于 2017-8-18 12:45
#encoding:utf-8
#==============================================================================
#  ...

[pre lang="ruby"]class Scene_ItemBase < Scene_MenuBase

  alias determine_item_hc determine_item
  def determine_item   #确定物品
    if $game_switches[1] == true
      if item.note =~ /<合成 (\d+)>/
      end
           #p item.is_a?(RPG::Weapon)
       if item.is_a?(RPG::Item) #道具判定
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(2);end
      if item.is_a?(RPG::Weapon)  #武器判定
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(3);end
      if item.is_a?(RPG::Armor) #防具判定  
        SceneManager.goto(Scene_Map);$game_temp.reserve_common_event(4);end
    else
       determine_item_hc
    end  
  end  
end[/pre]

测试通过..复制默认脚本的item.is_a?(RPG::Weapon)那些就可以了..不知你写错了什么..

点评

我知道我写错了什么了……武器防具的第一个字母没有大写……  发表于 2017-8-18 13:19

评分

参与人数 1星屑 +30 收起 理由
jianyulei + 30 认可答案

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部