[XP] Map Combiner

Started by nathmatt, January 10, 2011, 03:12:34 pm

Previous topic - Next topic

nathmatt

January 10, 2011, 03:12:34 pm Last Edit: January 10, 2011, 08:25:10 pm by nathmatt
Map Combiner
Authors: Nathmatt
Version: 1.1
Type: utility
Key Term: Scripting Tool



Introduction

want to make a town or house creation system this script will take data from 1 map and add it to the map you are on


Features


  • The ability to add data from 1 map to the the one you are on




Screenshots

no screenshots needed


Demo

Demo


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Map Combiner by Nathmatt
# Version: 1.1
# Type: utility
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Game_Map
 
  alias town_setup setup
  def setup(map_id)
    if $game_system.town[map_id] != nil
      @map_id = map_id
      @map = $game_system.town[map_id]
      # set tile set information in opening instance variables
      tileset = $data_tilesets[@map.tileset_id]
      @tileset_name = tileset.tileset_name
      @autotile_names = tileset.autotile_names
      @panorama_name = tileset.panorama_name
      @panorama_hue = tileset.panorama_hue
      @fog_name = tileset.fog_name
      @fog_hue = tileset.fog_hue
      @fog_opacity = tileset.fog_opacity
      @fog_blend_type = tileset.fog_blend_type
      @fog_zoom = tileset.fog_zoom
      @fog_sx = tileset.fog_sx
      @fog_sy = tileset.fog_sy
      @battleback_name = tileset.battleback_name
      @passages = tileset.passages
      @priorities = tileset.priorities
      @terrain_tags = tileset.terrain_tags
      # Initialize displayed coordinates
      @display_x = 0
      @display_y = 0
      # Clear refresh request flag
      @need_refresh = false
      # Set map event data
      @events = {}
      for i in @map.events.keys
        @events[i] = Game_Event.new(@map_id, @map.events[i])
      end
      # Set common event data
      @common_events = {}
      for i in 1...$data_common_events.size
        @common_events[i] = Game_CommonEvent.new(i)
      end
      # Initialize all fog information
      @fog_ox = 0
      @fog_oy = 0
      @fog_tone = Tone.new(0, 0, 0, 0)
      @fog_tone_target = Tone.new(0, 0, 0, 0)
      @fog_tone_duration = 0
      @fog_opacity_duration = 0
      @fog_opacity_target = 0
      # Initialize scroll information
      @scroll_direction = 2
      @scroll_rest = 0
      @scroll_speed = 4
    else
      town_setup(map_id)
    end
  end
 
  def add_map(map_id)
    map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    map.events.each{|id,value|@map.events[@map.events.keys.size+1] = value}
    (0..map.height-1).each{|y|(0..map.width-1).each{|x|(0..3).each{|z|
    if map.data[x,y,z] != nil && map.data[x,y,z] != 0
      @map.data[x,y,z] = map.data[x,y,z]
    end}}}
    $game_system.town[@map_id] = @map
    setup(@map_id)
    $scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)
  end
 
end
   
class Game_System
  attr_accessor :town
  alias town_initialize initialize
  def initialize
    town_initialize
    @town = []
  end
end

class Scene_Map
  attr_accessor :spriteset
end



Instructions

just create at least 2 maps 1 is the main map the second is the data you want to add then use the script call
$game_map.add_map(map_id) map id the the map where the data being added is
also make sure the maps are the same size and using the same tileset


Compatibility

shouldn't have any comparability issues


Credits and Thanks


  • Nathmatt




Author's Notes

post any bugs or suggestions here
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


ForeverZer0

I don't understand what purpose this serves, and when exactly you would use it.

Your explanation is a little vague, and by looking at the script, it doesn't appear to do anything more than draw the data from one map on to the current one. How could that be used?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

nathmatt

January 10, 2011, 08:24:04 pm #2 Last Edit: January 10, 2011, 08:26:22 pm by nathmatt
to make something like what i made in my demo

update 1.1 fixed bug you would get if the script call was called while not in Scene_Map
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


[Luke]

Magnificent. If you don't understand how can it work, let me show you an example (taken from my current project):

Imagine an Blizz-ABS game where 3 factions battle for the control of the island. It's an RMX-OS game, so faction members are real players. They can conquer towns and villages and defend them, also with NPC guards. Once they conquer a town, they can pay their money to develop it - build barracks, weapon shop and hire more guards (that one is by eventing, but you can feel the idea). This script will let you setup the option of adding new structures to current map and that's very useful.

Examples in non-RMX-OS game: paying for woodcutters to cut down trees, hiring masons to build a bridge, estabilishing a siege camp to destroy a wall, building a wall or fence - just imagine. Now you can add or remove any part of the map in-game without making clone maps (valley without bridge, valley with bridge, etc.).

Wizered67

The only problem with using this with RMX-OS is that it will only work for the one player that bought the town. Unfortunately, making it apply for all players would probably be really complicated......

