查看: 12803|回复: 11

[RMVA发布] 物品得失提示脚本(150123 设置提示信息更灵活)

[复制链接]

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-10-3 20:22:37 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 taroxd 于 2015-12-17 15:34 编辑

论坛里有类似的脚本(比如 https://rpg.blue/thread-249678-1-1.html)。
这个脚本主要的不同之处是:
1. 使用内置的事件指令-显示文字来弹出这个窗口。
   因此可以轻松地设置窗口背景、显示位置。并且,弹出的窗口不会冻结画面,就和普通的显示文字指令完全相同。
   另一个好处是:提示的文本可以自由定义(在脚本的常数设置区域),其中可以使用显示文字的控制符!
2. 弹出的提示为实际得失的值。也就是说,如果某物品只持有两个,但事件指令要减少三个的话,那么弹出的得失提示为【失去物品 * 2】

对于预设的提示文字格式不满意的,可以修改 Taroxd::GainMessage.message 的返回值,自由选择想要的提示效果。


  1. #--------------------------------------------------------------------------
  2. # ● 得失物品提示
  3. #--------------------------------------------------------------------------

  4. module Taroxd end

  5. module Taroxd::GainMessage

  6.   # --- 设置 ---

  7.   # 信息格式

  8.   # 转义符:
  9.   # \name    代表物品名称 / 金钱单位
  10.   # \value   代表获得 / 失去的物品 / 金钱数量
  11.   # \icon    绘制物品 / 金钱的图标
  12.   # \action  代表“获得”或者“失去”。可在下面修改。
  13.   # 支持“显示文字”中的所有转义符。
  14.   ITEM_FORMAT  = '\action了 \name * \value'
  15.   GOLD_FORMAT  = '\action了 \value \name'
  16.   ACTION_GAIN  = '获得'
  17.   ACTION_LOSE  = '失去'
  18.   GOLD_ICON_INDEX = 361           # 金钱图标的索引

  19.   BACKGROUND   = 1                # 窗口背景(0/1/2)
  20.   POSITION     = 1                # 显示位置(0/1/2)

  21.   # 音效(不需要的话可以直接删去对应的行)
  22.   GAIN_GOLD_SE = 'Shop'           # 获得金钱
  23.   LOSE_GOLD_SE = 'Blow2'          # 失去金钱
  24.   GAIN_ITEM_SE = 'Item1'          # 获得物品
  25.   LOSE_ITEM_SE = LOSE_GOLD_SE     # 失去物品

  26.   # 设置功能是否启用。
  27.   # true:启用。
  28.   # false:不启用。
  29.   # $game_switches[开关ID]: 对应开关打开时。
  30.   def self.enabled?
  31.     true
  32.   end

  33.   # --- 设置结束 ---

  34.   # 显示提示信息。获得金钱时将 item 设为 nil。
  35.   def self.show(value, item)
  36.     @item = item
  37.     @value = value
  38.     $game_message.background = BACKGROUND
  39.     $game_message.position = POSITION
  40.     $game_message.add(message)
  41.     play_se
  42.   end

  43.   private

  44.   # 获取提示的消息
  45.   def self.message
  46.     if @item
  47.       format = ITEM_FORMAT
  48.       icon_index = @item.icon_index
  49.       name = @item.name
  50.     else
  51.       format = GOLD_FORMAT
  52.       icon_index = GOLD_ICON_INDEX
  53.       name = Vocab.currency_unit
  54.     end

  55.     # gsub: 以替换前的字符串为键,替换后内容为值的 hash。可以自由设置。
  56.     gsub = {
  57.       '\action' => @value > 0 ? ACTION_GAIN : ACTION_LOSE,
  58.       '\value'  => @value.abs,
  59.       '\icon'   => "\\I[#{icon_index}]",
  60.       '\name'   => name
  61.     }

  62.     format.gsub(Regexp.union(gsub.keys), gsub)
  63.   end

  64.   def self.play_se
  65.     const = :"#{@value > 0 ? 'GAIN' : 'LOSE'}_#{@item ? 'ITEM' : 'GOLD'}_SE"
  66.     se = const_defined?(const) && const_get(const)
  67.     Audio.se_play('Audio/SE/' + se) if se
  68.   end
  69. end

  70. class Game_Party < Game_Unit
  71.   # 获取道具总数(包括装备)
  72.   def item_number_with_equip(item)
  73.     members.inject(item_number(item)) { |a, e| a + e.equips.count(item) }
  74.   end
  75. end

  76. class Game_Interpreter

  77.   GainMessage = Taroxd::GainMessage

  78.   # 别名:不显示提示窗口的事件指令
  79.   alias_method :gain_gold_without_message,   :command_125
  80.   alias_method :gain_item_without_message,   :command_126
  81.   alias_method :gain_weapon_without_message, :command_127
  82.   alias_method :gain_armor_without_message,  :command_128

  83.   # 显示提示窗口
  84.   def show_gain_message(value, item = nil)
  85.     return if value.zero?
  86.     GainMessage.show(value, item)
  87.     wait_for_message
  88.   end

  89.   # 增减持有金钱
  90.   def command_125
  91.     return gain_gold_without_message unless GainMessage.enabled?
  92.     last_gold = $game_party.gold
  93.     gain_gold_without_message
  94.     show_gain_message($game_party.gold - last_gold)
  95.   end

  96.   # 增减物品
  97.   def command_126
  98.     return gain_item_without_message unless GainMessage.enabled?
  99.     item = $data_items[@params[0]]
  100.     last_num = $game_party.item_number(item)
  101.     gain_item_without_message
  102.     show_gain_message($game_party.item_number(item) - last_num, item)
  103.   end

  104.   # 增减武器
  105.   def command_127
  106.     return gain_weapon_without_message unless GainMessage.enabled?
  107.     item = $data_weapons[@params[0]]
  108.     last_num = $game_party.item_number_with_equip(item)
  109.     gain_weapon_without_message
  110.     value = $game_party.item_number_with_equip(item) - last_num
  111.     show_gain_message(value, item)
  112.   end

  113.   # 增减护甲
  114.   def command_128
  115.     return gain_armor_without_message unless GainMessage.enabled?
  116.     item = $data_armors[@params[0]]
  117.     last_num = $game_party.item_number_with_equip(item)
  118.     gain_armor_without_message
  119.     value = $game_party.item_number_with_equip(item) - last_num
  120.     show_gain_message(value, item)
  121.   end
  122. end
复制代码

评分

参与人数 1星屑 +9 收起 理由
VIPArcher + 9 塞糖

查看全部评分

无限の剣制

梦石
0
星屑
10460
在线时间
5019 小时
注册时间
2013-2-28
回帖
4942

开拓者贵宾

发表于 2014-10-3 20:33:29 | 显示全部楼层
怒抢沙发。
干脆一口气把command_311~318都写了吧

点评

酷爱写  发表于 2014-10-3 20:39
233333  发表于 2014-10-3 20:37
你要写的话我很欢迎哦~ 很简单的不是嘛[s]连基础设置都没用到[/s]  发表于 2014-10-3 20:34
回复

使用道具 举报

卑微的梦

梦石
0
星屑
547
在线时间
820 小时
注册时间
2013-2-23
回帖
1121

短篇九勇士组季军

发表于 2014-10-3 21:25:55 | 显示全部楼层
( ´ρ`)( ´_っ`)

点评

你们俩别一口一个笨弹啦!  发表于 2014-10-3 23:42
笨弹可以看看这个脚本。除了 54~58 行之外应该不难理解吧~  发表于 2014-10-3 21:42
笨蛋把command_311~318啥的都写了吧。  发表于 2014-10-3 21:32
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

 楼主| 发表于 2014-10-6 12:45:34 | 显示全部楼层
2014.10.06 更新:
  增强兼容性。功能不变。
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

 楼主| 发表于 2015-1-23 21:12:19 | 显示全部楼层
@fyqinpku
更新。再不会的话我就没辙了

点评

谢谢  发表于 2015-1-23 22:22
回复

使用道具 举报

梦石
0
星屑
3167
在线时间
1078 小时
注册时间
2015-1-13
回帖
316

开拓者

发表于 2015-1-23 22:51:39 | 显示全部楼层
在ITEM_FORMAT里插入\icon终于实现了期待的结果,感谢!
回复

使用道具 举报

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-1-13
回帖
21
发表于 2015-1-31 21:43:33 | 显示全部楼层
可以插入图标配合这个脚本吗?
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● 获取图标
  #--------------------------------------------------------------------------
  def get_icon
    self.note.split(/[\r\n]+/).each { |line|
      return $1 if line =~ /<ICON:(\S+)>/i
    }
    return nil
  end
  #--------------------------------------------------------------------------
  # ● 图标 index
  #--------------------------------------------------------------------------
  alias vip_20140928_icon_index icon_index
  def icon_index
    return get_icon if get_icon
    return vip_20140928_icon_index
  end
end
class Window_Base
  #--------------------------------------------------------------------------
  # ● 绘制图标
  #--------------------------------------------------------------------------
  alias vip_20140928_draw_icon draw_icon
  def draw_icon(icon_index, x, y, enabled = true)
    if icon_index.is_a?(Integer)
      vip_20140928_draw_icon(icon_index, x, y, enabled)
    else
      bitmap = Cache.load_bitmap("Graphics/Icons/", icon_index)
      rect = Rect.new(0, 0, bitmap.width, bitmap.height)
      contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    end
  end
end
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

 楼主| 发表于 2015-1-31 21:48:46 | 显示全部楼层
本帖最后由 taroxd 于 2015-1-31 21:50 编辑
xiaoxiyp 发表于 2015-1-31 21:43
可以插入图标配合这个脚本吗?
class RPG::BaseItem
  #------------------------------------------------ ...


只要该脚本支持显示文字的 '\I[图标编号]' 转义就行。其中,图标编号默认由 item.icon_index 获取。

如有需要可以修改 Taroxd::GainMessage.message 方法。
回复

使用道具 举报

梦石
0
星屑
176
在线时间
359 小时
注册时间
2015-3-29
回帖
104
发表于 2015-7-6 01:51:19 | 显示全部楼层
你好,请问可以帮忙制作一个XP版本的么

点评

我需要的是不冻结窗口的那种类型  发表于 2015-7-6 22:11
http://6rweb.sinaapp.com/articles/3091  发表于 2015-7-6 16:24
我不用XP  发表于 2015-7-6 07:19
在内存有限的时光里, 容纳未见的可能。
回复

使用道具 举报

梦石
0
星屑
3947
在线时间
1591 小时
注册时间
2006-5-5
回帖
2564
发表于 2015-7-6 14:41:33 | 显示全部楼层
Coder7447 发表于 2015-7-6 01:51
你好,请问可以帮忙制作一个XP版本的么

论坛上有啊
步兵中尉
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部