by Dargor
Version 1.3
Introduction
At first, this script was an experiment but it turned out pretty well!
This script let you add "layers" on a map, using another map.
To be honest, it's not real layers, it's more like copy/pasting a part of a map on another map.
THis script is now compatible with both XP and VX! Use version 1.3 in the maker of your choice and simply set the XP variable to True/False in the configuration module. When True, the script will assume that you are using XP. When False, you're using VX.
Hope you like it!
Features
- Copy a source map and paste it on destination map
- You can specify a region of the source map to copy
- You can also copy events from that region of the source map
- Available for both XP and VX!
Demo
http://www.megaupload.com/?d=HFSSD1YZ
Script
[rgss]#==============================================================================
# ** Map Layers VX/XP
#------------------------------------------------------------------------------
# © Dargor, 2009
# 05/02/09
# Version 1.3
#------------------------------------------------------------------------------
# VERSION HISTORY:
# - 1.0 (17/01/09), Initial release
# - 1.1 (18/01/09), Event misplacement corrected with large maps
# - 1.2 (20/01/09), Can now modify any maps at any time
# - 1.3 (05/02/09), Now Compatible with RPGXP
#------------------------------------------------------------------------------
# INSTRUCTIONS:
# - Paste this script above Main and Below Materials
# - To add a new layer to the current map, use the following line of code:
# $game_map.add_map_layer(arguments)
# - The arguments:
# 1) Destination Map ID (Integer): The ID of the destination map.
# 2) Source Map ID (Integer): The ID of the source map to take tiles from.
# 3) Rect (Rect.new(x,y,width,height)) The "area" of the source map
# you want to apply on the destination map.
# 4) OX (Integer):
# 5) OY (Integer):
# The X/Y Offset of the area on the destination map. Starts at 0,0.
# 6) Events (Boolean, true/false):
# When true, copy the events from the source map to the
# destination map. It will Copy events that are within the
# source Rect only.
#------------------------------------------------------------------------------
# NOTES:
# - You can't remove layers from a map.
#==============================================================================
#==============================================================================
# ** Map Layers Configuration Module
#==============================================================================
module Map_Layers
# Using RPGXP?
XP = true
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_vx_map_alteration_game_map_initialize initialize
alias dargor_vx_map_alteration_game_map_setup setup
alias dargor_vx_map_alteration_game_map_refresh refresh
if !Map_Layers::XP
alias dargor_vx_map_alteration_game_map_setup_events setup_events
end
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :map_id
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@map_modified = {}
@map_new_data = {}
dargor_vx_map_alteration_game_map_initialize
end
#--------------------------------------------------------------------------
# * Setup
# map_id : map ID
#--------------------------------------------------------------------------
def setup(map_id)
# The usual
dargor_vx_map_alteration_game_map_setup(map_id)
# If the map has been modified
if @map_modified[map_id] && @map_new_data[map_id] != nil
# Load the modified map
@map = @map_new_data[@map_id]
# Recreate events and spriteset
setup_events
$scene.spriteset = Spriteset_Map.new
end
end
#--------------------------------------------------------------------------
# * Event Setup
#--------------------------------------------------------------------------
def setup_events
# If using XP, define "setup events"
if Map_Layers::XP
@events = {} # Map event
for i in @map.events.keys
@events = Game_Event.new(@map_id, @map.events)
end
@common_events = {} # Common event
for i in 1...$data_common_events.size
@common_events = Game_CommonEvent.new(i)
end
# If using VX, call the usual method
else
dargor_vx_map_alteration_game_map_setup_events
end
end
#--------------------------------------------------------------------------
# * Event Renewal
#--------------------------------------------------------------------------
def refresh_events
for i in @map.events.keys
next if @events.has_key?(i)
@events = Game_Event.new(@map_id, @map.events)
end
end
#--------------------------------------------------------------------------
# * Add Map Layer
# d_map_id : destination map ID
# s_map_id : source map ID
# rect : source map Rect to copy
# ox : X offset on destination map
# oy : Y offset on destination map
# events : Copy events that are within the source map Rect
#--------------------------------------------------------------------------
def add_map_layer(d_map_id, s_map_id, rect=Rect.new(0,0,$game_map.width, $game_map.height), ox=0, oy=0, events=false)
# Create map extention variable
ext = Map_Layers::XP ? 'rxdata' : 'rvdata'
# Create source and destionation map data
source_map = load_data(sprintf("Data/Map%03d.#{ext}", s_map_id))
if @map_modified[d_map_id]
dest_map = @map_new_data[d_map_id]
else
dest_map = load_data(sprintf("Data/Map%03d.#{ext}", d_map_id))
end
# Set "Map Modified" flag to true
@map_modified[d_map_id] = true
# Add Tiles to destination map
for x in rect.x...rect.width
for y in rect.y...rect.height
for z in [2, 1, 0]
tile_id = source_map.data[x, y, z]
dest_map.data[x+ox, y+oy, z] = tile_id if tile_id != 0
end
end
end
# Add Events to destination map
for i in source_map.events.keys
event = Game_Event.new(map_id, source_map.events)
if event.x.between?(rect.x, rect.width) && event.y.between?(rect.y, rect.height)
new_event = source_map.events.dup
new_event.x = event.x + ox
new_event.y = event.y + oy
dest_map.events[dest_map.events.size + i] = new_event
end
end
# Store new map data
@map_new_data[d_map_id] = dest_map
# If destination map is the current map
if @map_id == d_map_id
# Update Map data
@map = @map_new_data[@map_id]
# Recreate events and spriteset
refresh_events
$scene.spriteset = Spriteset_Map.new
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :spriteset
end
[/rgss]