查看: 2995|回复: 7

[已经过期] 金錢不少于輸入值

[复制链接]
梦石
0
星屑
4410
在线时间
204 小时
注册时间
2018-6-17
回帖
112
发表于 2019-3-19 15:17:54 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 VIPArcher 于 2022-5-31 08:52 编辑

怎麽設計出數值輸入處理>如果進錢不少過數值>…………/如果少過數值則失敗?
我用了隨即獲得物品的脚本,但提示脚本好像對這無效,不會顯示隨即獲得的物品。
這是提示的脚本:
  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.     [url=home.php?mod=space&uid=2683223]@value[/url] = 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
  123. ————————————————————————————————————————————————————————————————————
  124. 然後這是隨即獲得物品的脚本:
  125. # ■ 获得随机物品
  126. #------------------------------------------------------------------------------
  127. #  使用方法:
  128. #     事件脚本gain_item(种类, 范围, 数量)
  129. #   种类
  130. #     物品 => "i" 或 "物品"
  131. #     武器 => "w" 或 "武器"
  132. #     防具 => "a" 或 "防具"
  133. #   范围
  134. #     可以是数组(Array)或范围(Range)
  135. #  
  136. #   例
  137. #     从1~4号中随机选一个物品,获得1个          => gain_item("物品", 1..4   , 1)
  138. #     从1,10~20号中随机选一个武器,获得2个   => gain_item("武器", [1, 10..20]   , 2)
  139. #     从1,3,5号中随机选一个防具,获得3个        => gain_item("防具", [1,3,5], 3)
  140. #==============================================================================
  141. class Game_Interpreter

  142.   def gain_item(category, range_or_array, value)
  143.     p range_or_array
  144.     range_or_array = range_or_array.to_a if range_or_array.is_a?(Range)
  145.     id = range_or_array.sample
  146.     id = id.to_a.sample while !id.is_a?(Fixnum)
  147.     p id

  148.     p category
  149.     case category
  150.     when "物品" ,"i" then data = $data_items
  151.     when "武器" ,"w" then data = $data_weapons
  152.     when "防具" ,"a" then data = $data_armors
  153.     else raise "在事件脚本中使用脚本指令gain_item时指定的种类不正确!"
  154.     end

  155.     $game_party.gain_item(data[id], value)
  156.   end
  157. end
复制代码
梦石
0
星屑
231
在线时间
69 小时
注册时间
2019-1-14
回帖
11
发表于 2019-3-19 17:14:44 | 显示全部楼层
不知道有没有理解错。最简单粗暴的办法:
未标题-1.jpg
跑一遍这个公共事件,22号变量即为你拥有的金钱。
再把你输入的数值作为一个变量,与22号比较一下。

点评

噗用了这么多年才发现,变量确实可以直接代入金钱……多谢大佬  发表于 2019-3-19 18:40
变量不是可以代入金钱吗..  发表于 2019-3-19 17:30
回复

使用道具 举报

梦石
0
星屑
39336
在线时间
11161 小时
注册时间
2009-3-15
回帖
4768
发表于 2019-3-19 17:32:09 | 显示全部楼层
:LZ你问的什么鬼问题..无法理解..
回复

使用道具 举报

梦石
0
星屑
8177
在线时间
1873 小时
注册时间
2017-10-23
回帖
351
发表于 2019-3-19 17:56:55 | 显示全部楼层
重装机兵   报价买战车效果。

点评

……嗯?奇怪了,那個變量-持有金錢是怎麽做到的,  发表于 2019-3-19 20:38
回复 0 1

使用道具 举报

梦石
0
星屑
4410
在线时间
204 小时
注册时间
2018-6-17
回帖
112
 楼主| 发表于 2019-3-19 20:20:04 | 显示全部楼层
soulsaga 发表于 2019-3-19 17:32
:LZ你问的什么鬼问题..无法理解..

嗯……嘛,其他問題解決了。但隨即獲得物品提示無法解決,在圖書館的脚本都用過了,但是都沒用
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部