(RMXP) Vehicle Script error

So I've been finishing an old game I worked on a while ago and I'm trying to use "Super Simple Vehicle System - Enhanced" by Lambchop and DerVVulfman. If there is a switch required to make the vehicle appear, so that its invisible, it works but if you turn on the switch and the vehicle is actually visible, it's unboardable. I've tried this in other projects and it's clearly not the scripts fault but a compatibility issue, but I have so many scripts that it would be a major pain trying to find the cause. Is there a way I can have the event have a script call when I hit enter so that it automatically just puts me in a certain vehicle, so I can get around the issue?

Code:
#==============================================================================
# ** Super Simple Vehicle System - Enhanced
#------------------------------------------------------------------------------
#    by DerVVulfman (Original code by Lambchop)
#    version 10.1
#    01-02-2018 (MM/YY/DDDD)
#    RGSS / RPGMaker XP (requires Event Spawner & Related Scripts Noted)
#==============================================================================
#
#
#                                INTRODUCTION:
#                                =============
#
#  This system allows you to create and manage 'vehicles' in your RMXP project.
#  You can have  simple vehicles  that travel  in rivers or oceans,  or can fly
#  through the air  over all  the mountains  on the map.   You can  even create
#  mobile headquarters such as those in the Final Fantasy™ games.
#
#  The only thing you can't do is go into the default menus when riding, unless
#  you're IN a mobile headquarters.
#
#  And if you need hints on setting up the configuration section, it is heavily
#  laden with notes.
#
#  That's pretty much it. :) 
#
#
#==============================================================================
#
#  STEP ONE!  MAKE YOUR VEHICLE DATA
#  =================================
#
#  This is pretty much a given. 
# 
#  Each vehicle you design must contain a unique key name. This key name should
#  help identify the vehicle in question. The demo, for example, uses key names
#  such as Boat, Canoe and Dragon. And before you ask, yes... the key names are
#  case sensitive and must be in quotes.
#
#  For each vehicle, there are four hash arrays;   VEHICLE, BEHAVIOR, SOUND and
#  HEADQUARTERS. Each that you use  is referenced by a key, that key being  the
#  key name for each vehicle.  EX: VEHICLE['Blimp'] ...though there is no blimp
#  in the demo.
#
#  The main array of data to configure  is the VEHICLE array.   It is here that
#  you set up the basic data that handles the vehicle's character graphics, the
#  passable flags it may travel,  what terrain tags  the vehicle may be able to
#  land, whether it may pass through events, its movement speed,  and the ID of
#  an RPGMaker switch that may be turned on if the vehicle is in use.
#
#  Not necessary, the BEHAVIOR array is an optional array that controls how the
#  player boards a vehicle  (stepping up or not),  if the player may still have
#  random monster encounters
#
#  And the third SOUND array merely sets any music and/or sound fx that play
#  when in use.
#
#  The fourth array,  the one  labeled HEADQUARTERS,  is also an optional array
#  and is solely used if the game designer wants to make a mobile headquarters.
#  Such headquarters may resemble Final Fantasy VIII's Balamb Garden, or it may
#  act like the HeliCarrier from SHIELD by Marvel Comics. Unlike  the first two
#  arrays, this one is specific not only to a vehicle event,  but to a map that
#  acts as the vehicle's interior.  The array contains the headquarter's map ID
#  number, the X and Y position  the player appears  when he teleports  and the
#  direction the player faces when he appears.  It also includes two true/false
#  values that determines  if the map fades or blinks into existance and if the
#  sound effects performed  when the vehicle is boarded  continues to play when
#  within the headquarters.
#
#
#------------------------------------------------------------------------------
#
#  STEP TWO!  MAKE YOUR VEHICLE
#  ============================
#
#  You won't believe how easy this is.
#
#  The configuration section  not only has  the four vehicle  array types  that
#  designs your vehicles, but (along with input button data) you can set up the
#  specific text you use for your vehicle event's custom name.
#
#  By default,  the name of your event may be anything as long as it also holds
#  the custom vehicle text that is contained within a pair of brackets as such:
#                          EV003 [Vehicle 'Canoe']
#
#  The first segment of the name,  EV003,  holds no significance to the system,
#  though a vehicle that has landed will change to VEH001.  Again,  this really
#  holds no significance to the system.
#
#  What is significant in the event's name is the [Vehicle 'Canoe']  portion as
#  the word, Vehicle,  identifies the event as a Vehicle that can be used,  and
#  the following string, 'Canoe'.  As I said earlier,  within the configuration
#  you can set up a specific text for your vehicle event's custom name.  By de-
#  fault, this value (VEHICLE_FLAG) is set to 'Vehicle '.  And yes, it includes
#  the space.  After the this flag,  the next thing is the key used to identify
#  the vehicle itself.  This key is the string, 'Canoe', and must match the key
#  to a VEHICLE array where you define your individual vehicles (see Step One).
#
#  All in all,  that is the only thing you really need to do after creating the
#  arrays.   Just name your event appropriately  with the vehicle flag  and the
#  string key  between a pair of brackets like this:   EV004 [Vehicle 'Horse'].
#  As long as the flag  is correct,  and you have a matching VEHICLE array with
#  no errors, naming the event as the example showed is all you have to do.
#
#
#------------------------------------------------------------------------------
#
#  STEP THREE!  CUSTOMIZE YOUR RIDE
#  ================================
#
#  Okay, it's not really 'customizing' as it is more like, what you can do with
#  this system.
#
#  First,  you may not understand the significance as to why boarding a vehicle
#  should turn on a switch.  This is to allow certain things to happen when you
#  are riding.  One of the main things would be to allow access or block access
#  to a teleport event.
#
#  Within the demo, you can see the significance with two events located on the
#  third isle.   One is turned on,  and shows an animated beacon for the flying
#  dragon vehicle.  The second is a teleport event thats disabled so the dragon
#  does not inadvertently fly into it and into the ice cave.
#
#                                 *    *    *
#
#  Next, are a pair of script commands  that allow you to teleport  to and from
#  the Headquarters map.
#
#  The first command is the required '$game_player.hq_exit'  script call.  This
#  script call  is used  in some part  of your  headquarters map,  allowing the
#  player to leave the map and return to the vehicle itself... riding or flying
#  around on the initial map.
#
#  The command looks like this:  $game_player.hq_exit("Boat")  In this example,
#  this command returns the player to the map and makes him sail a boat.
#
#  The second one is more of an optional script call, '$game_player.map_to_hq',
#  and is used to teleport a player  who is currently not riding an event to a
#  specified vehicle headquarters map.
#
#  The command,  very much like the  hq_exit  script command,  looks like this:
#  $game_player.map_to_hq('Boeing747')
#
#  There is no script call  to teleport the player from a  Vehicle Headquarters
#  map to  another map.  That feature  can be  done manually  with any  generic
#  [Transfer Player] map event.
#
#                                 *    *    *
#
#  ----------------------------------------------------------------------------
#  The music and sound feature  in the system  is a hold-over from the previous
#  versions of Vehicles.   The system that deals with the audio effects  can be
#  adversely hampered by the methods  in which maps have music or sound effects
#  applied (or not applied).  So all I'll say is, take care of its use.
#
#                                 *    *    *
#
#  This system has an error checking routine  that looks for  duplicate vehicle
#  events that may hamper the game. These duplicate events could cause problems
#  if you were to attempt to use and land a vehicle, and the data from its dup-
#  licate repositions the vehicle  where you may not  be able to go.   It could
#  also hamper Headquarter Vehicles so entering & leaving  the Headquarters Map
#  could change the vehicle's position.
#
#  On the flip side,  the error checking routine  will also inform you  of any
#  vehicles that do not (as yet) have an assigned event.
#
#
#==============================================================================
#
#                        SPECIAL COMPATABILITY SYSTEMS
#                        =============================
#
#  After some cleanup of the code, I tested this script with my newly written
#  Enhanced Squad Movement system. To my delight, most of it worked without a
#  problem. Only some minor additions to the code were needed to make it work
#  fully and properly.
#
#  To use with Enhanced Squad Movement, the Vehicles system must be positioned
#  below the movement script.   This is because the Squad Movement system per-
#  forms major rewrites to the passables methods which Vehicles merely appends.
#
#  Now, party members from the squad system  can vanish when the player boards
#  a vehicle, and then reappear when he exits.   On top of that, squad members
#  that are left behind remain visible at this time.
#
#  >> Vehicles must be below Squad Movement.
#
#                                 *    *    *
#
#  Originally,  I created a special patch for Vehicles  to work with the Mode7
#  system offered by MGCaladtogel  (now known as MGC).   The patch was made so
#  the vehicles could cross looping map borders  so the player may coast along
#  the map  for an indefinite period of time.   Thanks to the redesign of this
#  system, there is no longer any need for the patch.
#
#  To use with the Mode7 system by MGC,  or the Mode7 Edit which I re-drafted,
#  place the Mode7 script below Vehicles.  The necessary passages systems that
#  permit map looping and the like attach themselves just fine to the passages
#  method within Vehicles.
#
#  >> Vehicles must be above Mode7.
#
#                                 *    *    *
#
#  It hasn't been long  since I developed  a script called BIG MAPS,  a script
#  that lets  you chain  multiple maps together  in a manner  to go beyond the
#  inherit 500x500 tile size max.  Ir was a pleasant surprise to find that the
#  Vehicles script had no problems with BIG MAPS at all.
#
#  Because the required 'Permanent Event Erase'  script actively looks for the
#  ID of any map it encounters,  BIG MAPS must be above everything.   Not only
#  the Vehicles script itself,  but over  Permanent Event Erase  and the Event
#  Spawner scripts as well.
#
#  It was quite entertaining to craft a massive map  and just spend some time
#  making a  little boat  go around  a massive continent  made from four maps
#  spliced together.
#
#  Not tested, but I would imagine  the Dynamic Maps Expanded script I posted
#  (a revised version of Near Fantastica's)  would also need  to be put above
#  everything as well.
#
#  >> Big Maps must be above everything.
#
#                                 *    *    *
#
#  You may be asking yourself now  "Can I really have massively big world maps
#  over 1000 X 1000 in size  that loop with this  vehicles script,  and have a
#  groups of party members following me?"
#
#  Just so you know...  Hehehe...  I tested Vehicles with both 'BIG MAPS', the
#  Mode7 system, and Enhanced Squad combined, and I had a BALL!   Yes,  if you
#  place them within your project as I described above,  the only issue you'll
#  have is that the party members will not be visible on the map...  but there
#  is a fix.
#
#  If using Squad Movement with the Mode7 system, you will find that Mode7 re-
#  writes the 'Spriteset_Map' system.  To make the two scripts  work together,
#  extract the Spriteset_Map code  from  Enhanced Squad Movement  and paste it
#  below Mode7.  This lets the the party members  generated by  Squad Movement
#  become visible on the revised map.
#
#  >> Slice 'Spriteset_Map' from Squad and paste the slice below Mode7.
#
#  Other than the alteration described above  to let  Mode7 and Squad Movement
#  work together, you should have no problems  unless you are using other sys-
#  tems that may alter the way the map system behaves.
#
#
#==============================================================================
#
#
#                             CREDITS AND THANKS:
#                             ===================
#
#  To Lambchop... DUH!   And to SephirothSpawn who inspired  and showed her how
#  to make the  first version  of this script.   Thanks to Regimos and Monk for
#  detecting a minor (yet stubborn)  bug that occurs when landing next to a map
#  n event (now fixed).  Another thank to Regimos  for detecting a glitch where
#  the main menu was accidentally re-enabled in  a regular vehicle.  To Alistor
#  and mephisto for supplying the code  for animating vehicles  in motion,  and
#  again to Alistor  for discovering the ability to accidentally debark a vehi-
#  cle when exiting  a mobile HQ.   And to shannon  who suggested  terrain tags
#  that may  not be 'landable',  even if they are passable.   Also, thanks goes
#  to Regimos  for noting that  'landed'  vehicles permitted  other vehicles to
#  pass across/into impassable terrains.  Also, thanks goes  to yamina-chan who
#  noted how characters moving quickly may shift vehicles off their desiginated
#  terrains, & discovering that the use of the Add Event fix was needed.   And,
#  to Sujabes467 who noted an issue where vehicles passed through solid events.
#  Lastly, thanks to Geminil who noted an issue where vehicles disappeared when
#  the player leaves the game map.
#
#
#==============================================================================
#
#                                REQUIREMENTS:
#                                =============
#
#  Apart from it being an RPGMaker XP script,  this system requires three other
#  scripts: The Event Spawner script by SephirothSpawn, DerVVulfman's Permanent
#  Event Erase script, and both the Event Erase and Add Event Fix for the Event
#  Spawner, fixes also by DerVVulfman
# 
#
#==============================================================================
#
#                                TERMS OF USE:
#                                =============
#
#  Free for use, even in commercial games.  Only due credit is required.
#
#
#==============================================================================



