| 赞 | 6 |
| VIP | |
| 好人卡 | |
| 积分 | 44 |
| 经验 | |
| 最后登录 | 2026-2-6 |
| 在线时间 | 204 小时 |
- 梦石
- 0
- 星屑
- 4410
- 在线时间
- 204 小时
- 注册时间
- 2018-6-17
- 回帖
- 112
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 VIPArcher 于 2022-5-31 08:52 编辑
怎麽設計出數值輸入處理>如果進錢不少過數值>…………/如果少過數值則失敗?
我用了隨即獲得物品的脚本,但提示脚本好像對這無效,不會顯示隨即獲得的物品。
這是提示的脚本:
- #--------------------------------------------------------------------------
- # ● 得失物品提示
- #--------------------------------------------------------------------------
- module Taroxd end
- module Taroxd::GainMessage
- # --- 设置 ---
- # 信息格式
- # 转义符:
- # \name 代表物品名称 / 金钱单位
- # \value 代表获得 / 失去的物品 / 金钱数量
- # \icon 绘制物品 / 金钱的图标
- # \action 代表“获得”或者“失去”。可在下面修改。
- # 支持“显示文字”中的所有转义符。
- ITEM_FORMAT = '\action了 \name * \value'
- GOLD_FORMAT = '\action了 \value \name'
- ACTION_GAIN = '获得'
- ACTION_LOSE = '失去'
- GOLD_ICON_INDEX = 361 # 金钱图标的索引
- BACKGROUND = 1 # 窗口背景(0/1/2)
- POSITION = 1 # 显示位置(0/1/2)
- # 音效(不需要的话可以直接删去对应的行)
- GAIN_GOLD_SE = 'Shop' # 获得金钱
- LOSE_GOLD_SE = 'Blow2' # 失去金钱
- GAIN_ITEM_SE = 'Item1' # 获得物品
- LOSE_ITEM_SE = LOSE_GOLD_SE # 失去物品
- # 设置功能是否启用。
- # true:启用。
- # false:不启用。
- # $game_switches[开关ID]: 对应开关打开时。
- def self.enabled?
- true
- end
- # --- 设置结束 ---
- # 显示提示信息。获得金钱时将 item 设为 nil。
- def self.show(value, item)
- @item = item
- [url=home.php?mod=space&uid=2683223]@value[/url] = value
- $game_message.background = BACKGROUND
- $game_message.position = POSITION
- $game_message.add(message)
- play_se
- end
- private
- # 获取提示的消息
- def self.message
- if @item
- format = ITEM_FORMAT
- icon_index = @item.icon_index
- name = @item.name
- else
- format = GOLD_FORMAT
- icon_index = GOLD_ICON_INDEX
- name = Vocab.currency_unit
- end
- # gsub: 以替换前的字符串为键,替换后内容为值的 hash。可以自由设置。
- gsub = {
- '\action' => @value > 0 ? ACTION_GAIN : ACTION_LOSE,
- '\value' => @value.abs,
- '\icon' => "\\I[#{icon_index}]",
- '\name' => name
- }
- format.gsub(Regexp.union(gsub.keys), gsub)
- end
- def self.play_se
- const = :"#{@value > 0 ? 'GAIN' : 'LOSE'}_#{@item ? 'ITEM' : 'GOLD'}_SE"
- se = const_defined?(const) && const_get(const)
- Audio.se_play('Audio/SE/' + se) if se
- end
- end
- class Game_Party < Game_Unit
- # 获取道具总数(包括装备)
- def item_number_with_equip(item)
- members.inject(item_number(item)) { |a, e| a + e.equips.count(item) }
- end
- end
- class Game_Interpreter
- GainMessage = Taroxd::GainMessage
- # 别名:不显示提示窗口的事件指令
- alias_method :gain_gold_without_message, :command_125
- alias_method :gain_item_without_message, :command_126
- alias_method :gain_weapon_without_message, :command_127
- alias_method :gain_armor_without_message, :command_128
- # 显示提示窗口
- def show_gain_message(value, item = nil)
- return if value.zero?
- GainMessage.show(value, item)
- wait_for_message
- end
- # 增减持有金钱
- def command_125
- return gain_gold_without_message unless GainMessage.enabled?
- last_gold = $game_party.gold
- gain_gold_without_message
- show_gain_message($game_party.gold - last_gold)
- end
- # 增减物品
- def command_126
- return gain_item_without_message unless GainMessage.enabled?
- item = $data_items[@params[0]]
- last_num = $game_party.item_number(item)
- gain_item_without_message
- show_gain_message($game_party.item_number(item) - last_num, item)
- end
- # 增减武器
- def command_127
- return gain_weapon_without_message unless GainMessage.enabled?
- item = $data_weapons[@params[0]]
- last_num = $game_party.item_number_with_equip(item)
- gain_weapon_without_message
- value = $game_party.item_number_with_equip(item) - last_num
- show_gain_message(value, item)
- end
- # 增减护甲
- def command_128
- return gain_armor_without_message unless GainMessage.enabled?
- item = $data_armors[@params[0]]
- last_num = $game_party.item_number_with_equip(item)
- gain_armor_without_message
- value = $game_party.item_number_with_equip(item) - last_num
- show_gain_message(value, item)
- end
- end
- ————————————————————————————————————————————————————————————————————
- 然後這是隨即獲得物品的脚本:
- # ■ 获得随机物品
- #------------------------------------------------------------------------------
- # 使用方法:
- # 事件脚本gain_item(种类, 范围, 数量)
- # 种类
- # 物品 => "i" 或 "物品"
- # 武器 => "w" 或 "武器"
- # 防具 => "a" 或 "防具"
- # 范围
- # 可以是数组(Array)或范围(Range)
- #
- # 例
- # 从1~4号中随机选一个物品,获得1个 => gain_item("物品", 1..4 , 1)
- # 从1,10~20号中随机选一个武器,获得2个 => gain_item("武器", [1, 10..20] , 2)
- # 从1,3,5号中随机选一个防具,获得3个 => gain_item("防具", [1,3,5], 3)
- #==============================================================================
- class Game_Interpreter
-
- def gain_item(category, range_or_array, value)
- p range_or_array
- range_or_array = range_or_array.to_a if range_or_array.is_a?(Range)
- id = range_or_array.sample
- id = id.to_a.sample while !id.is_a?(Fixnum)
- p id
-
- p category
- case category
- when "物品" ,"i" then data = $data_items
- when "武器" ,"w" then data = $data_weapons
- when "防具" ,"a" then data = $data_armors
- else raise "在事件脚本中使用脚本指令gain_item时指定的种类不正确!"
- end
-
- $game_party.gain_item(data[id], value)
- end
- end
复制代码 |
|