Group: Member
Posts: 31
Type: Event Designer
RM Skill: Masterful
Demo: click here DOES NOT WORK ANY MORE. Kindly see the instructions and script below.
Instructions:
You have to name maps in a certain way, to make this work properly.
[-A-][-B-][-C-] [-D-][-E-] [-F-]
If your first map is layed out like above, the map names need to be as such:
[-A-] should be named 'Mapname [1 1 1]' [-B-] should be named 'Mapname [1 2 1]' [-C-] should be named 'Mapname [1 3 1]' [-D-] should be named 'Mapname [1 1 2]' [-E-] should be named 'Mapname [1 2 2]' [-F-] should be named 'Mapname [1 1 3]'
The format is:
Mapname [MapID MapX MapY]
Where:
Mapname: is anything you want to name the map, does not need to be consistent with other joining maps. MapID: is a number ID. This is so that squares from one set of maps don't show up on another map. MapX: The X position of the map. MapY: The Y position of the map.
If you don't want a map to show up (such as an interior map), just don't give it anything, such as:
'InteriorMap'
Nothing at all!
Refer to the demo if you need any more instruction.
The Script:
Place this in a script above main. It uses the Scene_Save/Load data methods so if you have another script that uses them (such as Near's ABS) make sure to place this script above them.
CODE
# Metroid Style Map Script v1.0 # By Prexus (special thanks to Minkoff and Astro_Mech) # [url="http://prexus.rmxponline.com"]http://prexus.rmxponline.com[/url] # All Rights Reserved
class String def find(s1, s2) escape_s1 = Regexp.escape(s1) escape_s2 = Regexp.escape(s2) regexp = Regexp.new("#{escape_s1}(.*)#{escape_s2}") return self.scan(regexp) end end
class BigMap attr_accessor :id attr_accessor :map_squares def initialize(id) @id = id @map_squares = [] end end
class MapSquare attr_accessor :x; attr_accessor :y; attr_accessor :bigmap_id; attr_accessor :located; def initialize(bigmap_id, x, y) @x = x; @y = y; @bigmap_id = bigmap_id; @located = false; end end
class Game_Map def get_info map_data = load_data("Data/MapInfos.rxdata")[@map_id] return map_data.name.find("[", "]").to_s end def locate_info(id) map_data = load_data("Data/MapInfos.rxdata")[id] return map_data.name.find("[", "]").to_s end end
class Scene_Title def command_new_game # Play decision SE $game_system.se_play($data_system.decision_se) # Stop BGM Audio.bgm_stop # Reset frame count for measuring play time Graphics.frame_count = 0 # Make each type of game object $game_temp = Game_Temp.new $game_system = Game_System.new $game_switches = Game_Switches.new $game_variables = Game_Variables.new $game_self_switches = Game_SelfSwitches.new $game_screen = Game_Screen.new $game_actors = Game_Actors.new $game_party = Game_Party.new $game_troop = Game_Troop.new $game_map = Game_Map.new $game_player = Game_Player.new
# New Lines # Set Up Maps
map_array = Dir.entries("Data") map_array.delete("..") map_array.delete(".") new_array = [] for row in map_array if row =~ /^Map...\.rxdata$/ new_array.push(row.scan(/^Map(...)\.rxdata$/)[0]) end end
$prx_bigmap = [] for i in 0...new_array.size map_infos = $game_map.locate_info(new_array[i][0].to_i).split id = map_infos[0].to_i if $prx_bigmap[id] == nil $prx_bigmap[id] = BigMap.new(id) end $prx_bigmap[id].map_squares.push(MapSquare.new(id, map_infos[1].to_i, map_infos[2].to_i)) end
# //
# Set up initial party $game_party.setup_starting_members # Set up initial map position $game_map.setup($data_system.start_map_id) # Move player to initial position $game_player.moveto($data_system.start_x, $data_system.start_y) # Refresh player $game_player.refresh # Run automatic change for BGM and BGS set with map $game_map.autoplay # Update map (run parallel process event) $game_map.update # Switch to map screen $scene = Scene_Map.new end end
class Scene_Save < Scene_File def write_save_data(file) # Make character data for drawing save file characters = [] for i in 0...$game_party.actors.size actor = $game_party.actors[i] characters.push([actor.character_name, actor.character_hue]) end # Write character data for drawing save file Marshal.dump(characters, file) # Wrire frame count for measuring play time Marshal.dump(Graphics.frame_count, file) # Increase save count by 1 $game_system.save_count += 1 # Save magic number # (A random value will be written each time saving with editor) $game_system.magic_number = $data_system.magic_number # Write each type of game object Marshal.dump($game_system, file) Marshal.dump($game_switches, file) Marshal.dump($game_variables, file) Marshal.dump($game_self_switches, file) Marshal.dump($game_screen, file) Marshal.dump($game_actors, file) Marshal.dump($game_party, file) Marshal.dump($game_troop, file) Marshal.dump($game_map, file) Marshal.dump($game_player, file) # New Line Marshal.dump($prx_bigmap, file) # // end end
class Scene_Load < Scene_File def read_save_data(file) # Read character data for drawing save file characters = Marshal.load(file) # Read frame count for measuring play time Graphics.frame_count = Marshal.load(file) # Read each type of game object $game_system = Marshal.load(file) $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_self_switches = Marshal.load(file) $game_screen = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_map = Marshal.load(file) $game_player = Marshal.load(file) # New Line $prx_bigmap = Marshal.load(file) # // # If magic number is different from when saving # (if editing was added with editor) if $game_system.magic_number != $data_system.magic_number # Load map $game_map.setup($game_map.map_id) $game_player.center($game_player.x, $game_player.y) end # Refresh party members $game_party.refresh end end
class Window_MiniMap < Window_Base def initialize(bigmap_id, map_x, map_y) @bigmap_id = bigmap_id @map_x = map_x @map_y = map_y super(0, 0, 640, 480) self.contents = Bitmap.new(width-32, height-32) self.opacity = 0 if @bigmap_id <= 0 or @bigmap_id == nil self.contents.clear else refresh end end def re_init(bigmap_id, map_x, map_y) @bigmap_id = bigmap_id @map_x = map_x @map_y = map_y if @bigmap_id.to_i <= 0 or @bigmap_id == nil self.contents.clear else refresh end end def refresh for i in 0...$prx_bigmap[@bigmap_id].map_squares.size if $prx_bigmap[@bigmap_id].map_squares[i].x == @map_x and $prx_bigmap[@bigmap_id].map_squares[i].y == @map_y $prx_bigmap[@bigmap_id].map_squares[i].located = true end end self.contents.clear for square in $prx_bigmap[@bigmap_id].map_squares self.contents.fill_rect(square.x * 16, square.y * 16, 16, 16, Color.new(0, 0, 0, 200)) if square.located self.contents.fill_rect(square.x * 16 + 1, square.y * 16 + 1, 14, 14, Color.new(255, 25, 255, 200)) else self.contents.fill_rect(square.x * 16 + 1, square.y * 16 + 1, 14, 14, Color.new(160, 160, 160, 200)) end if square.x == @map_x and square.y == @map_y self.contents.fill_rect(square.x * 16 + 4, square.y * 16 + 4, 8, 8, Color.new(0, 0, 0, 200)) self.contents.fill_rect(square.x * 16 + 5, square.y * 16 + 5, 6, 6, Color.new(200, 0, 0, 200)) end end end end
class Scene_Map def initialize @map = $game_map.get_info end alias minimap_main main def main map_vars = @map.split @map_window = Window_MiniMap.new(map_vars[0].to_i, map_vars[1].to_i, map_vars[2].to_i) minimap_main @map_window.dispose end alias minimap_update update def update minimap_update @map_window.update end alias minimap_transfer_player transfer_player def transfer_player minimap_transfer_player @map = $game_map.get_info map_vars = @map.split @map_window.re_init(map_vars[0].to_i, map_vars[1].to_i, map_vars[2].to_i) end end
Group: +Gold Member
Posts: 1,528
Type: Scripter
RM Skill: Undisclosed
Hey Funshutsu, I've updated the original post, I've fixed the explanation given ( the X and the Y were flipped ), fixed the code ( it would throw an error if there was a map without the tags ), and I've added the much requested screenshots
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.
Group: Local Mod
Posts: 904
Type: Scripter
RM Skill: Skilled
Rev Points: 120
Great! I was just working on a Script/Common_Event Metroid on RMXP (actually, I was working when I had time to...) This could be perfect, since I haven't put a minimap into it!
Thanks, Prexus, this is really a good idea! Thanks Night Runner too for the fixes:)
Jens
__________________________
"Thorns are the rose's sweetest essence..." -Jens of Zanicuud