Maplinks V1.2.1

Maplinks
Version: 1.2.1

Introduction

My maplinks script allows you to effortlessly tile maps together to create regions without any transfer events. The underlying Object_Table class provides a powerful platform for this script. This script can handle any combination of maps you throw at it.

Features
  • Seamlessly tiles multiple maps together into a world map, dungeon, cave etc.
  • No need for any transfer events between linked maps
  • Can tile differently sized and shaped maps together
  • Map dimensions are not restricted to multiples of a number
  • Only transfers when you try to leave the map
  • Will not transfer if current location or destination is impassable in the direction you are travelling
  • You can create multiple maplinks planes using the tables? z-axis
  • Optional looping of maplinks planes in each direction
  • Dynamically, enable and disable maps as your adventure progresses
  • Disable access to maps from certain directions
  • Option to have player sprite leave map before transferring
  • Easy to setup tables
  • New Object_Table class
  • Thoroughly tested
  • No noticeable impact on frame rate

Screenshots

Picture a screen fading from one map to another...

Demo
Not available.

Instructions

Installation Spoiler
  • Object Table script above main.
  • Install Maplinks script above main.
  • If not using the SDK; install the Interpreter Script Fix. It's included in the SDK.


To setup my maplinks script you need to edit its initialize method to reflect your project. For reference here's the demo's initialize.

Sample Initialize Spoiler
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias_method :icarus_maplinks_initialize, :initialize
 def initialize
   # The Usual
   icarus_maplinks_initialize
   # Create size array for tables
   # You can create multiple maplinked planes using the tables? z-axis
   size = [4, 4, 1]
   # Create map layout table for maplinks
   @maps = Object_Table.new(*size)
   @maps[0,0,0], @maps[1,0,0], @maps[2,0,0], @maps[3,0,0] =  1,  2,  3,  4
   @maps[0,1,0], @maps[1,1,0], @maps[2,1,0], @maps[3,1,0] =  5,  6,  6,  7
   @maps[0,2,0], @maps[1,2,0], @maps[2,2,0], @maps[3,2,0] =  8,  6,  6,  9
   @maps[0,3,0], @maps[1,3,0], @maps[2,3,0], @maps[3,3,0] = 10, 10, 10, 10
   @maps.negative_read = false
   # Create map size arrays
   sm, long, large = [20, 15], [80, 15], [40, 30]
   # Define the size of each map
   @sizes = Object_Table.new(*size)
   @sizes[0,0,0], @sizes[1,0,0], @sizes[2,0,0], @sizes[3,0,0] = sm, sm, sm, sm
   @sizes[0,1,0], @sizes[1,1,0],                @sizes[3,1,0] = sm, large,  sm
   @sizes[0,2,0],                               @sizes[3,2,0] = sm,         sm
   @sizes[0,3,0]                                              = long
   # Disable access to curtain maps by direction
   # Down = 1, Left = 2, Right = 4, Up = 8, All = 15
   # ie. Down + Right = 1 + 4 = 5
   @disabled = []
   # @disabled[map_id] = value
   @disabled[1] = 4
   # Enable looped maplinked planes by direction
   # Down = 1, Left = 2, Right = 4, Up = 8, All = 15
   # ie. Left + Right = 2 + 4 = 6
   @looped = []
   # @looped[plane z] = value
   @looped[0] = 15
   # Fade between maps
   @fade = true
   # Walk off map before transferring
   @leave_map = true
 end
Expand to see the code.

Configuration Spoiler
Customize table size array. The size array's elements become the x, y, and z coordinate maximums of the tables. Therefore, xmax and ymax should be the gridded size of the largest regional plane. The zmax should be set to the total number of different maplinked regions.
   # Create size array for tables [xmax, ymax, zmax]
   # You can index multiple maplinks regions on the tables? z-axis
   size = [4, 4, 1]
Expand to see the code.