module Vehicles
 
  #==========================================================================#
  #                           ===================                            #
  #                           ** CONFIGURATION **                            #
  #                           ===================                            #
  #==========================================================================#
  VEHICLE, BEHAVIOR, SOUND, HEADQUARTERS = {}, {}, {}, {} # Do not Delete    #
  #==========================================================================#



  # VEHICLE DESIGN SYSTEM
  # This is where you design the basics for your vehicles, the graphics,
  # terrains it may cross or be blocked, whether it may pass over events,
  # and the like.
  #
  #         Key Value         Charactername     Pass  Land  Thru    Spd   Sw
  # ==================        ================  ====  ====  ======  ====  ====
    VEHICLE['Canoe']        = [ "Canoe",        [1],  [0],  false,  3]
    VEHICLE['Boat']         = [ "Boat_1838",    [1]     [2],  [0],  4,  2 ]
    VEHICLE['Dragon']       = [ "073-Bird03",   [],   [0],  true,   5,    1 ]
    VEHICLE['FireCanoe']    = [ "Canoe",        [1],  [0],  false,  3]


  # VEHICLE BEHAVIOR SYSTEM
  # This is where you set up how your vehicle behaves, whether you need to
  # step into it or whether you have random encounters.
  #
  #         Key Value           Climb   Encou.
  # ==================        ========  ======
    BEHAVIOR['Canoe']       = [ true,   false]
    BEHAVIOR['Boat']        = [ true,   true]
    BEHAVIOR['FireCanoe']   = [ true,   false]


  # VEHICLE SOUND SYSTEM
  # This is where you set up any audio effects that are played when travelling
  #
  #         Key Value          Background Music      Background Sound
  # ==================        ====================  ====================
    SOUND['Canoe']          = [["047-Positive05"],   nil ]
    SOUND['Boat']           = [["046-Positive04"],  ["008-Wave01"]  ]
    SOUND['FireCanoe']      = [["047-Positive05"],   nil ]


  # VEHICLE HQ SYSTEM
  # This attaches a map to the vehicle which is assumed to be a moving
  # headquarters.  Within you set the Map ID, X and Y locations and the
  # direction your facing, along with fade and sound effects.
  #
  #             Key Value     MapID   XPos  YPos  Dir   Fade  Sound
  # ======================    ======  ====  ====  ====  ====  ======
    HEADQUARTERS['Dragon']  = [2,     10,   7,    4,    false, false ]



  # VEHICLE INPUT
  # This is where you set the keys  used to board  and exit a vehicle,  as
  # well as enter the HQ from an already boarded vehicle.
  #
    BOARD_INPUT     = Input::A      # Key to board a vehicle
    DISEMBARK_INPUT = Input::A      # Key to exit a vehicle
    HQ_INPUT        = Input::B      # Key to enter a HQ from a HQ vehicle


  # VEHICLE ERROR CHECKING
  # When turned on, this activates a system that checks the project's maps
  # and ensures  that each every vehicle defined  has been applied  to one
  # (and only one)  event.   If you have  set up two or more events to the
  # same vehicle, it will warn you.  It will also notify you if you made a
  # vehicle but had not yet applied it to the game.
  #
    ERROR_CHECK     = true          # (true/false) Is the error check on?


  # VEHICLE FLAG
  # This is where  you define  the actual text used  to identify a vehicle
  # event within  its name.   The initial text  at the start  of any event
  # may be anything like EV003,  but it must be followed by  brackets with
  # the flag below  and the name  of the vehicle.   As an example,  it may
  # appear as  ...  EV003 [Vehicle 'Canoe']
  # Event name syntax:  General_Name [ vehicle_flag vehicle_key]
  #
    VEHICLE_FLAG    = 'Vehicle '




  #==========================================================================#
  # Text String for Event Name Data Extraction -- Do Not Touch               #
  #==========================================================================#
    VEHICLE_FORMULA  = /\[#{VEHICLE_FLAG}(?:ECT)?[ ]*'?(\w+)'?]/
  #==========================================================================#
end



#==============================================================================
# ** Non-Class Executable Methods
#------------------------------------------------------------------------------
#  These methods are run outside of the system.  The intent is primarily to
#  check for invalid data in a project before the project even starts.
#==============================================================================

#--------------------------------------------------------------------------
# * Vehicle Check System
#--------------------------------------------------------------------------
def veh_check
  return unless Vehicles::ERROR_CHECK == true
  # Create the empty temp hash for vehicles
  veh_temp = {}
  # Add each vehicle and set each counter to 0
  for key in Vehicles::VEHICLE.keys
    veh_temp[key] = 0
  end
  # Load list of all maps in game
  infos        = load_data("Data/MapInfos.rxdata")
  # Cycle through each map from list
  for key in infos.keys
    # Obtain data from map
    mapdata = Game_Map.new
    mapdata = load_data(sprintf("Data/Map%03d.rxdata", key))
    # Set map event data
    events = {}
    # Cycle through each event
    for i in mapdata.events.keys
      name = mapdata.events[i].name
      if name =~ Vehicles::VEHICLE_FORMULA
        #  Obtain key
        veh_key = $1
        # For valid vehicle keys only
        if Vehicles::VEHICLE.has_key?(veh_key)
          # Get count
          veh_counter = veh_temp[veh_key]
          # Add to count
          veh_counter += 1
          # Reinsert to hash for key
          veh_temp[veh_key] = veh_counter
        end
      end
    end
  end
  # Warning messages
  # Check for 0 vehicle flags
  error_count = 0
  for key in veh_temp.keys
    error_count += 1 if veh_temp[key] == 0
  end
  # If counted errors (part 1 - no vehicles)
  if error_count != 0
    string_list = "These absent vehicles are:  "
    for key in veh_temp.keys
      if veh_temp[key] == 0
        string_list += " "
        string_list += key.to_s
      end
    end
    print "WARNING:  Not all vehicles are in use.  This may be an error. \n" +
          "======================================== \n" +
    string_list
  end
  # Warning messages
  # Check for 2+ vehicle flags
  error_count = 0
  for key in veh_temp.keys
    error_count += 1 if veh_temp[key] > 1
  end
  # If counted errors (part 1 - no vehicles)
  if error_count != 0
    string_list = "These vehicles are:  "
    for key in veh_temp.keys
      if veh_temp[key] > 1
        string_list += " "
        string_list += key.to_s
      end
    end
    print "WARNING:  You have used the same vehicle data"+
          " on two (or more) events. \n" +
          "================================================= \n" +
    string_list
  end
end
# Perform check before project execution
veh_check



#==============================================================================
# ** Event_Spawner
#------------------------------------------------------------------------------
#  This class deals with the creation of new events on the Game_Map.
#==============================================================================

module Event_Spawner
  #--------------------------------------------------------------------------
  # * Return event ID
  #--------------------------------------------------------------------------
  def self.event_id
    return @event.id
  end
  #--------------------------------------------------------------------------
  # * Vehicle
  #     x            : x-location
  #     y            : y-location
  #     d            : facing direction
  #     vehicle_id   : key name id of the vehicle
  #     v_through    : whether the returned vehicle is through
  #--------------------------------------------------------------------------
  def self.vehicle(x, y, d, vehicle_id, v_through=false)
    # Set Facing and placement
    facing = d
    # Get Graphics
    v_image   = Vehicles::VEHICLE[vehicle_id][0]
    v_pattern = 0
    v_opacity = 255
    # --- Generate Chest Code ---
    # Placement and Event Name
    stringval = "VEH001 [Vehicle "+ vehicle_id +"]"
    Event_Spawner.create_event(x, y, stringval)
    # Obtain Event ID
    evie = Event_Spawner.event_id
    # Graphic Routines
    Event_Spawner.set_page_graphic({'c_name' => v_image})
    Event_Spawner.set_page_graphic({'pattern' => v_pattern})
    Event_Spawner.set_page_graphic({'dir' => facing})
    Event_Spawner.set_page_graphic({'opacity' => v_opacity})   
    Event_Spawner.set_page_options({'through' => v_through})
    # Trigger Type (player touch)
    Event_Spawner.set_page_trigger(0)
    # --- Done ---
    Event_Spawner.end_event(true)
    # Special!!!!
    return evie
  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
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :vehicle_object           # Data Object for Vehicles 
  attr_accessor :vehicle_character        # Original Player Characterset
  attr_accessor :vehicle_char_speed       # Original Player Speed
  attr_accessor :vehicle_current          # Current Vehicle
  attr_accessor :vehicle_passage          # Current Vehicle Passage Terr Tags
  attr_accessor :vehicle_through          # Current Vehicle Through (passages)
  attr_accessor :vehicle_disembark        # Current Vehicle Disembark Terr Tags
  attr_accessor :vehicle_event_through    # Current Vehicle Through (for event)
  attr_accessor :v_music                  # Current Vehicle Music Effect
  attr_accessor :v_sound                  # Current Vehicle Sound Effect
  attr_accessor :playing_bgm              # Default playing BGM Value
  attr_accessor :playing_bgs              # Default playing BGS Value
  attr_accessor :menu_was_disabled        # If main menu already disabled
  attr_accessor :e_squad_detect           # if Enhanced Squad is detected.
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias vehicle_game_system_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Perform the original call
    vehicle_game_system_initialize
    # Create the vehicle object value
    @vehicle_object = nil 
    @e_squad_detect = nil
    # Initializing new values
    vehicle_reset
  end
  #--------------------------------------------------------------------------
  # * Vehicle Initialization/Reset
  #-------------------------------------------------------------------------- 
  def vehicle_reset
    @vehicle_character      = nil
    @vehicle_char_speed     = 4
    @vehicle_current        = nil
    @vehicle_passage        = []
    @vehicle_through        = false
    @vehicle_disembark      = []
    @vehicle_event_through  = false
    @v_music                = nil
    @v_sound                = nil
    @menu_was_disabled      = false
  end
  #--------------------------------------------------------------------------
  # * Stop Background Sound
  #--------------------------------------------------------------------------
  def bgs_stop
    Audio.bgs_stop
  end
end



#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :character_name           # character file name
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
  #--------------------------------------------------------------------------
  # * Determine if Vehicle Passable
  #     x          : x-coordinate
  #     y          : y-coordinate
  #     d          : direction (0,2,4,6,8,10)
  #                  *  0,10 = determine if all directions are impassable
  #     self_event : Self (If event is determined passable)
  #--------------------------------------------------------------------------
  def vehicle_passable?(x, y, d, self_event = nil)
    # Coordinate adaption if using looped map system
    y = height-1 if y < 0
    y = 0 if y > height-1
    x = width-1 if x < 0
    x = 0 if x > width-1
    # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
    bit = (1 << (d / 2 - 1)) & 0x0f
    # Skip over events if vehicle not blocked
    unless $game_system.vehicle_through == true
      # Loop in all events
      for event in events.values
        # Get tile ID
        tile_id = event.tile_id
        # If tiles other than self are consistent with coordinates
        if tile_id >= 0 and event != self_event and
           event.x == x and event.y == y and not event.through
          return false  if @passages[tile_id] & bit != 0
          return false  if @passages[tile_id] & 0x0f == 0x0f
          return true   if @priorities[tile_id] == 0
          return false  unless $game_system.vehicle_character.nil?
        end
      end   
    end   
    # Loop searches in order from top of layer
    for i in [2, 1, 0]
      # Get tile ID
      tile_id = data[x, y, i]
      # Get Terrain Tag
      tag = @terrain_tags[tile_id]
      return false  if tile_id == nil
      return true   if $game_system.vehicle_passage.nil?
      return true   if $game_system.vehicle_passage == []
      return true   if $game_system.vehicle_passage.include?(tag)
    end
    return false
  end
  #--------------------------------------------------------------------------
  # * Determine if Landing Passable
  #     x          : x-coordinate
  #     y          : y-coordinate
  #     d          : direction (0,2,4,6,8,10)
  #                  *  0,10 = determine if all directions are impassable
  #     self_event : Self (If event is determined passable)
  #--------------------------------------------------------------------------
  def vehicle_landing?(x, y, d, self_event = nil)
    # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
    bit = (1 << (d / 2 - 1)) & 0x0f
    # Loop searches in order from top of layer
    for i in [2, 1, 0]
      # Get tile ID
      tile_id = data[x, y, i]
      return false  if tile_id == nil
      return false  if @passages[tile_id] & bit != 0
      return false  if @passages[tile_id] & 0x0f == 0x0f
    end
  end
end



#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias vehicle_game_character_passable? passable?
  #--------------------------------------------------------------------------
  # * Determine if Passable
  #     x : x-coordinate
  #     y : y-coordinate
  #     d : direction (0,2,4,6,8)
  #         * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    vehicle_game_character_passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # Impassible if coordinates are outside of map
    return false unless $game_map.valid?(new_x, new_y)
    # Perform new Vehicle passable if engaged
    unless $game_system.vehicle_current.nil?
      # If unable to leave first move tile in designated direction
      return $game_map.vehicle_passable?(new_x, new_y, d, self)
    end
    # Perform the original call
    return vehicle_game_character_passable?(x, y, d)
  end
end



#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page
#  switching via condition determinants, and running parallel process events.
#  It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :erased                   # event erased flag
  attr_accessor :pages                    # event page
  #--------------------------------------------------------------------------
  # * Obtain name
  #--------------------------------------------------------------------------
  def name
    return @event.nil? ? '' : @event.name
  end
end



#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :encounter_count          # Encounter count
  attr_accessor :move_speed               # Speed
  attr_accessor :v_event_id               # Vehicle Event ID
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias vehicle_game_player_update update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Establish vehicle wait count if non exists
    @v_wait_count = 0 if @v_wait_count.nil?
    # Added Vehicle Wait Count for Embark/Disembark
    if @v_wait_count > 0
      # Reduce wait count
      @v_wait_count -= 1
      super
      return
    end   
    # Perform original method unless boarding
    vehicle_game_player_update unless @veh_boarding == true
    # Handle boarding detection
    return if update_detect_boarding? == true
    # Exit method if still boarding vessel
    return update_board_completion unless @v_event_id.nil?
    # Exit method if performed disembark
    return if update_disembark == true
    # Check if HQ Button is pressed
    update_hq_entry
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when determining if player boarding)
  #--------------------------------------------------------------------------
  def update_detect_boarding?
    return false unless $game_system.vehicle_current.nil?
    return false unless Input.trigger?(Vehicles::BOARD_INPUT)
    veh_key = nil
    veh_id  = 0 
    for event in $game_map.events.values
      next if event.nil?
      next if event.erased == true
      if event.name =~ Vehicles::VEHICLE_FORMULA
        gx          = $game_player.x
        gy          = $game_player.y
        check_type  = false
        if event.through
          check_type = true if event.x == gx and event.y == gy
        else
          case $game_player.direction
          when 1 ; check_type = true if event.x == gx-1 and event.y == gy+1
          when 2 ; check_type = true if event.x == gx+0 and event.y == gy+1
          when 3 ; check_type = true if event.x == gx+1 and event.y == gy+1
          when 4 ; check_type = true if event.x == gx-1 and event.y == gy+0
          when 6 ; check_type = true if event.x == gx+1 and event.y == gy+0
          when 7 ; check_type = true if event.x == gx-1 and event.y == gy-1
          when 8 ; check_type = true if event.x == gx+0 and event.y == gy-1
          when 9 ; check_type = true if event.x == gx+1 and event.y == gy-1
          end
        end
        if check_type == true
          veh_key = $1
          veh_id  = event.id
          break
        end
      end
    end
    if veh_id != 0
      if Vehicles::VEHICLE.has_key?(veh_key)
        update_vehicle_board(veh_key, veh_id)
      end
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when ensuring the vehicle has been boarded)
  #--------------------------------------------------------------------------
  def update_board_completion
    # Deactivate Vehicle Boarding flag
    @veh_boarding = nil
    # Ensure not a through vehicle
    @through      = false
    # Store the actor and initial key data
    $game_system.vehicle_character        = $game_party.actors[0].character_name
    $game_system.vehicle_char_speed       = $game_player.move_speed
    key = $game_system.vehicle_current
    # Reset the actor to new vehicle specs
    $game_party.actors[0].character_name  = Vehicles::VEHICLE[key][0]
    $game_system.vehicle_passage          = Vehicles::VEHICLE[key][1]
    $game_system.vehicle_disembark        = Vehicles::VEHICLE[key][2]
    $game_system.vehicle_through          = Vehicles::VEHICLE[key][3]
    $game_player.move_speed               = Vehicles::VEHICLE[key][4]
    # Set the switch if needed
    unless Vehicles::VEHICLE[key][5].nil?
      $game_switches[Vehicles::VEHICLE[key][5]] = true
    end
    # Set Perma-Erase
    $game_temp.perma_erase = true
    # Erase Event from map
    $game_map.events[@v_event_id].erase
    # Set the music and sound
    vehicle_music(key)
    vehicle_sound(key)
    # Make the vehicle animated
    @step_anime = true
    # Don't flag refresh.  Force it.
    $game_player.refresh
    $game_map.need_refresh == true
    $game_map.refresh
    # Hide squad members if present
    update_vehicle_squad_conceal
    # Remove event id altogether
    @v_event_id = nil
  end 
  #--------------------------------------------------------------------------
  # * Frame Update (when making the player exit the vehicle by key input)
  #--------------------------------------------------------------------------
  def update_disembark
    # Only function if Disembark Key pressed
    return false unless Input.trigger?(Vehicles::DISEMBARK_INPUT)
    # Used for vehicle behavior
    id    = $game_system.vehicle_current
    new_x = @x
    new_y = @y
    d     = @direction
    stepping_forward = false
    # Adjust depending on type of vehicle
    if Vehicles::BEHAVIOR.has_key?(id)
      if Vehicles::BEHAVIOR[id][0] == true
        new_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
        new_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
        stepping_forward = true
      end
    end
    tag = $game_map.terrain_tag(new_x, new_y)
    # Prevent disembark
    unless $game_system.vehicle_disembark.include?(tag)
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return false
    end
    # Prevent disembark (blocked terrains though same tag)
    if $game_map.vehicle_landing?(new_x, new_y, d, self) == false
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return false
    end
    # Set Wait Count
    @v_wait_count = 10
    @v_wait_count = 15 if stepping_forward == true
    # Reset the Vehicle Data
    id                            = $game_system.vehicle_current
    v_through                     = $game_system.vehicle_event_through
    $game_system.vehicle_current  = nil
    # Reset Actor
    $game_party.actors[0].character_name  = $game_system.vehicle_character
    $game_player.move_speed               = $game_system.vehicle_char_speed
    # Set the switch if needed
    unless Vehicles::VEHICLE[id][5].nil?
      $game_switches[Vehicles::VEHICLE[id][5]] = false
    end
    # Retrieve current event ID for generated vehicle
    v_id = Event_Spawner::vehicle(@x, @y, @direction, id, v_through)
    # Set Location and event ID in Game_System
    vehicle_array = [$game_map.map_id, @x, @y, @direction, v_id]
    $game_system.vehicle_object.vehicle[id] = vehicle_array
    @through = true
    move_forward if stepping_forward == true
    # Retrieve Original Music (unless in Auto-Change BGM)
    music_set = $game_system.v_music
    # Erase music set if it is the vehicle (ala HQ) and it exists
    if Vehicles::SOUND.has_key?(id)
      unless Vehicles::SOUND[id][0].nil?
        unless music_set.nil?
          music_set = nil if music_set[0] == Vehicles::SOUND[id][0][0]
        end
      end
    end
    if music_set.nil?
      $game_system.bgm_stop
      $game_system.playing_bgm = nil
    end
    # Playback Music
    vehicle_music_playback(music_set)
    # Retrieve Original Sound (unless in Auto-Change BGS)
    sound_set = $game_system.v_sound
    if sound_set.nil?
      $game_system.bgs_stop
      $game_system.playing_bgs = nil
    end
    # Playback Sound
    vehicle_sound_playback(sound_set)
    # Check if menu was already disabled
    unless $game_system.menu_was_disabled == true
      # Re-Enable Menu
      $game_system.menu_disabled = false
    end
    # Turn off Stepping
    @step_anime = false   
    # Reset Vehicle Values to Start
    $game_system.vehicle_reset
    # Don't flag refresh.  Force it.
    $game_player.refresh
    $game_map.need_refresh == true
    $game_map.refresh   
    @through = false
    # Reveal squad members if present   
    update_vehicle_squad_reveal
    # Exit true
    return true
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when ensuring the player is in the HQ Map)
  #--------------------------------------------------------------------------
  def update_hq_entry
    # Exit if not using HQ Entry input
    return unless Input.trigger?(Vehicles::HQ_INPUT)
    # Obtain current vehicle key
    v_key = $game_system.vehicle_current
    # Exit unless the vehicle has a HQ
    return unless Vehicles::HEADQUARTERS.has_key?(v_key)
    # Create stored vehicle array
    vehicle_array = [$game_map.map_id, @x, @y, @direction, nil]
    # Save it and other data to Game_System
    $game_system.vehicle_object.vehicle[v_key]  = vehicle_array
    $game_system.vehicle_current              = nil
    $game_party.actors[0].character_name      = $game_system.vehicle_character
    $game_player.move_speed                   = $game_system.vehicle_char_speed
    # Retrieve Original Sound (unless in Auto-Change BGS)
    sound_set = $game_system.v_sound
    if sound_set.nil?
      $game_system.bgs_stop
      $game_system.playing_bgs = nil
    end
    # Playback Sound
    vehicle_sound_playback(sound_set)
    # Check if menu was already disabled
    unless $game_system.menu_was_disabled == true
      # Re-Enable Menu
      $game_system.menu_disabled = false
    end
    # Vehicle Animation is turned off
    @step_anime = false
    # Set transferring player flag
    $game_temp.player_transferring = true   
    hq_map = Vehicles::HEADQUARTERS[v_key]
    # Set player move destination
    $game_temp.player_new_map_id    = hq_map[0] # MapID
    $game_temp.player_new_x         = hq_map[1] # X
    $game_temp.player_new_y         = hq_map[2] # Y
    $game_temp.player_new_direction = hq_map[3] # Direction
    if hq_map[4] == true                        # Fade
      # Prepare for transition
      Graphics.freeze
      # Set transition processing flag
      $game_temp.transition_processing = true
      $game_temp.transition_name = ""
    end
    # Don't flag refresh.  Force it.
    $game_player.refresh
    $game_map.need_refresh == true
    $game_map.refresh
    @through = false
    # Reveal squad members if present
    update_vehicle_squad_reveal
    # Exit Method
    return
  end 
  #--------------------------------------------------------------------------
  # * Frame Update (when actively boarding a vehicle)
  #     key      : vehicle key
  #     event_id : event ID
  #--------------------------------------------------------------------------
  def update_vehicle_board(key, event_id)   
    # Activate Vehicle Boarding flag
    @veh_boarding = true
    # Set the key   
    $game_system.vehicle_current  = key
    @v_event_id = event_id
    $game_system.vehicle_event_through = false
    if $game_map.events[event_id].through == true
      $game_system.vehicle_event_through = true
    end
    update_stop
    @v_wait_count = 4
    # Flag if menu already disabled
    $game_system.menu_was_disabled = $game_system.menu_disabled
    # Disable menu
    $game_system.menu_disabled = true
    # Hide squad members if present
    update_vehicle_squad_conceal
    # Permit player to walk into/through if behavior set
    return unless Vehicles::BEHAVIOR.has_key?(key)
    if Vehicles::BEHAVIOR[key][0] == true
      @through = true
      move_forward
      # Set Wait Count
      @v_wait_count = 15
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when concealing squad members - Enhanced Squad Addendum)
  #-------------------------------------------------------------------------- 
  def update_vehicle_squad_conceal
    # Exit method if Enhanced Squad Movement not detected
    return unless $game_system.e_squad_detect == true
    # Loop all allies
    for ally in $game_system.allies.values
      # If testing an active party member on the map
      if ally.force_wait == false && ($game_map.map_id == ally.map_id)
        # Set Wait Flag for Vehicle System
        ally.vehicle_wait = true
      end
    end   
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when revealing squad members - Enhanced Squad Addendum)
  #--------------------------------------------------------------------------
  def update_vehicle_squad_reveal
    # Exit method if Enhanced Squad Movement not detected
    return unless $game_system.e_squad_detect == true
    # Loop all allies
    for ally in $game_system.allies.values
      # If testing an active party member on the map
      if ally.force_wait == false && ($game_map.map_id == ally.map_id)
        # Disable Wait Flag for Vehicle System
        ally.vehicle_wait = false
        # Force ally to player position
        ally.moveto(@x, @y)
      end
    end   
  end
  #--------------------------------------------------------------------------
  # * Exit the HQ Map
  #     key : vehicle Key
  #--------------------------------------------------------------------------
  def hq_exit(key=nil)
    # Exit if no valid key passed
    return false if key.nil?
    # Exit if no valid Vehicle
    return unless Vehicles::VEHICLE.has_key?(key)   
    $game_system.vehicle_current = key
    # Reset the actor to new vehicle specs
    $game_party.actors[0].character_name  = Vehicles::VEHICLE[key][0]
    $game_system.vehicle_passage          = Vehicles::VEHICLE[key][1]
    $game_system.vehicle_disembark        = Vehicles::VEHICLE[key][2]
    $game_system.vehicle_through          = Vehicles::VEHICLE[key][3]
    $game_player.move_speed               = Vehicles::VEHICLE[key][4]
    # Set the switch if needed
    unless Vehicles::VEHICLE[key][5].nil?
      $game_switches[Vehicles::VEHICLE[key][5]] = true
    end
    # Set transferring player flag
    $game_temp.player_transferring = true
    # Set Vehicle map, postion and direction
    vehicle_array = $game_system.vehicle_object.vehicle[key]
    $game_temp.player_new_map_id    = vehicle_array[0]
    $game_temp.player_new_x         = vehicle_array[1]
    $game_temp.player_new_y         = vehicle_array[2]
    $game_temp.player_new_direction = vehicle_array[3]
    # Vehicle Animation is turned on
    @step_anime = true
    # Required Refreshes
    if Vehicles::HEADQUARTERS[key][4] == true
      # Prepare for transition
      Graphics.freeze
      # Set transition processing flag
      $game_temp.transition_processing = true
      $game_temp.transition_name = ""
    end   
    # Get Previously existing event id for disembarked vehicle
    v_id = $game_system.vehicle_object.vehicle[key][4]   
    # Only function if an actual event ID exists for vehicle
    unless v_id.nil?
      # Set Perma-Erase
      $game_temp.perma_erase = true   
      # Get map id for the map being transported
      map_id = $game_temp.player_new_map_id
      # Erase Event from Event Spawn list for that map
      if Event_Spawner.saved_events(map_id).has_key?(v_id)
        # Make sure we have 'through' flag saved before deletion
        $game_system.vehicle_event_through = false
        if Event_Spawner.saved_events(map_id)[v_id].pages[0].through == true
          $game_system.vehicle_event_through = true
        end   
        # Delete
        Event_Spawner.saved_events(map_id).delete(v_id)
      end
    end
    # Rehash/Refresh Event Spawn list
    Event_Spawner.saved_events.rehash
    # Set the music and sound
    vehicle_music(key)
    vehicle_sound(key)
    # Don't flag refresh.  Force it.
    $game_player.refresh
    $game_map.need_refresh == true
    $game_map.refresh
    @through = false
    # Hide squad members if present
    update_vehicle_squad_conceal
    # Exit Method
    return true
  end
  #--------------------------------------------------------------------------
  # * Change Vehicle Music
  #     key : vehicle Key
  #--------------------------------------------------------------------------
  def map_to_hq(key=nil)
    # Exit if no valid key passed
    return if key.nil?
    # Exit if no valid Vehicle HQ
    return unless Vehicles::HEADQUARTERS.has_key?(key)
    # Set Vehicle map, postion and direction
    vehicle_array = $game_system.vehicle_object.vehicle[key]
    # Map ID of vehicle being deleted
    map_id    = vehicle_array[0]
    # Obtain Vehicle Event ID
    mapdata = Game_Map.new
    mapdata = load_data(sprintf("Data/Map%03d.rxdata", map_id))   
    event_id = 0
    # Set map event data
    events = {}
    # Cycle through each event
    for i in mapdata.events.keys
      name = mapdata.events[i].name
      if name =~ Vehicles::VEHICLE_FORMULA
        #  Obtain key
        veh_key = $1
        # For valid vehicle keys only
        if Vehicles::VEHICLE.has_key?(veh_key)
          event_id = mapdata.events[i].id if veh_key = key
        end
      end
    end
    # Load map data from vehicle's own map
    map_data = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    # Search and erase vehicle from map
    events = {}
    for i in map_data.events.keys
      events[i] = Game_Event.new(map_id, map_data.events[i])
      events[i].erase if events[i].id == event_id
    end   
    # Save map data back to vehicle's own map
    save_data(map_data, sprintf("Data/Map%03d.rxdata", map_id))
    # Setup a temp version
    map_event_temp = []
    # Push current map's list into array if it exists
    if $game_map.current_map_event_list.has_key?(map_id)
      map_event_temp = $game_map.current_map_event_list[map_id]
    end
    # Erase ID if it exists in array
    map_event_temp.delete(event_id) if map_event_temp.include?(event_id)
    # Reapply
    $game_map.current_map_event_list[map_id] = map_event_temp
    # Store the actor and initial key data as if previously boarded
    $game_system.vehicle_character        = $game_party.actors[0].character_name
    $game_system.vehicle_char_speed       = $game_player.move_speed
    # Set the music and sound
    vehicle_music(key)
    vehicle_sound(key)
    # Retrieve Original Music (unless in Auto-Change BGM)
    sound_set = $game_system.v_sound
    if sound_set.nil?
      $game_system.bgs_stop
      $game_system.playing_bgs = nil
    end
    # Playback Music
    vehicle_sound_playback(sound_set)   
    $game_system.vehicle_current = nil
    # Set transferring player flag
    $game_temp.player_transferring = true   
    hq_map = Vehicles::HEADQUARTERS[key]
    # Set player move destination
    $game_temp.player_new_map_id    = hq_map[0] # MapID
    $game_temp.player_new_x         = hq_map[1] # X
    $game_temp.player_new_y         = hq_map[2] # Y
    $game_temp.player_new_direction = hq_map[3] # Direction
    # Don't flag refresh.  Force it.
    $game_player.refresh
    $game_map.need_refresh == true
    $game_map.refresh   
    @through = false     
    # Reveal squad members if present
    update_vehicle_squad_reveal
    # Exit Method
    return
  end 
  #--------------------------------------------------------------------------
  # * Change Vehicle Music
  #--------------------------------------------------------------------------
  def vehicle_music(key)
    # Save the original music playing
    $game_system.v_music = orig_audio_process($game_system.playing_bgm)
    # Ignore if not set
    return unless Vehicles::SOUND.has_key?(key)
    # Play vehicle BGM
    return if Vehicles::SOUND[key][0].nil?
    music_set = Vehicles::SOUND[key][0]
    vehicle_music_playback(music_set)
  end 
  #--------------------------------------------------------------------------
  # * Change Vehicle Music
  #--------------------------------------------------------------------------
  def vehicle_sound(key)
    # Save the original music playing
    $game_system.v_sound = orig_audio_process($game_system.playing_bgs)
    # Ignore if not set
    return unless Vehicles::SOUND.has_key?(key)
    # Play vehicle BGM
    return if Vehicles::SOUND[key][1].nil?
    sound_set = Vehicles::SOUND[key][1]
    vehicle_sound_playback(sound_set)
  end   
  #--------------------------------------------------------------------------
  # * Obtain original Map Audio
  #--------------------------------------------------------------------------
  def orig_audio_process(value_name)
    result = nil
    return result if value_name.nil?
    n = value_name.name
    v = value_name.volume
    p = value_name.pitch
    result = [n,v,p]
    return result
  end
  #--------------------------------------------------------------------------
  # * Music Playback
  #--------------------------------------------------------------------------
  def vehicle_music_playback(music_set)
    return if music_set.nil?
    # Extract from array
    music_f   = music_set[0]  # File
    music_v   = music_set[1]  # Volume
    music_p   = music_set[2]  # Pitch       
    # For default values
    music_v = 100   if music_v.nil?
    music_p = 100   if music_p.nil?
    # Ensure valid Music File
    begin
      @trd = RPG::AudioFile.new(music_f)
      Audio.bgm_play("Audio/BGM/" + @trd.name, 0, 100)
    rescue Errno::ENOENT
      # Music file is invalid (restore default)
      music_f = nil
    end
    # Play the Music File
    return if music_f.nil?
    # Recombine into audio format
    music = RPG::AudioFile.new
    music.name   = music_f
    music.volume = music_v
    music.pitch  = music_p
    # Pass to master system
    $game_system.bgm_play(music)
  end
  #--------------------------------------------------------------------------
  # * Music Playback
  #--------------------------------------------------------------------------
  def vehicle_sound_playback(sound_set)
    return if sound_set.nil?
    # Extract from array
    sound_f   = sound_set[0]  # File
    sound_v   = sound_set[1]  # Volume
    sound_p   = sound_set[2]  # Pitch       
    # For default values
    sound_v = 100   if sound_v.nil?
    sound_p = 100   if sound_p.nil?
    # Ensure valid Music File
    begin
      @trd = RPG::AudioFile.new(sound_f)
      Audio.bgs_play("Audio/BGS/" + @trd.name, 0, 100)
    rescue Errno::ENOENT
      # Music file is invalid (restore default)
      sound_f = nil
    end
    # Play the Music File
    return if sound_f.nil?
    # Recombine into audio format
    sound = RPG::AudioFile.new
    sound.name   = sound_f
    sound.volume = sound_v
    sound.pitch  = sound_p
    # Pass to master system
    $game_system.bgs_play(sound)
  end
