12-07-2016, 11:36 PM
(This post was last modified: 09-02-2024, 05:26 PM by DerVVulfman.)
Event Location Saver
Version: 1. 1
Posted on: December 7, 2016
By: Ixfuru
Original Code: August 18, 2013
System: RpgMaker VX
INTRODUCTION
This script allows you to save the location of events on the map through transfers. The script uses short script calls to perform the procedure. You can save all event spots or even release all saved event spots with simple calls as well. Further instructions are in the script.
HOW TO USE
Place the script above main and below materials. You'll have to set up a switch_id which can be used to turn event location saving globally on and off. There's also an option you can set up by filling in an array with all the maps you want to save positions on.
THE CODE
CREDITS
Use it as you wish. Just credit me, Ixfuru, if you use it commercially or non-commercially. If you use it, let me know and be sure to posts any errors you find.
Version: 1. 1
Posted on: December 7, 2016
By: Ixfuru
Original Code: August 18, 2013
System: RpgMaker VX
INTRODUCTION
This script allows you to save the location of events on the map through transfers. The script uses short script calls to perform the procedure. You can save all event spots or even release all saved event spots with simple calls as well. Further instructions are in the script.
HOW TO USE
Place the script above main and below materials. You'll have to set up a switch_id which can be used to turn event location saving globally on and off. There's also an option you can set up by filling in an array with all the maps you want to save positions on.
THE CODE
Content Hidden
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
CREDITS
Use it as you wish. Just credit me, Ixfuru, if you use it commercially or non-commercially. If you use it, let me know and be sure to posts any errors you find.