Quick travel

0 Members and 1 Guest are viewing this topic.

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
Quick Travel
Version: 1.2
Author: TDS
Date: February 19, 2012

Version History


  • Version 1.0 2012.02.19 - Original Release
  • Version 1.2 2012.03.24 - Added method to call quick travel menu from events.


Description


This script allows you to set quick travel locations that you can quickly go to in a map from a special menu.

Features

  • Quickly changing locations in a map.

Screenshots




Instructions

Just put the script in the materials area of the script editor and follow the instructions in the script. To call the Quick Travel menu from the map press A.

Script


Code: [Select]
#==============================================================================
# ** TDS Quick Travel
#    Ver: 1.2
#------------------------------------------------------------------------------
#  * Description:
#  This script allows you to quickly travel to pre determined locations on a
#  map.
#------------------------------------------------------------------------------
#  * Features:
#  Quickly changing locations in a map.
#------------------------------------------------------------------------------
#  * Instructions:
#
#  To add a quick travel location to a map use this in a script call:
#
#  add_map_quick_travel(name, map_id, x, y, dir, index)
#
#   name   = name of the quick travel location
#   map_id = map id to add quick travel location to
#   x      = X coordinate of the quick travel location on the map
#   y      = Y coordinate of the quick travel location on the map
#   dir    = facing direction after quick traveling (2, 4, 6, 8)
#
#  To disable quick travel use this on a script call:
#
#  disable_map_quick_travel

#  To enable quick travel use this on a script call:
#
#  disable_map_quick_travel
#
#  To call the quick travel menu directly from an event use this in a script
#  call:
#
#  call_map_quick_travel_menu
#------------------------------------------------------------------------------
#  * Notes:
#  None.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#==============================================================================
# * Import to Global Hash *
#==============================================================================
($imported ||= {})[:TDS_Quick_Travel] = true

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :map_quick_travel
  attr_accessor :disable_quick_travel
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias tds_quick_travel_game_system_initialize                    initialize 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Run Original Method
    tds_quick_travel_game_system_initialize     
    # Initialize Quick Travel Values
    init_quick_travel       
  end
  #--------------------------------------------------------------------------
  # * Initialize Map Quick Travel
  #--------------------------------------------------------------------------
  def init_quick_travel 
    # Disable Quick Travel Flag
    @disable_quick_travel = false
    # Make Map Quick Travel Hash
    @map_quick_travel = {}
  end 
  #--------------------------------------------------------------------------
  # * Determine if Map Quick Travel is possible
  #--------------------------------------------------------------------------
  def can_quick_travel?
    # Return false if map quick travel is disabled
    return false if @disable_quick_travel
    # Return false if Map Quick Travel has no quick travel points
    return false if !has_quick_travel? #@map_quick_travel[$game_map.map_id].nil? or @map_quick_travel[$game_map.map_id].empty?
    # Return true by default
    return true
  end
  #--------------------------------------------------------------------------
  # * Determine if Map has Quick Travel points
  #--------------------------------------------------------------------------
  def has_quick_travel?
    # Return false if Map Quick Travel List is nil or empty
    return false if @map_quick_travel[$game_map.map_id].nil? or @map_quick_travel[$game_map.map_id].empty?
    # Return true by default
    return true
  end
  #--------------------------------------------------------------------------
  # * Get Quick Travel Map List
  #--------------------------------------------------------------------------
  def quick_travel_map_list
    # Map List
    list = []
    quick_travel = @map_quick_travel[$game_map.map_id]
    # Go Through Quick Travel Points
    quick_travel.keys.each {|n|
    # Add Quick Travel Point to list
    list << [n] + quick_travel[n]
    }
    # Return list sorted by Index
    return list.sort {|a,b| a.at(4) <=> b.at(4)}
  end
end


#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Enable or Disable Map Quick Travel
  #--------------------------------------------------------------------------
  def enable_map_quick_travel ; $game_system.disable_quick_travel = false end 
  def disable_map_quick_travel ; $game_system.disable_quick_travel = true end
  #--------------------------------------------------------------------------
  # * Call Map Quick Travel Menu
  #--------------------------------------------------------------------------
  def call_map_quick_travel_menu
    # If on Scene Map and there are quick travel points
    if SceneManager.scene_is?(Scene_Map) and $game_system.has_quick_travel?
      # Call Quick Travel Menu Process
      SceneManager.scene.process_quick_travel
    end
  end
  #--------------------------------------------------------------------------
  # * Add Map Quick Travel
  #--------------------------------------------------------------------------
  def add_map_quick_travel(name, map_id, x, y, dir = 2, index = 0)
    # Make Empty hash
    $game_system.map_quick_travel[map_id] ||= {}
    # Set Map Quick Travel Point
    $game_system.map_quick_travel[map_id][name] = [x, y, dir, index]   
  end
  #--------------------------------------------------------------------------
  # * Remove Map Quick Travel
  #--------------------------------------------------------------------------
  def remove_map_quick_travel(name, map_id)
    # Return if there are quick travel points in the map
    return if $game_system.map_quick_travel[map_id].nil?
    # Delete Map Quick Travel Point
    $game_system.map_quick_travel[map_id].delete(name)
  end
end


