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

Project1

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

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
4471
在线时间
1053 小时
注册时间
2013-3-28
帖子
390

开拓者

跳转到指定楼层
1
发表于 2019-7-29 10:57:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
比如在背包里可以登记某个物品到A键,然后在地图上按A键就可以使用该物品

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

2
发表于 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 网络脚本 *
回复 支持 反对

使用道具 举报

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

3
发表于 2019-8-10 16:17:23 | 只看该作者
本帖最后由 guoxiaomi 于 2019-8-10 16:20 编辑

凑合着用吧,这个脚本需要占一个变量、一个开关和一个公共事件,指定ID就行。
RUBY 代码复制
  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.  
  12. class Scene_Item
  13.   include Item_ShortCut
  14.   alias _item_shortcut_update_item update_item
  15.  
  16.   def update_item
  17.     if Input.trigger?(Select_Key)
  18.       # 获取物品窗口当前选中的物品数据
  19.       @item = @item_window.item
  20.       # 不使用物品的情况下
  21.       unless @item.is_a?(RPG::Item)
  22.         # 演奏冻结 SE
  23.         $game_system.se_play($data_system.buzzer_se)
  24.         return
  25.       end
  26.       # 不能使用的情况下
  27.       if !$game_party.item_can_use?(@item.id)
  28.         # 演奏冻结 SE
  29.         $game_system.se_play($data_system.buzzer_se)
  30.         return
  31.       end
  32.       # 演奏确定 SE
  33.       $game_system.se_play($data_system.decision_se)
  34.       # 标记并激活公共事件
  35.       item_id = $game_variables[Variable_ID]
  36.       if @item.id == item_id
  37.         $game_switches[Switches_ID] = false
  38.         $game_variables[Variable_ID] = 0
  39.       else
  40.         $game_switches[Switches_ID] = true
  41.         $game_variables[Variable_ID] = @item.id
  42.         # 准备公共事件
  43.         $data_common_events[CommonEvent_ID] ||= RPG::CommonEvent.new
  44.         event = $data_common_events[CommonEvent_ID]
  45.         if event.name != "_item_shortcut"
  46.           event.name = "_item_shortcut"
  47.           event.trigger = 2
  48.           event.switch_id = Switches_ID
  49.           event.list = [
  50.             RPG::EventCommand.new(355, 0, ["_item_shortcut_use_item"]),
  51.             RPG::EventCommand.new,
  52.           ]
  53.           $game_map.need_refresh = true
  54.         end
  55.       end
  56.     end
  57.     # 继续后面的判断
  58.     _item_shortcut_update_item
  59.   end
  60. end
  61.  
  62. class Interpreter
  63.   include Item_ShortCut
  64.  
  65.   def _item_shortcut_use_item
  66.     if !Input.trigger?(Use_Key)
  67.       return
  68.     end
  69.     if !$scene.is_a?(Scene_Map)
  70.       return
  71.     end
  72.     item_id = $game_variables[Variable_ID]
  73.     item = $data_items[item_id]
  74.     if !$game_party.item_can_use?(item.id)
  75.       # 演奏冻结 SE
  76.       $game_system.se_play($data_system.buzzer_se)
  77.       return
  78.     end
  79.     if item.scope > 3
  80.       if item.scope == 4 || item.scope == 6
  81.         $game_party.actors.each do |actor|
  82.           actor.item_effect(item)
  83.         end
  84.       else
  85.         # 给队伍第一个角色使用
  86.         $game_party.actors[0].item_effect(item)
  87.       end
  88.     end
  89.     if item.consumable
  90.       $game_party.lose_item(item.id, 1)
  91.     end
  92.     if item.common_event_id > 0
  93.       $game_temp.common_event_id = item.common_event_id
  94.     end
  95.     # 播放动画和设置冷却时间
  96.     $game_player.animation_id = Animation_ID
  97.     @wait_count = Cool_Down
  98.   end
  99. end

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

评分

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

查看全部评分

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-27 10:46

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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