查看: 1830|回复: 0

[RMVX发布] [渣型垃圾]事件脚本中变量/开关的简写

[复制链接]
梦石
0
星屑
660
在线时间
1286 小时
注册时间
2011-6-14
回帖
3949
发表于 2012-8-1 13:14:12 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 satgo1546 于 2012-8-2 18:29 编辑

首先,我选【VX发布】是因为我只在VX中测试过,别的不知道如何。
使用说明:脚本前面的注释!注释啊
啊对了,如有雷同,纯属凑巧!


这也没什么好截图的了。

要说明的是:
这样的调用都可以。
  1. p \v[1] # 数字形式
  2. p "\v[1]" # 字符串形式
复制代码
脚本:
[pre lang="ruby" line="1"]#==============================================================================
# ■ 开关/变量在事件中简写
#------------------------------------------------------------------------------
# 超级无用脚本,仅仅是不想打字而已。
# 使用方法:在可以输入脚本的地方输入\S[ID]表示ID号开关(true/false)
#           输入\V[ID]表示ID号变量(数字)
#==============================================================================

# 移动路线里面的脚本

class Game_Character
  # 重定义 move_type_custom
  alias mtc_swi move_type_custom
  def move_type_custom
    if @move_route.list[@move_route_index].code == 45 # 当执行内容是脚本时
      command.parameters[0].gsub!(/\\s\[(\d+)\]/i) do
        $game_switches[$1.to_i] ? "true" : "false"    # 替换开关
      end
      command.parameters[0].gsub!(/\\v\[(\d+)\]/i) do  # 替换变量
        $game_variables[$1.to_i].to_s
      end
    end
    mtc_swi # 刚刚加上去的,汗
  end
end

# 事件中条件分歧的脚本和脚本
# 偷懒了,条件分歧里的直接替换了……应该没什么脚本在里面
class Game_Interpreter
  def command_111
    result = false
    case @params[0]
    when 0  # 开关
      result = ($game_switches[@params[1]] == (@params[2] == 0))
    when 1  # 变量
      value1 = $game_variables[@params[1]]
      if @params[2] == 0
        value2 = @params[3]
      else
        value2 = $game_variables[@params[3]]
      end
      case @params[4]
      when 0  # 数值 1 等于 数值 2
        result = (value1 == value2)
      when 1  # 数值 1 大于或等于 数值 2
        result = (value1 >= value2)
      when 2  # 数值 1 小于等于 数值 2
        result = (value1 <= value2)
      when 3  # 数值 1 大于 数值 2
        result = (value1 > value2)
      when 4  # 数值 1 小于 数值 2
        result = (value1 < value2)
      when 5  # 数值 1 不等于 数值 2
        result = (value1 != value2)
      end
    when 2  # 独立开关
      if @original_event_id > 0
        key = [@map_id, @original_event_id, @params[1]]
        if @params[2] == 0
          result = ($game_self_switches[key] == true)
        else
          result = ($game_self_switches[key] != true)
        end
      end
    when 3  # 计时器
      if $game_system.timer_working
        sec = $game_system.timer / Graphics.frame_rate
        if @params[2] == 0
          result = (sec >= @params[1])
        else
          result = (sec <= @params[1])
        end
      end
    when 4  # 角色
      actor = $game_actors[@params[1]]
      if actor != nil
        case @params[2]
        when 0  # 角色在队伍中
          result = ($game_party.members.include?(actor))
        when 1  # 角色名称
          result = (actor.name == @params[3])
        when 2  # 角色已学会技能
          result = (actor.skill_learn?($data_skills[@params[3]]))
        when 3  # 角色已装备武器
          result = (actor.weapons.include?($data_weapons[@params[3]]))
        when 4  # 角色已装备武器
          result = (actor.armors.include?($data_armors[@params[3]]))
        when 5  # 状态
          result = (actor.state?(@params[3]))
        end
      end
    when 5  # 敌人
      enemy = $game_troop.members[@params[1]]
      if enemy != nil
        case @params[2]
        when 0  # 出现
          result = (enemy.exist?)
        when 1  # 状态为…
          result = (enemy.state?(@params[3]))
        end
      end
    when 6  # 角色
      character = get_character(@params[1])
      if character != nil
        result = (character.direction == @params[2])
      end
    when 7  # 金钱
      if @params[2] == 0
        result = ($game_party.gold >= @params[1])
      else
        result = ($game_party.gold <= @params[1])
      end
    when 8  # 物品
      result = $game_party.has_item?($data_items[@params[1]])
    when 9  # 武器
      result = $game_party.has_item?($data_weapons[@params[1]], @params[2])
    when 10  # 防具
      result = $game_party.has_item?($data_armors[@params[1]], @params[2])
    when 11  # 按钮
      result = Input.press?(@params[1])
    when 12  # 脚本
      #====================================================
      @params[1].gsub!(/\\s\[(\d+)\]/i) do  # 替换开关
        $game_switches[$1.to_i] ? "true" : "false"
      end
      @params[1].gsub!(/\\v\[(\d+)\]/i) do  # 替换变量
        $game_variables[$1.to_i].to_s
      end
      #====================================================
      result = eval(@params[1])
    when 13  # 交通工具
      result = ($game_player.vehicle_type == @params[1])
    end
    @branch[@indent] = result     # 判断结果保存在 hash 中
    if @branch[@indent] == true
      @branch.delete(@indent)
      return true
    end
    return command_skip
  end
  
  def command_355
    script = @list[@index].parameters[0] + "\n"
    loop do
      if @list[@index+1].code == 655 # 下一个事件指令在脚本2行以上的情况下
        script += @list[@index+1].parameters[0] + "\n"
      else
        break
      end
      @index += 1
    end
    script.gsub!(/\\s\[(\d+)\]/i) do  # 替换开关
      $game_switches[$1.to_i] ? "true" : "false"
    end
    script.gsub!(/\\v\[(\d+)\]/i) do  # 替换变量
      $game_variables[$1.to_i].to_s
    end
    eval(script)
    return true
  end
end
[/pre]

最后,发现貌似移动路线不行。改了一下~(其实我除了355code脚本测试过别的什么也没测试)
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部