Modify @maps table to reflect the map ids of your linked regions
   # Create map layout table for maplinks
   @maps = Object_Table.new(*size)
   @maps[0,0,0], @maps[1,0,0], @maps[2,0,0], @maps[3,0,0] =  1,  2,  3,  4
   @maps[0,1,0], @maps[1,1,0], @maps[2,1,0], @maps[3,1,0] =  5,  6,  6,  7
   @maps[0,2,0], @maps[1,2,0], @maps[2,2,0], @maps[3,2,0] =  8,  6,  6,  9
   @maps[0,3,0], @maps[1,3,0], @maps[2,3,0], @maps[3,3,0] = 10, 10, 10, 10
   @maps.negative_read = false
Expand to see the code.

Record the size of each map in the @sizes table
   # Create map size arrays
   sm, long, large = [20, 15], [80, 15], [40, 30]
   # Define the size of each map
   @sizes = Object_Table.new(*size)
   @sizes[0,0,0], @sizes[1,0,0], @sizes[2,0,0], @sizes[3,0,0] = sm, sm, sm, sm
   @sizes[0,1,0], @sizes[1,1,0],                @sizes[3,1,0] = sm, large,  sm
   @sizes[0,2,0],                               @sizes[3,2,0] = sm,         sm
   @sizes[0,3,0]                                              = long
Expand to see the code.

Optional: Disable access to curtain areas in your region
   # Disable access to curtain maps by direction
   # Down = 1, Left = 2, Right = 4, Up = 8, All = 15
   # ie. Down + Right = 1 + 4 = 5
   @disabled = []
   # @disabled[map_id] = value
   @disabled[1] = 4
Expand to see the code.

Optional: Loop curtain maplinked planes
   # Enable looped maplinked planes by direction
   # Down = 1, Left = 2, Right = 4, Up = 8, All = 15
   # ie. Left + Right = 2 + 4 = 6
   @looped = []
   # @looped[plane z] = value
   @looped[0] = 15
Expand to see the code.

Optional: Change miscellaneous settings
   # Fade between maps
   @fade = true
   # Walk off map before transferring
   @leave_map = true
Expand to see the code.


Compatibility

SDK compliant
Does not require the SDK
All edited methods are aliased with alias_method for compatibility and are automatically logged if the SDK is used
Aliases Game_Map(initialize, setup) and Game_Player(check_event_trigger_touch, update)

Credits and Thanks

Wachunga - Activating Maplinks when the player tries to leave the map; a feature of his Maplinks script.
G-man - Requesting the ability to have the player sprite leave the map before transferring.
Regimos - Major Bug Report (Save/Load Error)
Cheatking - Bug Report (Table Axis Error)
Busbuzz - Bug Report

Author's Notes

I've spent quite a while on this script so far and have already rewritten it twice. If you have any errors please post your edited initialize method and a screenshot of the error dialogue box.

Version Info Spoiler
Next Version: 1.3.0
Maps Folio V1.0.0 - Regional maps drawn up from maplinks data (world maps, dungeon maps etc.)

Current Version: 1.2.1 - October 25, 2007
Fixed map id 0 bug
Split Difference and Shift methods by x and y axis for faster processing

Version Log Spoiler
1.2.0 - October 23, 2007
Option to have looped regions where each edge of the region is connected to the opposite side
Option to have certain maps in a region partially disabled; with access on certain sides only
Completely rebuilt Object_Table class
Removed RGSS.Table

1.1.1 - October 3, 2007
Fixes save/load error in RGSS.Table and Object_Table

1.1.0 - September 22, 2007
Added option to have the player leave the map before transferring
Fixed and enhanced RGSS.Table and Object_Table
Replaced @disabled Object_Table with Array

1.0.1 - August 22, 2007
Changes @disabled table handling for multi-grid maps
Object_Table is now initialized with nil

