提供了基本的事件处理功能的脚本。
如需使用或转载时请不要删除版权声明信息,并注意标明作者。
#==============================================================================
# ■ 简单的事件呼叫与替换
#------------------------------------------------------------------------------
# By:六零道长 授权自由使用,转载请注明出处,使用时请标明作者。
#------------------------------------------------------------------------------
# 目前功能:
# 1. call_common_event(id) 呼叫指定编号的公共事件。
# 2. call_map_event(id, page) 呼叫指定事件的事件页
# 3. call_other_map_event(map, id, page) 呼叫某地图的某事件的事件页。
# 4. recover_event(map_id, event_id) 替换本事件为其它事件。
# 5. copy_map_event(map_id, event_id, x, y) 在运行时复制事件。
# 6. remove_map_event(event_id) 从地图彻底移除事件。
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# ● 呼叫指定编号的公共事件
#--------------------------------------------------------------------------
def call_common_event(id)
common_event = $data_common_events[id]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, same_map? ? @event_id : 0)
child.new_run
end
end
#--------------------------------------------------------------------------
# ● 呼叫指定事件的事件页
#--------------------------------------------------------------------------
def call_map_event(id, page)
common_event = $game_map.events[id].instance_variable_get(:@event).pages[page-1]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, id)
child.new_run
end
end
#--------------------------------------------------------------------------
# ● 呼叫指定事件的事件页 #自己执行
#--------------------------------------------------------------------------
def call_map_event_me(id, page)
common_event = $game_map.events[id].instance_variable_get(:@event).pages[page-1]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, @event_id)
child.new_run
end
end
#--------------------------------------------------------------------------
# ● 呼叫指定地图的指定事件中的事件页
#--------------------------------------------------------------------------
def call_other_map_event(map_id, id, page)
if map_id == @map_id
call_map_event(id, page)
else
map_filename = sprintf("Data/Map%03d.rvdata2", map_id)
event = load_data(map_filename).events[id]
common_event = event.pages[page-1]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, id)
child.new_run
end
end
end
#--------------------------------------------------------------------------
# ● 呼叫指定地图的指定事件中的事件页 #自己执行
#--------------------------------------------------------------------------
def call_other_map_event_me(map_id, id, page)
if map_id == @map_id
call_map_event(id, page)
else
map_filename = sprintf("Data/Map%03d.rvdata2", map_id)
event = load_data(map_filename).events[id]
common_event = event.pages[page-1]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, @event_id)
child.new_run
end
end
end
#--------------------------------------------------------------------------
# ● 呼叫指定地图的指定事件中的事件页 #指定事件执行
#--------------------------------------------------------------------------
def call_other_map_event_byid(map_id, id, page, event_id)
if map_id == @map_id
call_map_event(id, page)
else
map_filename = sprintf("Data/Map%03d.rvdata2", map_id)
event = load_data(map_filename).events[id]
common_event = event.pages[page-1]
if common_event
child = Game_Interpreter.new(@depth + 1)
child.setup(common_event.list, event_id)
child.new_run
end
end
end
#--------------------------------------------------------------------------
# ● 在运行时替换事件
#--------------------------------------------------------------------------
def recover_event(map_id, event_id)
map_filename = sprintf("Data/Map%03d.rvdata2", map_id)
event = load_data(map_filename).events[event_id]
event.id = @event_id
$game_map.events[@event_id].set_event(event)
$game_map.refresh_tile_events
end
#--------------------------------------------------------------------------
# ● 在运行时复制事件
#--------------------------------------------------------------------------
def copy_map_event(map_id, event_id, x, y)
map_filename = sprintf("Data/Map%03d.rvdata2", map_id)
event = load_data(map_filename).events[event_id]
index = 1
if $game_map.new_events
while($game_map.new_events[index])
index += 1
end
else
while($game_map.events[index])
index += 1
end
end
event.id = index
event = Game_Event.new($game_map.map_id, event)
event.moveto(x, y)
$game_map.new_events = $game_map.events.dup if !$game_map.new_events
$game_map.new_events[index] = event
SceneManager.scene.spriteset.push_characters_sprite(event)
$game_map.refresh_tile_events
return $game_map.new_events[index]
end
#--------------------------------------------------------------------------
# ● 在运行时移除事件
#--------------------------------------------------------------------------
def remove_map_event(event_id)
if $game_map.events[event_id]
SceneManager.scene.spriteset.delete_characters_sprite($game_map.events[event_id])
$game_map.events[event_id].erase
$game_map.events.delete(event_id)
$game_map.new_events.delete(event_id) if $game_map.new_events && $game_map.new_events[event_id]
$game_map.refresh_tile_events
end
end
#--------------------------------------------------------------------------
# ● 执行
#--------------------------------------------------------------------------
def new_run
wait_for_message
while @list[@index] do
execute_command
@index += 1
end
@fiber = nil
end
end
class Game_Event < Game_Character
attr_accessor :id
#--------------------------------------------------------------------------
# ● 设置事件内容
#--------------------------------------------------------------------------
def set_event(event)
@event = event
refresh
end
#--------------------------------------------------------------------------
# ● 判定事件页的条件是否符合
#--------------------------------------------------------------------------
def conditions_met?(page)
c = page.condition
if c.switch1_valid
return false unless $game_switches[c.switch1_id]
end
if c.switch2_valid
return false unless $game_switches[c.switch2_id]
end
if c.variable_valid
return false if $game_variables[c.variable_id] < c.variable_value
end
if c.self_switch_valid
key = [@map_id, @id, c.self_switch_ch]
return false if $game_self_switches[key] != true
end
if c.item_valid
item = $data_items[c.item_id]
return false unless $game_party.has_item?(item)
end
if c.actor_valid
actor = $game_actors[c.actor_id]
return false unless $game_party.members.include?(actor)
end
return true
end
end
class Game_Map
attr_accessor :new_events
alias siz_doevents_update_events update_events
def update_events
if @new_events != nil
@events = @new_events
@new_events = nil
end
siz_doevents_update_events
end
end
class Scene_Map
#--------------------------------------------------------------------------
# ● 返回图块组
#--------------------------------------------------------------------------
attr_reader :spriteset
end
class Spriteset_Map
#--------------------------------------------------------------------------
# ● 添加人物精灵
#--------------------------------------------------------------------------
def push_characters_sprite(event)
@character_sprites.push(Sprite_Character.new(@viewport1, event))
end
#--------------------------------------------------------------------------
# ● 删除人物精灵
#--------------------------------------------------------------------------
def delete_characters_sprite(event)
@character_sprites.each {|sprite|
if sprite.character == event
@character_sprites.delete(sprite)
sprite.dispose
return
end
}
end
end