查看: 2938|回复: 7

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

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

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

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

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

怎麽設計出數值輸入處理>如果進錢不少過數值>…………/如果少過數值則失敗?
我用了隨即獲得物品的脚本,但提示脚本好像對這無效,不會顯示隨即獲得的物品。
這是提示的脚本:
[pre lang="ruby"]#--------------------------------------------------------------------------
# ● 得失物品提示
#--------------------------------------------------------------------------

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
    @value = 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[/pre]
梦石
0
星屑
181
在线时间
68 小时
注册时间
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
星屑
39236
在线时间
11155 小时
注册时间
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.

在本版发帖返回顶部