查看: 3926|回复: 2

[已经解决] 如何在地图上快捷使用物品

[复制链接]
梦石
0
星屑
4657
在线时间
1069 小时
注册时间
2013-3-28
回帖
309

开拓者

发表于 2019-7-29 10:57:43 | 显示全部楼层 |阅读模式

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

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

×
比如在背包里可以登记某个物品到A键,然后在地图上按A键就可以使用该物品
梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2019-8-10 14:51:35 | 显示全部楼层
本帖最后由 guoxiaomi 于 2019-8-10 14:54 编辑

使用并行公共事件,在地图上使用就行,但是你可能需要考虑到物品的消耗、和目标选择:

  1. item = $data_items[物品ID]
  2. # 1. 使用物品
  3. $game_party.actors[队伍ID].item_effect(item)
  4. # 2. 使用的物品数减 1
  5. if item.consumable
  6.   $game_party.lose_item(item.id, 1)
  7. end
  8. # 3. 预约公共事件
  9. if item.common_event_id > 0
  10.   $game_temp.common_event_id = item.common_event_id
  11. end
复制代码

如果是全体队伍为目标,第 1 步应该是:
  1. $game_party.actors.each do |actor|
  2.   actor.item_effect(item)
  3. end
复制代码


音效和动画可以在公共事件里添加,注意你可能需要让并行事件等待 1 帧
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2019-8-10 16:17:23 | 显示全部楼层
本帖最后由 guoxiaomi 于 2019-8-10 16:20 编辑

凑合着用吧,这个脚本需要占一个变量、一个开关和一个公共事件,指定ID就行。
  1. # encoding: utf-8
  2. module Item_ShortCut
  3.   Variable_ID = 1
  4.   Switches_ID = 1
  5.   CommonEvent_ID = 1
  6.   Animation_ID = 3
  7.   Select_Key = Input::X
  8.   Use_Key = Input::X
  9.   Cool_Down = 40
  10. end

  11. class Scene_Item
  12.   include Item_ShortCut
  13.   alias _item_shortcut_update_item update_item

  14.   def update_item
  15.     if Input.trigger?(Select_Key)
  16.       # 获取物品窗口当前选中的物品数据
  17.       @item = @item_window.item
  18.       # 不使用物品的情况下
  19.       unless @item.is_a?(RPG::Item)
  20.         # 演奏冻结 SE
  21.         $game_system.se_play($data_system.buzzer_se)
  22.         return
  23.       end
  24.       # 不能使用的情况下
  25.       if !$game_party.item_can_use?(@item.id)
  26.         # 演奏冻结 SE
  27.         $game_system.se_play($data_system.buzzer_se)
  28.         return
  29.       end
  30.       # 演奏确定 SE
  31.       $game_system.se_play($data_system.decision_se)
  32.       # 标记并激活公共事件
  33.       item_id = $game_variables[Variable_ID]
  34.       if @item.id == item_id
  35.         $game_switches[Switches_ID] = false
  36.         $game_variables[Variable_ID] = 0
  37.       else
  38.         $game_switches[Switches_ID] = true
  39.         $game_variables[Variable_ID] = @item.id
  40.         # 准备公共事件
  41.         $data_common_events[CommonEvent_ID] ||= RPG::CommonEvent.new
  42.         event = $data_common_events[CommonEvent_ID]
  43.         if event.name != "_item_shortcut"
  44.           event.name = "_item_shortcut"
  45.           event.trigger = 2
  46.           event.switch_id = Switches_ID
  47.           event.list = [
  48.             RPG::EventCommand.new(355, 0, ["_item_shortcut_use_item"]),
  49.             RPG::EventCommand.new,
  50.           ]
  51.           $game_map.need_refresh = true
  52.         end
  53.       end
  54.     end
  55.     # 继续后面的判断
  56.     _item_shortcut_update_item
  57.   end
  58. end

  59. class Interpreter
  60.   include Item_ShortCut

  61.   def _item_shortcut_use_item
  62.     if !Input.trigger?(Use_Key)
  63.       return
  64.     end
  65.     if !$scene.is_a?(Scene_Map)
  66.       return
  67.     end
  68.     item_id = $game_variables[Variable_ID]
  69.     item = $data_items[item_id]
  70.     if !$game_party.item_can_use?(item.id)
  71.       # 演奏冻结 SE
  72.       $game_system.se_play($data_system.buzzer_se)
  73.       return
  74.     end
  75.     if item.scope > 3
  76.       if item.scope == 4 || item.scope == 6
  77.         $game_party.actors.each do |actor|
  78.           actor.item_effect(item)
  79.         end
  80.       else
  81.         # 给队伍第一个角色使用
  82.         $game_party.actors[0].item_effect(item)
  83.       end
  84.     end
  85.     if item.consumable
  86.       $game_party.lose_item(item.id, 1)
  87.     end
  88.     if item.common_event_id > 0
  89.       $game_temp.common_event_id = item.common_event_id
  90.     end
  91.     # 播放动画和设置冷却时间
  92.     $game_player.animation_id = Animation_ID
  93.     @wait_count = Cool_Down
  94.   end
  95. end
复制代码

最好配置一下公共事件为:并行处理,一行脚本,否则在读取新的存档的时候,需要重新绑定快捷键:
  1. _item_shortcut_use_item
复制代码

评分

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

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部