Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP/VX] Map Layers

Map Layers
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]
 
Wow! Dargor! Great script, very useful to anyone!
I always say that you're one of the scripters that I most admire. I had an error when I started the game, appeared a message saying that "Sea of Clouds" file cannot be found. It's clear that this has nothing to do with the script, is the map itself.
 

ikos

Member

It states that 'Sea of Clouds' is missing. Is this one of your custom graphics or would it be due to the fact there isn't a /Graphics folder?

EDIT: I just threw a graphic in to try it out. I must say, I am immensely impressed. Only issue is that I have no idea how the hell to use it. XD;
 
Thanks :)

'Sea of Clouds' is a VX panorama, so just open the map and remove it.

EDIT: I have updated the scripted and fixed an event misplacement bug with maps larger than 17x13.
 
@ikos
Just take a look at the demo, it's pretty easy to understand ;)

I have updated the script again. You can now modify any maps at any time!
To do so, I had to change a bit the add_map_layer method; It now requires 6 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.

Take care!
-Dargor
 
I know that there was a script like this for XP, but it required the SDK (and an old version at that) and that was its undoing. Maybe in the future you or someone else could make an XP version? Just a suggestion.
 
You guys are lucky today. I've made an XP Version of the script.
It works the same as the VX version with a little constraint. The tileset image of both the source and destination map must be the same.

Hope you like it!
-Dargor
 

EOG

Member

There is a bug. When you add layer where event start is or event position is during adding layer, the event is stacks inside non-plasable parts. My gues to fix is to delete event or reset it(if start pos of event is defferent).
 
That's not a bug, you have to watch where you add your layer. But I can make walking events go through an impassable location when they are on it.
 
I have reupdated the script to version 1.3. The only difference with 1.2 is that,whatever the maker you're using, you now need only 1 version of the script. If you're using XP, simply set the XP variable to True in the configuration module. That's all!

Take care
-Dargor
 
I dont know, if its fixed now, but when I looked at the code (dindt test it) I thought, that it copys all evnts, not only the ones in the rect doesnt it?
And when you talk to a cpoied event, which is not on Parallel Process or Auto Start, its Move Route doesnt work anymore D:
 
Hmm, in your notes it said : You can't remove layers from a map.

Does this mean, after we put a map layer, it cannot be removed? :crazy:
 
That's right. I'm trying to find a way to revert the changes but I doubt it will be doable. Unless I recreate the VX Tilemap class.

You see, there's only 2 map layers in VX and the script changes the Tile ID in these layers instead of creating another layer.
If i wanted to add real layers to the map, I would need to recreate the Tilemap class and expand it's possibilities...

Which I will probably do... :)
 
Couldn't you also use two Tilemaps instead of just one? I think Tilemap uses viewports, so you would be able to make one display above the other. This was an idea I had for making heavily layered cities in XP.
 
Good idea. I was about to say I can't because I don't have access to the tilemap data but that's not true.
Thanks to viewports and that: @tilemap.map_data = $game_map.data
I'll be able to make REAL layers :)

That's awesome. Thanks a lot for the idea!

*goes back to work*
 
OMFG, at first I was like, when am I going to use this?

Then I start to map again in VX To think that this made making cliffs actually bearable! This works really well if you use it to have things actually overlap in VX lol. Thanks Dargor!

#Idea

You can make the script look for a map with a name smiler to the original map [IE: Has the same name but with an extra character...] Then you can manually tile on this surface and it would be like adding a layer that's easy to map on top of the other.

Hmmm IDK to tired to think. I'll come back later with more ideas...
 

JoshC

Member

Ok I'm using RPG Maker XP, from what I understand I should be able to copy areas of a map rather than the whole map itself correct? However, I'm having difficulty doing this.

The script is set up and everything.

And the Event is just a basic character clicks do:

Text: Here you go.
Script: $game_map.add_map_layer(1, 2, \
: Rect.new(7,2,5,5), 0, 0, false)

What am I doing wrong?> I'm just copying a tent from map 2 to map 1, the tent is a 5x5 rectangle from coords (7,2)-(11,6)

{For those who aren't good with coord planes: that means the 5x5 square is taking up spaces (7,2)-(11,2); (7,3)-(11,3); (7,4)-(11,4); (7,5)-(11,5); (7,6)-(11,6)}
 
I really don't understand this, and the demo won't work on my computer. Could you explain how an event is supposed to be set up in order to use this?
 
riku, do you mean that the user can choose where to place the object?

You could prompt the user for a position before adding a tile from the source map to the destination map.

However, if you're just placing a few tiles, use an event and set the graphic for the event from the tileset.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top