ForeverZer0

Quote from: [Luke] on January 12, 2011, 07:42:56 pm
Now you can add or remove any part of the map in-game without making clone maps (valley without bridge, valley with bridge, etc.).


You are still going to be making extra maps. You may has well just make them direct clones and change the maps.

It does give me an idea, though. I'm not gonna write it anytime soon, but a script that changes the specific tiles on the current map. A very similar effect would be given, with added houses, etc.


  • It would not require any extra maps, since you are merely modifing the map data for the current map.
  • The data could be saved easily by saving it to the Data/Map###.rxdata
  • All players would experience the effect.
  • All you would need to do would be to re-load the map and priority data, then re-draw the map.

I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

[Luke]

Quote from: ForeverZer0 on January 12, 2011, 08:32:11 pm
Quote from: [Luke] on January 12, 2011, 07:42:56 pm
Now you can add or remove any part of the map in-game without making clone maps (valley without bridge, valley with bridge, etc.).

You are still going to be making extra maps. You may has well just make them direct clones and change the maps.


There's a huge difference. Imagine there are 5 houses to add to the city. Making clone maps would require 2^5 = 32 maps with all combinations of houses added. Now you've got the point?

ForeverZer0

Yeah, dumbass I get the point, probably much better than you do. I'm saying its possible to do without ANY extra maps.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Poe

December 04, 2011, 09:42:04 am #8 Last Edit: December 04, 2011, 11:39:06 am by Poe
Quote from: ForeverZer0 on January 12, 2011, 08:32:11 pm
Quote from: [Luke] on January 12, 2011, 07:42:56 pm
Now you can add or remove any part of the map in-game without making clone maps (valley without bridge, valley with bridge, etc.).


You are still going to be making extra maps. You may has well just make them direct clones and change the maps.

It does give me an idea, though. I'm not gonna write it anytime soon, but a script that changes the specific tiles on the current map. A very similar effect would be given, with added houses, etc.


  • It would not require any extra maps, since you are merely modifing the map data for the current map.
  • The data could be saved easily by saving it to the Data/Map###.rxdata
  • All players would experience the effect.
  • All you would need to do would be to re-load the map and priority data, then re-draw the map.




i checked the viability of that and found out this can be very easily done.

$game_map.data[x,y,z]

where z is the layer (0-2)
holds the tile values for the currently active map, loaded from the data folder, and can be altered ingame.

to make the first layer of the second map tile the same as the first tile all you would need to do is put this in a script:

$game_map.data[1,0,0] = $game_map.data[0,0,0]
$game_map.need_refresh = true

or set it to any integer corresponding to a tile sprite, starting at 384 (numbers below are autotile parts).

i've only run a couple tests but it seems passability and priority gets transferred as well.

autotiles don't do their auto aligning however because every variation of the autotile has its own graphic that gets copied literally.
and it does not get saved either, when you exit the map the tiles will change back to the original setting. can't be that hard to work around that though.

(sorry if this was obvious to everyone already :))

Sin86

I spotted a compatibilty issue using Blizz ABS and Tons of Addons.


No error message appears but if you try to combind an object on one map with another, the object will appear but you'll walk right through it(where you set the x's to on the map options) regardless of how you set up that map object within the map . Without Blizz ABS and Tons, the object will act normal.


Also, on huge maps(this map is width 170, height is 118), if you try using the script, your character will disappear although you can still control him/her unless you go to an event that transfers you into another map, reenter the map you were in before and you'll reappear on it. Only to see that the new object is still walkthroughable.

Wizered67

December 19, 2011, 01:19:51 am #10 Last Edit: December 19, 2011, 01:26:06 am by Wizered67
I've done some testing with this as I plan to use it in my own game and had no problems with Blizz-ABS and Tons of Addons. I have no problems with walking through things. Try putting Blizz-ABS and Tons below the map combiner. However, I have found 1 minor thing with Blizz-ABS and 1 fairly major thing. If you have an enemy on the original map and then combine a map with it, the enemy's HP will be reset. The major thing is that if you have a Blizz-ABS enemy on a map you combine with the original, when it dies, everything goes crazy. I'm not sure how to describe it. You randomly level up multiple times and items start appearing everywhere.

Oh yeah, and as for your other problem with character dissapearing, it is because the camera isn't centered anymore on the player. I solved this by adding
$game_player.center($game_player.x, $game_player.y)

at the end of the "add_map" method.

Sin86

December 19, 2011, 11:47:19 am #11 Last Edit: December 19, 2011, 12:24:38 pm by Sin86
About the stuff about items appearing everywhere and you leveling up rapidly like you said. Well, lets say you make an enemy, it dies but has a switch(or self switch) on a 2nd page where it will never appear again. However, you want it to trigger only one thing. Not items or leveling up but all you want it to trigger is the script call to map combine whatever you want it to be. Will it still be doing the rapid level up and random items to appear too?

