Code:
################################################################################
# Event Location Saver 1.1
# By: Ixfuru
# August 18, 2013
################################################################################
#
# This script saves the location of an event and holds this place even after
# transfers to different maps. To use the script, utilize the following
# script calls:
#
# To save the position of an event, use:
#-------------------------------------------------------------------------------
# $game_map.save_ev_loc(event_id, x, y)
#
# event_id: the event you wish to lock into a position
# x: the x position where you want the event to stay
# y: the y position where you want the event to stay
#-------------------------------------------------------------------------------
#
# To free a locked event, use:
#-------------------------------------------------------------------------------
# $game_map.free_ev_loc(event_id)
#
# event_id: the id of the event you wish to free from its saved position
#-------------------------------------------------------------------------------
#
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
# EXPANDED VERSION
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
# In the following hash, you can store map ids in an array. If the hash has a
# map_id, all it's events' locations will be saved.
################################################################################
module Ixfuru
module EvLoc
EVLOCMAPS = [2]
################################################################################
# Also, if you'd rather, you can set the below boolean to true in order to save
# all the events from all the maps location.
################################################################################
EVLOCSAVEALL = false
################################################################################
# Finally, you can set the below switch to determine when to 'save all'. If the
# switch is on, it will save ALL event locations. If off, it will save only
# those you have stated. If EVLOCSAVEALL is true, you can just leave the switch
# off. This only takes effect if EVLOCSAVEALL is false.
################################################################################
EVLOCSWITCH = 3 #switch_id used to save all
end
end
##*************************SCRIPT SUMMARY*************************************##
# So to emphasize the way the script is set up:
#
# The EVLOCSAVEALL overrides everything, causing the locations of ALL events on
# ALL maps to be saved.
#
# The EVLOCSWITCH overrides the EVLOCMAPS but NOT the EVLOCSAVEALL.
#
# The EVLOCMAPS overrides the individual calls of event location saves but NOT
# the EVLOCSWICH.
#
# Save individual events by using the script call at the top of the script.
#*******************************************************************************
# There are two other script calls you can make. These involve the clearing of
# saved locations.
#
# To clear ALL event location saves on ALL maps, use:
#
# $game_map.ev_loc_free_all
#
# To clear the event location saves on an individual map, use:
#
# $game_map[map_id].ev_loc_free_map
#
# Replace the map_id with the id of the map you wish to clear.
#-------------------------------------------------------------------------------
# Don't edit anything beyond this point unless you know how to script!
#
################################################################################
################################################################################
################################################################################
# Give credit to Ixfuru
################################################################################
################################################################################
# CLASS GAME EVENT
################################################################################
class Game_Event < Game_Character
#-----------------------------------------------------------------------------
# Move to Saved Location
#-----------------------------------------------------------------------------
def moveto_saved_location
return if $game_map.evlocsaves.empty? || !$game_map.evlocsaves.has_key?(@map_id) ||
!$game_map.evlocsaves[@map_id].has_key?(@id)
loc = $game_map.evlocsaves[@map_id][@id]
moveto(loc[0], loc[1])
end
end
################################################################################
# CLASS GAME MAP
################################################################################
class Game_Map
attr_accessor :evlocsaves
#-----------------------------------------------------------------------------
# Initialize (Aliased)
#-----------------------------------------------------------------------------
alias ixgmapinit initialize unless $@
def initialize
ixgmapinit
@evlocsaves = {}
end
#-----------------------------------------------------------------------------
# Setup (Aliased)
#-----------------------------------------------------------------------------
alias ixgmapsetup setup unless $@
def setup(map_id)
ixgmapsetup(map_id)
operate_evloc
end
#-----------------------------------------------------------------------------
# Operate Evloc
# determines how event location saves should be handled and handles them
#-----------------------------------------------------------------------------
def operate_evloc
if Ixfuru::EvLoc::EVLOCSAVEALL || Ixfuru::EvLoc::EVLOCSWITCH ||
Ixfuru::EvLoc::EVLOCMAPS.has_key?($game_map.id)
@events.each_key { |event|
@events[event].moveto_saved_location
}
else
move_evloc_individual
end
end
#-----------------------------------------------------------------------------
# Move Event Individual (sets event location on an individual basis)
#-----------------------------------------------------------------------------
def move_evloc_individual
@events.each_key { |event|
if @evlocsaves.has_key?(map_id) && @evlocsaves[map_id].has_key?(event)
@events[event].moveto_saved_location
end
}
end
#-----------------------------------------------------------------------------
# Save Ev Loc (Save Event Location)
# event_id: id of the event you wish to save
# x: map x corresponding to where you want the event to be
# y: map y corresponding to where you want the event to be
#------------------------------------------------------------------------------
def save_ev_loc(event_id, x, y)
if @evlocsaves[@map_id] == nil
@evlocsaves[@map_id] = Hash[event_id, [x, y]]
else
@evlocsaves[@map_id][event_id] = [x, y]
end
end
#-----------------------------------------------------------------------------
# Free Ev Loc
# called to free the event from its saved location
# event_id: the id of the event you wish to free
#-----------------------------------------------------------------------------
def free_ev_loc(event_id)
if @evlocsaves[@map_id].has_key?(event_id)
@evlocsaves[@map_id].delete(event_id)
end
end
#-----------------------------------------------------------------------------
# Ev Loc Free All
# erases all event location saves
#-----------------------------------------------------------------------------
def ev_loc_free_all
@evlocsaves.clear
end
#-----------------------------------------------------------------------------
# Ev Loc Free Map
# frees all event saved locations for an individual map
#-----------------------------------------------------------------------------
def ev_loc_free_map
@evlocsaves.delete(@map_id)
end
#-----------------------------------------------------------------------------
# Gather Saved Locations
# determines how saved locations should be handled when leaving map and
# handles them accordingly.
#-----------------------------------------------------------------------------
def gather_saved_locations
if Ixfuru::EvLoc::EVLOCSAVEALL || $game_switches[Ixfuru::EvLoc::EVLOCSWITCH] ||
Ixfuru::EvLoc::EVLOCMAPS.include?(@map_id)
@events.each_key { |event|
save_ev_loc(event, @events[event].x, @events[event].y)
}
p @evlocsaves
end
end
end
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
# SCENE MAP
#&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# * Player Transfer Processing (Aliased)
#--------------------------------------------------------------------------
alias ixscmapupdplytrnsfr update_transfer_player unless $@
def update_transfer_player
if $game_player.transfer?
$game_map.gather_saved_locations
end
ixscmapupdplytrnsfr
end
end