Introduction
This script allows the user to allow the contents of their maps retain their settings prior to exiting or teleporting. This means that events that have moved on a map, or have changed their graphics through a simple self-switch, do not reset if the player leaves the map and later returns.
Screenshots
Yeeeaaahhhhh.... no. Nothing visible for a screenie.
Script
Here there be Dragons!
Code:
#==============================================================================
# ** Dynamic Maps Expanded
#------------------------------------------------------------------------------
# Expanded version by DerVVulfman
# Version 1.5
# 07-05-2021 (MM/DD/YYYY)
# RGSS / RPGMaker XP
#==============================================================================
# Original Version by Near Fantastica - September 5, 2005
# * First Revision by Wachunga - November 7, 2005
# * Wachunga's initial work modified it for use with other Game_Map edits
# while replacing global values with cleaner instance variable usage.
#==============================================================================
#
# This script allows the user to allow the contents of their maps retain
# their settings prior to exiting or teleporting. This means that events
# that have moved on a map, or have changed their graphics through a simple
# self-switch, do not reset if the player leaves the map and later returns.
#
# * Revisions by DerVVulfman
# - Stores the saved 'dynamic maps' values in with the save games. The
# original version did have issues if switching between saves.
# - Added compatability for Big Maps (by DerVVulfman)
# - New commands to clear Dynamic Map data
# . clear_current_dynamic_map(map_id)
# . clear_all_dynamic_maps
# - Ability to specify maps using or are ignored by the system
#
#
#==============================================================================
#
# Credits and Thanks:
#
# Credits definitely to Near Fantastica for the initial work and Wachunga
# for his edit to make Near's original work more compliant with other map
# scripts. And lastly, credit to Melana for a request to clear map data,
# and in detection of a logic error involving ignored maps.
#
#==============================================================================
#
# Terms of Use:
#
# Free for use, even in commercial projects. Due credit is required, not
# only for me but for Near Fantastica, Wachunga and Melana.
#
#==============================================================================
module Dynamic
# List of Maps (by their IDs) that are ignored by the system
# Set to nil if all maps permitted
#
IGNORED_MAP_IDs = [1]
# List of Maps (by their IDs) that alone use the system
# Set to nil if all maps permitted
#
REQUIRED_MAP_IDs = nil
end
#==============================================================================
# ** BigMaps
#------------------------------------------------------------------------------
# This module handles routines executed without the need of the Game_Map
# class being loaded to test validity of Big Map data
#==============================================================================
module BigMaps
def self.exists?
return BigMaps.const_defined? :Map
end
end
#==============================================================================
# ** Game_MapD
#------------------------------------------------------------------------------
# This class handles the storage and retrieval of Dynamic Map Data.
# Refer to "$game_system.game_map_d" for the instance of this class.
#==============================================================================
class Game_MapD
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :map_data # Stored map data content
#--------------------------------------------------------------------------
# * Private Instance Variables
#--------------------------------------------------------------------------
def initialize
@map_data = {}
end
#--------------------------------------------------------------------------
# * Set Map
# map : map data
# map_id : Map ID
#--------------------------------------------------------------------------
def set_map(map, map_id)
map_id = big_map?(map_id)
@map_data[map_id] = map
end
#--------------------------------------------------------------------------
# * Get Map
# map_id : Map ID
#--------------------------------------------------------------------------
def get_map(map_id)
map_id = big_map?(map_id)
return @map_data[map_id]
end
#--------------------------------------------------------------------------
# * Big Map Test ?
# map_id : Map ID
#--------------------------------------------------------------------------
def big_map?(map_id)
# Reset the test array
map_list = []
# Exit unless Big Maps Exist
unless BigMaps.exists?
# Exit Method
return map_id
end
# IF Big Map System exists
map_key = BigMaps.map_test(map_id)
# If within a Big Map
unless map_key.nil?
# Change the map ID
map_list = BigMaps::Map[map_key]
map_id = map_list[1][0]
end
# Exit Method
return map_id
end
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias dm_orig_initialize initialize
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :game_map_d # Holder for all Dynamic Maps
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
dm_orig_initialize
@game_map_d = Game_MapD.new
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Alias Listingd
#--------------------------------------------------------------------------
alias dm_orig_setup setup
#--------------------------------------------------------------------------
# * Setup
# map_id : map ID
#--------------------------------------------------------------------------
def setup(map_id)
# Save current map
save_dynamic_map(@map_id)
# If test for Dynamic Map fails
if $game_system.game_map_d.get_map(map_id).nil?
# Perform the original call
dm_orig_setup(map_id)
# Exit method
return
end
# Load Dynamic Map
load_dynamic_map(map_id)
end
#--------------------------------------------------------------------------
# * Load Dynamic Map
# map_id : map ID
#--------------------------------------------------------------------------
def load_dynamic_map(map_id)
# Do not function unless it passes dynamic map test
return unless dynamic_test_map?(map_id) == true
# Restore map game object from Dynamic Map Module by ID
$game_map = $game_system.game_map_d.get_map(map_id)
end
#--------------------------------------------------------------------------
# * Save Dynamic Map
# map_id : map ID
#--------------------------------------------------------------------------
def save_dynamic_map(map_id)
# Exit method if no active map ID
return if map_id == 0
# Do not function unless it passes dynamic map test
return unless dynamic_test_map?(map_id) == true
# Set Current Map into Dynamic Map Module
$game_system.game_map_d.set_map(self.dup, map_id)
end
#--------------------------------------------------------------------------
# * Test for Permitted Dynamic Map
# map_id : map ID
#--------------------------------------------------------------------------
def dynamic_test_map?(map_id)
# Define true dynamic flag
effective = true
# Set dynamic flag false if required flag list does not contain map
unless Dynamic::REQUIRED_MAP_IDs.nil?
effective = false unless Dynamic::REQUIRED_MAP_IDs.include?(map_id)
end
# Set dynamic flag false if ignored flag list contains map
unless Dynamic::IGNORED_MAP_IDs.nil?
effective = false if Dynamic::IGNORED_MAP_IDs.include?(map_id)
end
# Return flag
return effective
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Clear Dynamic Map data from current map
# map_id : Map ID
#--------------------------------------------------------------------------
def clear_current_dynamic_map(map_id=0)
return if map_id == 0
$game_system.game_map_d.map_data[map_id] = nil
end
#--------------------------------------------------------------------------
# * Clear all Dynamic Map data from current map
#--------------------------------------------------------------------------
def clear_all_dynamic_maps
map_list = load_data("Data/MapInfos.rxdata")
for map in map_list
# Get map ID
map_id = map[0]
next if map_id == 0
$game_system.game_map_d.map_data[map_id] = nil
end
end
end
Instructions
Post this Below Scene_Debug and above Main. If used with either Big Maps (by DerVVulfman) and/or Fog of War (by Wachunga), it must be below 'em'. It should take effect after that.
FAQ
I only did this rewrite after testing Near's early 2007 era work, only to see it didn't function properly between different game saves under specific conditions.
Compatibility
Designed for RPGMaker XP. As a bonus, compatible with my Big Maps at no extra cost.
Credits and Thanks
Credits definitely to Near Fantastica for the initial work and Wachunga for his edit to make Near's original work more compliant with other map scripts. And lastly, credit to Melana for a a request to clear map data, and in detection of a logic error involving ignored maps.
Terms and Conditions
Free for use, even in commercial projects. Due credit is required, not only for me but for Near Fantastica, Wachunga and Melana.
This script now includes two new script calls that lets you clear dynamic map data, returning the map to its default settings rather than hold onto the saved settings. If a map event was 'erased' and this condition was saved by the dynamic map system, running these commands nullify this.
A nice new feature has been added now, a module where you can list those maps that may be skipped by the system or those that may be the only ones that are used.
Yes, you can limit the Dynamic Maps now.
The first array is called the "IGNORED_MAP_IDs". Here, you can list the IDs of maps that will never be dynamic maps. In the default script, it currently has maps 1 and 2 blocked. They are NOT dynamic and will never be. It can be set to 'nil' instead of having an array of map IDs if you wish.
The second array is called the "REQUIRED_MAP_IDs". Here, you can list the IDs of maps that must be dynamic maps, this under the assumption that maps not listed are 'not' dynamic maps. Currently, it is set to 'nil'. However, if this value was set to an array like REQUIRED_MAP_IDs = [4,5,7,8], then these four maps are the ONLY ones that would be dynamic maps.
Saving games with Dynamic Maps does create larger game save files, not only with this system but others (I am not gonna plug any names). However, this new feature should allow mitigation and lessen the resulting file size.
Then let me ask you a question that might be interesting for users like Melana herself.
What if anyone added the same map to both arrays by mistake?
Will it trigger the dynamic maps? Or would it be cancelled altogether by the latter?
I noticed that the IGNORED_MAP_IDs feature doesn't seem to work.
If I include a map in the array, it will still save it's state and won't reset after leaving.
One single line within the code performed a test on the WRONG value, testing the existence of the Required Maps array instead! Ugh...
Well, that's been fixed, and I changed the 'names' of the alias commands for the last couple of methods of this script. Seripusly, I had 'LYCAN' in one of the alias commands which woulda been a problem if anyone used this with my ABS.
Hmm I noticed that in the newest version of this script all maps reset after leaving them regardless if they are in the IGNORED_MAP_IDs array or not
It doesn't happen in the old 1.1 version.
EDIT: It was my bad..I forgot to set the REQUIRED_MAP_IDs array to nil.
Everything works as it should now.
Uhm I just noticed that if you save and load a savegame all maps will reset.
Right now I'm able to respawn all defeated enemies and all other erased events simply by leaving a map and reloading the game.
I don't think this should happen at all? :o
It's funny that I never noticed this until now after testplaying my game for more than 50 hours the last months.^^
Edit: I managed to save the dynamic maps into the savegames now to prevent the respawning of events after loading with these lines of code in the save and load methods for now:
Code:
Marshal.dump($game_map_d, file)
Code:
$game_map_d = Marshal.load(file)
Do you think this will cause any trouble?
It works for me so far..