end



#==============================================================================
# ** Game_Vehicles
#------------------------------------------------------------------------------
#  This class holds some arbitrary data you wish to use and store.
#==============================================================================

class Game_Vehicles
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :vehicle                  # Vehicle Map ID
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Vehicle Data
    @vehicle  = {}
  end
end



#==============================================================================
# ** Game_Ally
#------------------------------------------------------------------------------
#  This class handles active party members.  Its functions keep the members
#  following the player unless acted upon. Refer to "$game_system.allies" for
#  each instance of this class.
#==============================================================================

class Game_Ally < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :vehicle_wait                # Force wait for vehicle system
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Unless not on the current map
    if $game_system.e_squad_detect == true
      unless @map_id != $game_map.map_id
        @transparent = false
        if @vehicle_wait == true
          @transparent = true
          moveto($game_player.x, $game_player.y)
          return
        end
      end
    end
    # Exit with original parent system if ally set with move route flag
    return super if @wait_move_route == true
    # Exit if ally waiting
    return if @force_wait == true
    # Exit if not in the same map
    return if @map_id != $game_map.map_id
    # Regroup proper and active allies if 'stuck'
    update_autoregroup
    # Handle ally speed and move frequency
    update_speed_and_frequency
    update_moving if !moving?
    # Inherit method remainder from parent class
    super
  end
