07-27-2017, 04:51 AM (This post was last modified: 07-06-2021, 04:01 AM by DerVVulfman.)
Dynamic Maps Expanded Version: 1.5
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.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)