1.0.0 - August 21, 2007
Original Release
Sounds good, wouldn't this cause a few bugs with some events and scripts?
It shouldn't cause any bugs; all edited methods aliased for compatibility. Additionally, since I used alias_method, the aliases are logged if the SDK is used. I've updated the compatibility section of my post to address your concerns.
Very useful, I may use it!
This looks great! Please update the thread when the demo is back up and running. I look forward to trying it out.
[QUOTE=samamanjaro;265529]Very useful, I may use it![/QUOTE]

[QUOTE=RomanMelnik;265741]This looks great! Please update the thread when the demo is back up and running. I look forward to trying it out.[/QUOTE]

Thank you both and sorry for the wait. The updated demo is up. Right now I'm working on creating regional maps from the maplinks data and bitmaps of each map.
So I'm curious would this work good with like handrawn maps? B\c thats what it sounds like to me. A nice feature to add would be like the player could walk off the map before teleporting.
[QUOTE=G-man;267721]So I'm curious would this work good with like handrawn maps? [/QUOTE]

The new Maps Folio addon I'm working on uses images stored in the Graphics/Maps folder. You can either draw them by hand or use Seph's Map Screenshot Maker to create them.
[QUOTE=G-man;267721]A nice feature to add would be like the player could walk off the map before teleporting.[/QUOTE]

Good idea, G-man. I'll add that option.
This is a very useful script. Good Work Icarus. It saves a lot of time and add a more confiable link between maps. But, honestly, i didn't get how to use it. How can i tell that map01 leads to maps02?
For reference...
[QUOTE=Icarus Featherfight;265072]
Sample Initialize Spoiler
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias_method :icarus_maplinks_initialize, :initialize
  def initialize
    # The Usual
    icarus_maplinks_initialize
    # Create size array for tables
    # You can create multiple maplinks planes using the tables? z-axis
    size = [4, 4, 2]
    # Create map layout table for maplinks
    @maps = Table.new(size)
    [COLOR=Green]
    @maps[0,0,0], @maps[1,0,0], @maps[2,0,0], @maps[3,0,0] =  1,  2,  3,  4
    @maps[0,1,0], @maps[1,1,0], @maps[2,1,0], @maps[3,1,0] =  5,  6,  6,  7
    @maps[0,2,0], @maps[1,2,0], @maps[2,2,0], @maps[3,2,0] =  8,  6,  6,  9
    @maps[0,3,0], @maps[1,3,0], @maps[2,3,0], @maps[3,3,0] = 10, 10, 10, 10
    [/COLOR]
    @maps.negitive_read = false
    # Create map size arrays
    sm, long, large = [20, 15], [80, 15], [40, 30]
    # Define the size of each map
    @sizes = Object_Table.new(size)
    @sizes[0,0,0], @sizes[1,0,0], @sizes[2,0,0], @sizes[3,0,0] = sm, sm, sm, sm
    @sizes[0,1,0], @sizes[1,1,0],                @sizes[3,1,0] = sm, large,  sm
    @sizes[0,2,0],                               @sizes[3,2,0] = sm,         sm
    @sizes[0,3,0]                                              = long
    # Disable access to curtain areas (@disabled[x, y[, z]] = true)
    @disabled = Object_Table.new(size)
    @fade = true
  end
Expand to see the code.
[/QUOTE]
In the above initialize configuration note the @maps table. It allows you to configure the layout of your maps.

In this case:
  • Map 1's right side leads to map 2 and its bottom to map 5
  • Map 6 connects to maps 5 and 6 on its left side
  • Map 10 fills the bottom of the region; bordering maps 6, 8 and 9
  • etc.

Hopefully that clears some things up, Arachus. When I have time I'll add more to the instructions section.
I kinda already understood that, right, but where do you get these numbers: @maps[0,0,0], @maps[1,0,0] (The numbers inside the brackets.)
The first two numbers are the x and y coordinates of the maps on the table. The final z value is used to distinguish between multiple regions of linked maps. For example, the world map, a town, dungeon, etc. I should have made that more clear.
Now that i read this carefully, i'm understanding it, Icarus. So, after @map array (or a multi-dimensional array) it's the reference to mapID from rmxp, right? @maps[0,0,0] = 1 refers to the tile 0,0,0 (is this 0 the Z position?) of the first mapID. Now, the @sizes array i'm still trying to understand. But, thanks for explain it again.
I've updated the Maplinks script to version 1.1.0 and it has finally been approved on the download manager.