Also, I tried using the script call that is used to center the player but when I do. I get this error saying "SyntaxError occurred while running script". I set x and y to the respective coordinates too to where I want the player to be. I even have that script call at the end of the script call that uses the Map Combinder. Tried using it all in one script call, tried using it in 2 seperate script calls.

I even tried it without having to change the x and y but instead keeping x and y to be just x and y. No error there but the camera still goes off and eventually when I locate myself, I can still walk through the object that is suppose to appear. I even fixed the script order to have Map Combinder above Blizz ABS and Tons, still didn't fix it.

Wizered67

I'm not sure why you are having issues with walking through things still. It only did that when I had the wrong script order. As for the line I gave you, make sure it is in the right place. I put it in immediately after this line
$scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)


And as for the items appearing, it seems to do that no matter what, although if you have the enemy give no EXP the leveling thing no longer happens. To be honest, I have no idea how to fix this. It seems to be dropping all sorts of items, even when none should drop.

Sin86

December 19, 2011, 12:43:55 pm #13 Last Edit: December 19, 2011, 12:46:28 pm by Sin86
Script order I have done:




$game_map.add_map(30)

$scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)

$game_player.center($game_player.x, $game_player.y)


Tried making them all in one script call, tried making them in all 3 seperate script calls, tried replacing x and y to the appropiate coordinates, tried keeping x and y to be just x and y. I still get the same error saying "SyntaxError occurred while runing script".

Wizered67

Don't do it in a script call event. Add
$game_player.center($game_player.x, $game_player.y)


to the actual script immediately after the line

$scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)

Sin86

December 19, 2011, 01:28:13 pm #15 Last Edit: December 19, 2011, 01:32:28 pm by Sin86
Just tried it. I have the event saying:

$game_map.add_map(30)
(30 is the map id for the map that has the object thats suppose to be placed, everything else including the player takes place on map 29 and all the event has is the script call that calls out the script to use the combinder)

Now I use the script that has the x and y on it and I place it directly below the part with
$scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)
. No error message this time but I still get thrown off the camera like I was getting before. The combinder script is above all the other the other scripts but below all the default scripts.

Wizered67

I don't know why its not working. Here is the exact script I have in and it works fine as far as the camera issue goes.

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Map Combiner by Nathmatt
# Version: 1.0
# Type: utility
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Game_Map
 
  alias town_setup setup
  def setup(map_id)
    if $game_system.town[map_id] != nil
      @map_id = map_id
      @map = $game_system.town[map_id]
      # set tile set information in opening instance variables
      tileset = $data_tilesets[@map.tileset_id]
      @tileset_name = tileset.tileset_name
      @autotile_names = tileset.autotile_names
      @panorama_name = tileset.panorama_name
      @panorama_hue = tileset.panorama_hue
      @fog_name = tileset.fog_name
      @fog_hue = tileset.fog_hue
      @fog_opacity = tileset.fog_opacity
      @fog_blend_type = tileset.fog_blend_type
      @fog_zoom = tileset.fog_zoom
      @fog_sx = tileset.fog_sx
      @fog_sy = tileset.fog_sy
      @battleback_name = tileset.battleback_name
      @passages = tileset.passages
      @priorities = tileset.priorities
      @terrain_tags = tileset.terrain_tags
      # Initialize displayed coordinates
      @display_x = 0
      @display_y = 0
      # Clear refresh request flag
      @need_refresh = false
      # Set map event data
      @events = {}
      for i in @map.events.keys
        @events[i] = Game_Event.new(@map_id, @map.events[i])
      end
      # Set common event data
      @common_events = {}
      for i in 1...$data_common_events.size
        @common_events[i] = Game_CommonEvent.new(i)
      end
      # Initialize all fog information
      @fog_ox = 0
      @fog_oy = 0
      @fog_tone = Tone.new(0, 0, 0, 0)
      @fog_tone_target = Tone.new(0, 0, 0, 0)
      @fog_tone_duration = 0
      @fog_opacity_duration = 0
      @fog_opacity_target = 0
      # Initialize scroll information
      @scroll_direction = 2
      @scroll_rest = 0
      @scroll_speed = 4
    else
      town_setup(map_id)
    end
  end
 
  def add_map(map_id)
    map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    map.events.each{|id,value|@map.events[@map.events.keys.size+1] = value}
    (0..map.height-1).each{|y|(0..map.width-1).each{|x|(0..3).each{|z|
    if map.data[x,y,z] != nil && map.data[x,y,z] != 0
      @map.data[x,y,z] = map.data[x,y,z]
    end}}}
    $game_system.town[@map_id] = @map
    setup(@map_id)
    $scene.spriteset = Spriteset_Map.new if $scene.is_a?(Scene_Map)
    $game_player.center($game_player.x, $game_player.y)
    end
 
end
   
class Game_System
  attr_accessor :town
  alias town_initialize initialize
  def initialize
    town_initialize
    @town = []
  end
end

class Scene_Map
  attr_accessor :spriteset
end