可以在事件中直接使用对应的变量编号达成独立变量的效果。
由于修改了默认的存档内容,与现有游戏存档不兼容。
与大部分同样修改了存档内容的脚本同时使用可能会产生意料之外的情况。
如需使用或转载时请不要删除版权声明信息,并注意标明作者。
#==============================================================================
# ■ 独立变量 5.1 By:六零道长
#------------------------------------------------------------------------------
# 本脚本由六零道长编写,授权自由使用,转载请写明出处。
# ※ 中途插入时请注意存档不兼容。(存档方式现在没有覆盖了)
#==============================================================================
#------------------------------------------------------------------------------
# 【常量设定】
#------------------------------------------------------------------------------
Self_Var = 5 #改成你需要的变量号
#------------------------------------------------------------------------------
class Game_SelfVariables
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize
@data = {}
end
#--------------------------------------------------------------------------
# ● 获取变量
#--------------------------------------------------------------------------
def [](key)
@data[key] || 0
end
#--------------------------------------------------------------------------
# ● 设置变量
#--------------------------------------------------------------------------
def []=(key, value)
@data[key] = value
on_change
end
#--------------------------------------------------------------------------
# ● 设置变量时的处理
#--------------------------------------------------------------------------
def on_change
$game_map.need_refresh = true
end
end
class Game_Event
#--------------------------------------------------------------------------
# ● 在事件中的初始化
#--------------------------------------------------------------------------
alias shige_didi_initialize initialize
def initialize(map_id, event)
@map_id = map_id
@event = event
$game_variables[Self_Var] = 99999999
shige_didi_initialize(map_id, event)
end
#--------------------------------------------------------------------------
# ● 调整事件页出现条件
#--------------------------------------------------------------------------
alias didide_conditions_met? conditions_met?
def conditions_met?(page)
c = page.condition
if c.variable_valid
if c.variable_id == Self_Var
return false if $game_self_variables && $game_self_variables[[@map_id, @id, 0]] < c.variable_value
end
end
return didide_conditions_met?(page)
end
end
class Game_Interpreter
#--------------------------------------------------------------------------
# ● 调整事件指令中条件分歧
#--------------------------------------------------------------------------
alias old_command_111 command_111
def command_111
if @params[1] == Self_Var && @params[0] == 1
result = false
case @params[0]
when 1 # 变量
value1 = $game_self_variables[[@map_id, @event_id, 0]]
if @params[2] == 0
value2 = @params[3]
else
value2 = $game_variables[@params[3]]
end
case @params[4]
when 0 # 等于
result = (value1 == value2)
when 1 # 以上
result = (value1 >= value2)
when 2 # 以下
result = (value1 <= value2)
when 3 # 大于
result = (value1 > value2)
when 4 # 小于
result = (value1 < value2)
when 5 # 不等于
result = (value1 != value2)
end
end
@branch[@indent] = result
command_skip if !@branch[@indent]
else
old_command_111
end
end
#--------------------------------------------------------------------------
# ● 调整事件指令中变量操作
#--------------------------------------------------------------------------
def command_122
value = 0
case @params[3] # 操作方式
when 0 # 常量
value = @params[4]
when 1 # 变量
value = $game_variables[@params[4]]
when 2 # 随机数
value = @params[4] + rand(@params[5] - @params[4] + 1)
when 3 # 游戏数据
value = game_data_operand(@params[4], @params[5], @params[6])
when 4 # 脚本
value = eval(@params[4])
end
(@params[0]..@params[1]).each do |i|
if i == Self_Var
operate_self_variable([@map_id, @event_id, 0], @params[2], value)
else
operate_variable(i, @params[2], value)
end
end
end
#--------------------------------------------------------------------------
# ● 操作变量
#--------------------------------------------------------------------------
def operate_self_variable(variable_id, operation_type, value)
begin
case operation_type
when 0 # 代入
$game_self_variables[variable_id] = value
when 1 # 加法
$game_self_variables[variable_id] += value
when 2 # 减法
$game_self_variables[variable_id] -= value
when 3 # 乘法
$game_self_variables[variable_id] *= value
when 4 # 除法
$game_self_variables[variable_id] /= value
when 5 # 取余
$game_self_variables[variable_id] %= value
end
rescue
$game_self_variables[variable_id] = 0
end
end
end
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias old_start start
def start
old_start
$game_self_variables = Game_SelfVariables.new
end
end
class << DataManager
#--------------------------------------------------------------------------
# ● 添加独立变量初始化
#--------------------------------------------------------------------------
alias create_game_objects_self_variables create_game_objects
def create_game_objects
create_game_objects_self_variables
$game_self_variables = Game_SelfVariables.new
end
end
class << DataManager
#--------------------------------------------------------------------------
# ● 存档内容更改
#--------------------------------------------------------------------------
alias make_save_contents_self_variables make_save_contents
def make_save_contents
contents = make_save_contents_self_variables
contents[:self_variables] = $game_self_variables
contents
end
#--------------------------------------------------------------------------
# ● 读档内容更改
#--------------------------------------------------------------------------
alias extract_save_contents_self_variables extract_save_contents
def extract_save_contents(contents)
extract_save_contents_self_variables(contents)
$game_self_variables = contents[:self_variables]
end
end