#==============================================================================
# Teleportation
# Author: Shdwlink1993
# Version: 1.1
# Type: Game Addon
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Teleport Date 1.0: 2/1/2009
# Teleport Date 1.1: 2/5/2009
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# # 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.
# #
# #----------------------------------------------------------------------------
# #
# # Note that if you share this file, even after editing it, you must still
# # give proper credit to shdwlink1993.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# ~= Functions =~
#
# This script allows you to teleport to predefined locations, not unlike RPG
# Maker 2003's similar function.
#
# $game_player.add_location(name, map, x, y, face, description)
# Adds a location to the list of teleportable locations. You cannot add a
# location if it's name is already in use (limit duplicates). Face refers to
# the direction the player will be facing. If you don't know, look at a number
# pad. 2 is down, 4 left, etc.
#
# $game_player.add_here(name, description)
# Adds a location to the list where you are with the designated name and
# description.
#
# $game_player.remove_location(name)
# Removes a location with the name from the list of teleportable locations.
#
# $game_player.disable_location(name)
# Disallows you to teleport to the location with the name. This should be
# used only in instances where the teleport is to be temporarily disabled. If
# it should be permanently disabled, use the remove_location command to free
# space.
#
# $game_player.enable_location(name)
# Allows you to teleport to the disabled location with the name.
#
# $game_player.toggle_location(name)
# Changes if the location with the name can be teleported to or not.
#
# $game_player.backup_locations
# Makes a backup of all known locations and deletes them.
#
# $game_player.restore_locations
# Restores the locations from the backup. All locations learned in the backup
# are added to the list.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# ~= Version History =~
#
# Version 1.0 ------------------------------------------------------ [2/1/2009]
# Version 1.1 ------------------------------------------------------ [2/5/2009]
# - Added in ability to disable individual teleports.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# ~= Compatability =~
#
# - Should work perfectly with just about anything.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Game_System
attr_accessor :teleport_disabled
alias teleinit initialize
def initialize
teleinit
@teleport_disabled = false
end
end
class Game_Player
attr_reader :known_locs
alias teleinit initialize
def initialize
teleinit
@known_locs = []
@backup_locs = []
end
def add_here(name, desc = '')
return add_location(name, $game_map.map_id, @x, @y, @direction, desc)
end
def add_location(name, map, x, y, face, desc = '')
unless @known_locs == []
@known_locs.each_index {|i| return if name == @known_locs[i][0] }
end
@known_locs.push([name, map, x, y, face, desc, true])
end
def remove_location(name)
@known_locs.each_index {|i|
if name == @known_locs[i][0]
@known_locs.delete(@known_locs[i])
return
end}
end
def disable_location(name)
@known_locs.each_index {|i|
if name == @known_locs[i][0]
@known_locs[i][6] = false
return
end}
end
def enable_location(name)
@known_locs.each_index {|i|
if name == @known_locs[i][0]
@known_locs[i][6] = true
return
end}
end
def toggle_location(name)
@known_locs.each_index {|i|
if name == @known_locs[i][0]
@known_locs[i][6] = !@known_locs[i][6]
return
end}
end
def backup_locations
@backup_locs = @known_locs
@known_locs = []
end
def restore_locations
@known_locs & @backup_locs
@backup_locs = []
end
end
class Window_Teleport < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 64, 640, 416)
@column_max = 2
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
$game_player.known_locs.each {|t| @data.push(t) }
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
@item_max.times {|i| draw_item(i) }
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item[6]
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(x + 4, y, 212, 32, item[0], 0)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? '' : self.item[5])
end
end
class Scene_Teleport
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@teleport_window = Window_Teleport.new
# Associate help window
@teleport_window.help_window = @help_window
# Execute transition
Graphics.transition
# Main loop
loop {
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
break if $scene != self
}
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@teleport_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@teleport_window.update
update_tele
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_tele
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @teleport_window.item
# If you can't teleport, then you don't!
unless @item[6]
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
$game_temp.player_transferring = true
# Set player move destination
$game_temp.player_new_map_id = @item[1]
$game_temp.player_new_x = @item[2]
$game_temp.player_new_y = @item[3]
$game_temp.player_new_direction = @item[4]
$scene = Scene_Map.new
return
end
end
end