New in version 1.1.0 - September 22, 2007
Added option to have the player leave the map before transferring.
Fixed and enhanced RGSS.Table and Object_Table.
Replaced @disabled Object_Table with Array.

I am still working on the Maps Folio addon and I'll release it when I have the time. Please see my first post for more information.
It's great, but can you provide instructions or something on how to make different map planes? And can you add a function, so you can program maps that you can only enter from one side (say you can enter from the right side, if you go to the top, bottom or left side you can't go to the map to the left of it)?

EDIT: I don't really care about the entering from one side anymore, but there's something else bothering me. For some reason, whenever I load an old save file and try to enter a new map, it goes error on me ("Script Maplinks line 251: Argument Error occured. Game_Map's @sizes table contains incorrect data and/or linked maps don't line up..." etc). But if I start a new game, it works fine... I don't want this to corrupt the saving system, so could you please fix this? (It's not just in my game, I tried it in your demo and it happens too.)
[QUOTE=Regimos;287880]For some reason, whenever I load an old save file and try to enter a new map, it goes error on me ("Script Maplinks line 251: Argument Error occured. Game_Map's @sizes table contains incorrect data and/or linked maps don't line up..." etc). But if I start a new game, it works fine... I don't want this to corrupt the saving system, so could you please fix this? (It's not just in my game, I tried it in your demo and it happens too.)[/QUOTE]

Thanks for pointing that out Regimos; it is quite an oversight. It seems my enhancements to the Table classes are not being marshaled properly; when the table is reloaded all its instance variables have been lost. It seems I'll have to edit the _dump and _load methods...

P.S.
Thanks for the suggestions, Regimos.
if i have any more than 4 maps i get this error.

Script 'RGSS.Table' Line 88: TypeError occurred.
cannot convert Array into Interger
[QUOTE=cheatking;288428]if i have any more than 4 maps i get this error.

Script 'RGSS.Table' Line 88: TypeError occurred.
cannot convert Array into Interger[/QUOTE]

Cheatking, please make sure you have the latest versions of all the components; that error is usually caused by a mismatch. Did you for instance copy and paste in parts of your old initialize into the new one? Would you please post your edited initialize. Additionally, when exactly does the error occur? In essence, please elaborate.
It comes up as soon as i click new game.

I copyed and pasted the scripts from your demo.

Content Hidden Spoiler
  def initialize
    # The Usual
    icarus_maplinks_initialize
    # Create size array for tables
    # You can create multiple maplinks planes using the tables’ z-axis
    size = [4, 2, 1]
    # Create map layout table for maplinks
    @maps = Table.new(*size)
    @maps[0,0,0], @maps[1,0,0], @maps[2,0,0], @maps[3,0,0], @maps[4,0,0], @maps[5,0,0], @maps[6,0,0], @maps[7,0,0] =  1,  2,  3,  4, 5, 6, 7, 8
    @maps.negitive_read = false
    # Create map size arrays
    sm, long, large = [50, 50], [80, 15], [40, 30]
    # Define the size of each map
    @sizes = Object_Table.new(*size)
    @sizes[0,0,0], @sizes[1,0,0], @sizes[2,0,0], @sizes[3,0,0], @maps[4,0,0], @maps[5,0,0], @maps[6,0,0], @maps[7,0,0] = sm, sm, sm, sm, sm, sm, sm, sm
    # Disable access to curtain maps (@disabled[map_id] = true)
    @disabled = []
    # Fade between maps
    @fade = true
    # Walk off map before transfering
    @leave_map = true
  end