#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias tds_quick_travel_scene_map_update                              update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update Quick Travel Input
    update_quick_travel_input   
    # Run Original Method
    tds_quick_travel_scene_map_update
  end
  #--------------------------------------------------------------------------
  # * Update Quick Travel Input
  #--------------------------------------------------------------------------
  def update_quick_travel_input
    # Return if Interpreter is running or messages
    return if !$game_system.can_quick_travel? or $game_map.interpreter.running? or ($game_message.busy? or $game_message.visible)   
    # If Input Trigger A
    if Input.trigger?(:X)
      # Play Ok Sound
      Sound.play_ok
      # Process Quick Travel
      process_quick_travel
    end
  end
  #--------------------------------------------------------------------------
  # * Process Quick Travel
  #--------------------------------------------------------------------------
  def process_quick_travel
    # Make Cutscene Cover Sprite
    @scene_cover = Sprite.new
    @scene_cover.bitmap = Graphics.snap_to_bitmap
    @scene_cover.bitmap.blur     
    @scene_cover.opacity = 0     
    @scene_cover.tone.set(-30, -30, -30)
    @scene_cover.z = 5000
   
    # Make Cutscene Skip Window
    @quick_travel_list_window = Window_Quick_Travel_List.new
    @quick_travel_list_window.x = (Graphics.width - @quick_travel_list_window.width) / 2
    @quick_travel_list_window.y = (Graphics.height - @quick_travel_list_window.height) / 2     
    @quick_travel_list_window.z = 5100
    @quick_travel_list_window.openness = 0
    @quick_travel_list_window.open     
   
    # Scene Cover Fade In
    15.times do Graphics.update ; @scene_cover.opacity += 17 end
    # Opem Quick Travel Window
    10.times do Graphics.update ; @quick_travel_list_window.update end
   
    loop do
      # Update Graphics and Input
      Graphics.update ; Input.update     
      # Update Quick Travel List Window
      @quick_travel_list_window.update       
      # If Input Trigger C (Confirm)
      if Input.trigger?(:C)
        # Play Ok Sound
        Sound.play_ok
        # Get Transfer Information
        transfer_info = @quick_travel_list_window.selected_transfer
        # Deactivate and Close Quick Travel List window
        @quick_travel_list_window.deactivate ; @quick_travel_list_window.close                   
        # Fadeout All Windows
        10.times do Graphics.update ; @scene_cover.opacity -= 17 ; @quick_travel_list_window.update end
        # Dispose of Scene Cover
        @scene_cover.bitmap.dispose ; @scene_cover.dispose ; @scene_cover = nil
        # Dispose of Quick Travel List Window
        @quick_travel_list_window.dispose ; @quick_travel_list_window = nil
        # Start Transfer
        $game_player.reserve_transfer($game_map.map_id, transfer_info.at(1), transfer_info.at(2), transfer_info.at(3))
        $game_temp.fade_type = 0
        # Update Input
        Input.update
        break
      end
     
      # If Input Trigger B (Cancel)
      if Input.trigger?(:B)
        # Play Cancel Sound
        Sound.play_cancel
        # Deactivate and Close Quick Travel List window
        @quick_travel_list_window.deactivate ; @quick_travel_list_window.close
        # Fadeout All Windows
        10.times do Graphics.update ; @scene_cover.opacity -= 17 ; @quick_travel_list_window.update end
        # Dispose of Scene Cover
        @scene_cover.bitmap.dispose ; @scene_cover.dispose ; @scene_cover = nil
        # Dispose of Quick Travel List Window
        @quick_travel_list_window.dispose ; @quick_travel_list_window = nil
        # Update Input
        Input.update
        break
      end       
    end     
  end
end


#==============================================================================
# ** Window_Quick_Travel_List
#------------------------------------------------------------------------------
#  This window handles Quick Travel List selection.
#==============================================================================

class Window_Quick_Travel_List < Window_Command
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :quick_travel_list 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Get Quick Travel List
    @quick_travel_list =  $game_system.quick_travel_map_list     
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Window Width and Height
  #--------------------------------------------------------------------------
  def window_width  ; 300 end
  def window_height ; 48 + @quick_travel_list.size * item_height end
  #--------------------------------------------------------------------------
  # * Item Rect
  #--------------------------------------------------------------------------
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * item_width
    rect.y = 24 + index / col_max * item_height
    rect
  end
  #--------------------------------------------------------------------------
  # * Ok Enabled Handling
  #--------------------------------------------------------------------------
  def ok_enabled? ; false end
  #--------------------------------------------------------------------------
  # * Max Columns
  #--------------------------------------------------------------------------
  def col_max ; 1 end
  #--------------------------------------------------------------------------
  # * Command Text Alignment
  #--------------------------------------------------------------------------
  def alignment ; 0 end   
  #--------------------------------------------------------------------------
  # * Make Commands List
  #--------------------------------------------------------------------------
  def make_command_list
    # Make Command List
    @quick_travel_list.each {|i| add_command(i.at(0), :i, true)}
  end
  #--------------------------------------------------------------------------
  # * Get Selected Transfer Information
  #--------------------------------------------------------------------------
  def selected_transfer ; @quick_travel_list[@index] end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    super
    contents.font.color = system_color
    draw_text(0, 0, contents_width, 24, "Quick travel list", 1)
  end
end

Credit


  • TDS

Thanks

  • Archeia for requesting the script and testing.

Support


On this topic.

Known Compatibility Issues

None that I know of so far.

Restrictions

Only for use in non-commercial games.
« Last Edit: March 25, 2012, 03:22:58 AM by TDS »

**
Rep:
Level 71
Captain of Ultima
Is there any possibility to make this script calling by a "Script" command instead of pressing button? I want to make something like waypoints, so i need to let the player move only from point to point, not from anywhere he wants...
Sorry 'bout my bad english :/

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
Sure, I updated the script.

Just use this to call the quick travel menu with a script call from an event.

Code: [Select]
call_map_quick_travel_menu

It should still work even if the feature is disabled, it will prevent a player from calling it with a key but it will allow it to be called from an event.