end



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

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias vehicle_scene_map_main main
  alias vehicle_scene_map_update update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Start Vehicles
    attach_vehicles
    # Test for Allies
    $game_system.e_squad_detect = true if defined?(main_allies_start)
    # Perform the original call
    vehicle_scene_map_main
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Reset encounter flag
    no_enc_tag  = false
    # Acquire revised flag if in a vehicle
    unless $game_system.vehicle_current.nil?
      key =  $game_system.vehicle_current
      if Vehicles::BEHAVIOR.has_key?(key)
        no_enc_tag  = true unless Vehicles::BEHAVIOR[key][1] == true
      end
    end
    # Reset 'count' to start (prevent encounters) if flag is true
    if no_enc_tag == true
      $game_player.encounter_count  = $game_map.encounter_step
    end
    # Perform the original call
    vehicle_scene_map_update
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Installing Vehicles Object
  #--------------------------------------------------------------------------
  def attach_vehicles
    # Exit method if vehicle already available
    return unless $game_system.vehicle_object.nil?
    # This attaches the vehicle into Game_System
    $game_system.vehicle_object = Game_Vehicles.new
    # Load list of all maps in game
    infos        = load_data("Data/MapInfos.rxdata")
    # Cycle through each map from list
    for key in infos.keys
      # Obtain data from map
      mapdata = Game_Map.new
      mapdata = load_data(sprintf("Data/Map%03d.rxdata", key))
      # Set map event data
      events = {}
      # Cycle through each event
      for i in mapdata.events.keys
        name = mapdata.events[i].name
        next unless name =~ Vehicles::VEHICLE_FORMULA
        #  Obtain key
        veh_key = $1
        # For valid vehicle keys only
        next unless Vehicles::VEHICLE.has_key?(veh_key)
        # Obtain Event Map, positions and direction
        e_k = key
        e_x = mapdata.events[i].x
        e_y = mapdata.events[i].y
        e_d = mapdata.events[i].pages[0].graphic.direction
        # Create Array
        vehicle_array = [e_k, e_x, e_y, e_d]
        # Insert into Vehicle Object
        $game_system.vehicle_object.vehicle[veh_key] = vehicle_array
      end
    end
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/rmxp-vehicle-script-error.122118/