Expand to see the code.
[QUOTE=cheatking;288505]
    @sizes[0,0,0], @sizes[1,0,0], @sizes[2,0,0], @sizes[3,0,0],[highlight] @maps[4,0,0], @maps[5,0,0], @maps[6,0,0], @maps[7,0,0][/highlight] = sm, sm, sm, sm, sm, sm, sm, sm
Expand to see the code.
[/QUOTE]

Could this be the problem, Cheatking? A simple typo. The @maps table can't hold arrays and hence your error occurs.
Yeah, your map system is really handy, but also picky when it comes to errors. By the way, are you working on the loading glitch?
Nifty script. I'll keep my eyes peeled for future updates. I've PMed you too, please read :)
Icarus Featherfight;288608 wrote:
Could this be the problem, Cheatking? A simple typo. The @maps table can't hold arrays and hence your error occurs.


Oops!

Yea, it was a typo.
[QUOTE=Regimos;288609]Yeah, your map system is really handy, but also picky when it comes to errors. By the way, are you working on the loading glitch?[/QUOTE]
Yes Regimos, I'm working on it. It fix is about halfway done.

[QUOTE=RPG Wizard;288615]Nifty script. I'll keep my eyes peeled for future updates. I've PMed you too, please read :)[/QUOTE]
I'm glad you like it. I'll be sure to PM you when it is bug free.

[QUOTE=cheatking;288648]Oops!

Yea, it was a typo.[/QUOTE]

Don't worry, it happens to the best of us.
Version 1.1.1 of my Maplinks script is up and running. The save & load bug Regimos pointed out has been squashed. The underlying table classes were not been marshaled properly. I'd just like to take this opportunity to thank everyone who has supported this script. Hopefully, this new version is to your liking.
I'm not sure if it's a script I'm using that's causing the glitch, but whenever I try to save or load it goes error:

"Script 'Object_Table' line 85: TypeError occurred.
Instance of IO needed"

The line 85 mentioned is:
  #-------------------------------------------------------------------------
  # * Name      : self._load
  #   Info      : Retores Object_Table from a marshaled string
  #   Author    : Icarus Featherfight
  #   Call Info : A String string
  #   Comments  : Restores @depth Table
  #-------------------------------------------------------------------------
  def self._load(string)
    array = string.split('~|~')
    table = super(array[0])
    [B]table.instance_variable_set(:@depth, Marshal.load(array[1]))[/B]
    return table
  end
Expand to see the code.


I'm also using Mog's Scene File (Save) script, and a prompt for overwrite function. Help would be much appreciated.
[QUOTE=Regimos;291333]I'm not sure if it's a script I'm using that's causing the glitch, but whenever I try to save or load it goes error:

"Script 'Object_Table' line 85: TypeError occurred.
Instance of IO needed"

I'm also using Mog's Scene File (Save) script, and a prompt for overwrite function. Help would be much appreciated.[/QUOTE]

Sorry to here that Regimos, it works fine in the demo. :-/ From what I've seen, appears the 'Prompt for Overwrite' script isn't causing the problem. However, since I cannot download Mog's demo, would you please PM me his script for reference?
All right, sending it. I tried placing Mog's script both above and below this one, but it doesn't work.

EDIT: It works now, thanks for your reply. Just some advice for anyone else using Mog's save file script along with this one, you need to delete all your old save files before trying to save a new one or the game will crash.
[QUOTE=Regimos;291430]It works now, thanks for your reply. Just some advice for anyone else using Mog's save file script along with this one, you need to delete all your old save files before trying to save a new one or the game will crash.[/QUOTE]

I'm glad we've worked that out. I'll be sure to add that reminder to the header.
Cool. I have another request, though. Could you make some maps loopable? I don't mean one map, but a whole array of them.. here's a diagram to make it clear.

Maps = X and O
Arrows = Loop here



So if you go left of map O, you would appear at the very right side of the array! This would be a great function to have in my game.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=27205