This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Aha! I have returned! And I have arrived with the first true adaptable
fairly easy to use Vehicle script! This script is preset to be similar to
previous RPG makers with a boat, ship, etc that work like they should.
Also, this script makes it easy to define and create your own vehicles.
RMXP lacks vehicle character graphics, so I used what I could find in
the default charsets. Read the documentation in the beginning of this
script to learn more about how to use it.
#----------------------------------------------------------------------------
# What it Does:
# This script creates usable vehicles that can be set to cross certian
# terrain tagged tiles. Three vehicles are predefined, a Land Rover, a
# a Sea Rover, and a Sky Rover. This script also makes it easy to define
# your own vehicles. You can even take any vehicle across to other maps.
# As of version 2.0, vehicles now have their own BGM and speeds.
#
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# How it Works: This script is organized into 5 small parts.
#
# Part 1 defines Vehicles and sets up the database.
#
# class Vehicle defines a new object (the vehicle)
# Its attributes are as follows.
# - id : As its name implies it is the Vehicle's ID
# - name : The Name of the Vehicle
# - graphic_name : The name of the character graphic that will
# represent the vehicle
# - location : Map ID of where vehicle is located
# - x : Vehicle's x coordinate
# - y : Vehicle's y coordinate
# - speed : Vehicle's movement speed
# - bgm : Name of vehicles music file
# - passable_terrains: An array of terrain tag ID's that vehicle
# can cross
#
# class Data_Vehicles is the database where all the games vehicles
# are defined. The vehicles are set up in an array and assigned to
# a Constant. Define your Vehicles within the array like so:
#
# Vehicle.new(id, name, graphic_name, location, x, y, speed, bgm,
# passable_terrains)
#
# All the classes that are new or had to be altered are as follows:
#
# Part I
# - RPG::Vehicle
# - Game_Vehicle
# Part II
# - Game_Map
# - Spriteset_Map
# Part III
# - Game_Character 1
# - Game_Player
# Part IV
# - Scene_Map
# - Scene_Menu
# Part V
# - Scene_Title
# - Scene_Save
# - Scene_Load
#
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# How to Use This Script:
# Copy it and paste it above Main.
#
# All you need to do is go under the tilesets tab of RPG Maker set the
# tiles you want to have with a certian ID.
#
# The terrain tags my preset vehicles respond to are: (7) for arial,
# (6) for sea, and (1), (2), and (3) for various ground.
#
# You can create new vehicles under the Module RPG Data-Vehicles class.
# There you can specify what tag numbers they can cross. Just remeber,
# any tag number that you do not include is NOT passable. The tags range
# from 0-7. The RPG Maker default tags for everything is 0.
#
#
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# Comments:
# I hope my script is easy for you to use and modify. Study this script
# to learn the magical arts RGSS!
#
#----------------------------------------------------------------------------
#******************************************************************************
# I Part One
#------------------------------------------------------------------------------
# This part deals with the definition of the vehicle objects
# and sets up the Vehicle Database.
#******************************************************************************
#==============================================================================
# ** Module RPG
#------------------------------------------------------------------------------
# This is where most of the games internal data is stored.
#==============================================================================
module RPG
#==============================================================================
# ** Vehicle
#------------------------------------------------------------------------------
# This class defines the Vehicle object.
#==============================================================================
class Vehicle
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :id
attr_accessor :name
attr_accessor :graphic_name
attr_accessor :starting_location
attr_accessor :starting_x
attr_accessor :starting_y
attr_accessor :location
attr_accessor :x
attr_accessor :y
attr_accessor :speed
attr_accessor :bgm
attr_accessor :passable_terrain
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(id, name, graphic_name, location, x, y, speed, bgm_name,
passable_terrain = [])
# Set parameters
@id = id
@name = name
@graphic_name = graphic_name
@starting_location = location
@starting_x = x
@starting_y = y
@location = 0
@x = 0
@y = 0
@speed = speed
@bgm = RPG::AudioFile.new(bgm_name, 100, 100)
@passable_terrain = passable_terrain
end
end
#==============================================================================
# ** Vehicle_Data
#------------------------------------------------------------------------------
# Stores all the games Vehicle_Data data.
#==============================================================================
class Data_Vehicles
# This is the Vehicle database
# Define new Vehicles like so;
# Vehicle.new(id, name, graphic_name, location, x, y, passable_terrains)
#******************************************************************************
# II Part Two
#------------------------------------------------------------------------------
# This part deals with map classes that had to be altered to accomadate the
# vehicle capabilities.
#******************************************************************************
class Game_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
# Added variable
attr_reader :vehicles
#--------------------------------------------------------------------------
# * Alias Method
#--------------------------------------------------------------------------
alias vehicle_game_map_setup setup
alias vehicle_game_map_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def setup(map_id)
# Original setup method
vehicle_game_map_setup(map_id)
# Added vehicles array
# This array stores all the vehicles in the map
@vehicles = []
# For all the vehicles in $data_vehicles array,
for i in 0...$data_vehicles.size
# If the vehicle's location is equal to the id of the current map
if @map_id == $data_vehicles[i].location
# Add a new vehicle to the map by creating a new Game_Vehicle
# object and sending it to the map vehicles array
@vehicles.push(Game_Vehicle.new($data_vehicles[i].id))
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Original update method
vehicle_game_map_update
for vehicle in @vehicles
vehicle.update
end
end
end
class Spriteset_Map
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# Make tilemap
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
# Make panorama plane
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
# Make fog plane
@fog = Plane.new(@viewport1)
@fog.z = 3000
# Make character sprites
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
# For all indexes in game map vehicles array
for i in 0...$game_map.vehicles.size
# Create a new character sprite for vehicle from index i
sprite = Sprite_Character.new(@viewport1, $game_map.vehicles[i])
@character_sprites.push(sprite)
end
# Make weather
@weather = RPG::Weather.new(@viewport1)
# Make picture sprites
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end
end
#******************************************************************************
# III Part Three
#------------------------------------------------------------------------------
# This part contains the new Game_Vehicle class and modifications to the
# standard character classes to deal with vehicles.
#******************************************************************************
#==============================================================================
# ** Game_Vehicle
#------------------------------------------------------------------------------
# Usable vehicles on map are instances of this class.
#==============================================================================
class Game_Vehicle < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :map_id
attr_accessor :passable_terrain
attr_accessor :through
attr_accessor :id
attr_accessor :move_speed
attr_accessor :bgm
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(vehicle_id)
super()
vehicle = $data_vehicles[vehicle_id]
@id = vehicle.id
@character_name = vehicle.graphic_name
@move_speed = vehicle.speed
@map_id = vehicle.location
@passable_terrain = vehicle.passable_terrain
@bgm = vehicle.bgm
if $game_player.current_vehicle != nil
@through = true
end
moveto(vehicle.x, vehicle.y)
end
#--------------------------------------------------------------------------
# * Embark
#--------------------------------------------------------------------------
def embark
self.through = true
end
#--------------------------------------------------------------------------
# * Dismbark
#--------------------------------------------------------------------------
def disembark
self.through = false
$data_vehicles[self.id].x = @x
$data_vehicles[self.id].y = @y
end
#--------------------------------------------------------------------------
# * Don't delete this! Or you will get errors!
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
# This is put here to do nothing.
# It is difficult to explain why this is neccessary.
end
end
class Game_Character
#--------------------------------------------------------------------------
# * 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)
# Get new coordinates
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# If coordinates are outside of map
unless $game_map.valid?(new_x, new_y)
# impassable
return false
end
# If through is ON
if @through
# passable
return true
end
# If unable to leave first move tile in designated direction
unless $game_map.passable?(x, y, d, self)
# impassable
return false
end
# If unable to enter move tile in designated direction
unless $game_map.passable?(new_x, new_y, 10 - d)
# impassable
return false
end
# Check for all vehicles in $game_map vehicles array
for vehicle in $game_map.vehicles
# If vehicle coordinates are equal to destination coordinates
if vehicle.x == new_x and vehicle.y == new_y
# Make impassable unless vehicle is set to through
unless vehicle.through == true
return false
end
end
end
# Loop all events
for event in $game_map.events.values
# If event coordinates are consistent with move destination
if event.x == new_x and event.y == new_y
# If through is OFF
unless event.through
# If self is event
if self != $game_player
# impassable
return false
end
# With self as the player and partner graphic as character
if event.character_name != ""
# impassable
return false
end
end
end
end
# If player coordinates are consistent with move destination
if $game_player.x == new_x and $game_player.y == new_y
# If through is OFF
unless $game_player.through
# If your own graphic is the character
if @character_name != ""
# impassable
return false
end
end
end
# passable
return true
end
end
class Game_Player < Game_Character
#------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
# Added variables
attr_accessor :current_vehicle
attr_accessor :graphic
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super()
@current_vehicle = nil;
end
#--------------------------------------------------------------------------
# * Passable Determinants
# 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)
# Get new coordinates
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# If coordinates are outside of map
unless $game_map.valid?(new_x, new_y)
# Impassable
return false
end
# If debug mode is ON and ctrl key was pressed
if $DEBUG and Input.press?(Input::CTRL)
# Passable
return true
end
# If player has a vehicle
# Check if the player's vehicle can cross the terrain tag coordinate
if @current_vehicle != nil
# If the vehicle's passable_terrain array cotains the ID of the terrain tag
if @current_vehicle.passable_terrain.include?($game_map.terrain_tag(new_x, new_y))
# Then player can cross
return true
else
return false
end
end
super
end
#--------------------------------------------------------------------------
# * Passable Determinants
# x : x-coordinate
# y : y-coordinate
# d : direction (0,2,4,6,8)
# * 0 = Determines if all directions are impassable (for jumping)
#--------------------------------------------------------------------------
def passable_without_vehicle?(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)
# If coordinates are outside of map
unless $game_map.valid?(new_x, new_y)
# Impassable
return false
end
# If debug mode is ON and ctrl key was pressed
if $DEBUG and Input.press?(Input::CTRL)
# Passable
return true
end
# If through is ON
if @through
# passable
return true
end
# If unable to leave first move tile in designated direction
unless $game_map.passable?(x, y, d, self)
# impassable
return false
end
# If unable to enter move tile in designated direction
unless $game_map.passable?(new_x, new_y, 10 - d)
# impassable
return false
end
# Loop all vehicles
for vehicle in $game_map.vehicles
if vehicle.x == new_x and vehicle.y == new_y
unless vehicle.through == true
return false
end
end
end
# Loop all events
for event in $game_map.events.values
# If event coordinates are consistent with move destination
if event.x == new_x and event.y == new_y
# If through is OFF
unless event.through
# If self is event
if self != $game_player
# impassable
return false
end
# With self as the player and partner graphic as character
if event.character_name != ""
# impassable
return false
end
end
end
end
# If player coordinates are consistent with move destination
if $game_player.x == new_x and $game_player.y == new_y
# If through is OFF
unless $game_player.through
# If your own graphic is the character
if @character_name != ""
# impassable
return false
end
end
end
# passable
return true
end
#--------------------------------------------------------------------------
# * Move Down
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# Turn down
if turn_enabled
turn_down
if @current_vehicle != nil
@current_vehicle.turn_down
end
end
# If passable
if passable?(@x, @y, 2)
# Turn down
turn_down
# Move both player and vehicle
if @current_vehicle != nil
@current_vehicle.move_down
end
# Update coordinates
@y += 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y+1)
end
end
#--------------------------------------------------------------------------
# * Move Left
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# Turn left
if turn_enabled
turn_left
if @current_vehicle != nil
@current_vehicle.turn_left
end
end
# If passable
if passable?(@x, @y, 4)
# Turn left
turn_left
# Move both player and vehicle
if @current_vehicle != nil
@current_vehicle.move_left
end
# Update coordinates
@x -= 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x-1, @y)
end
end
#--------------------------------------------------------------------------
# * Move Right
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# Turn right
if turn_enabled
turn_right
if @current_vehicle != nil
@current_vehicle.turn_right
end
end
# If passable
if passable?(@x, @y, 6)
# Turn right
turn_right
# Move both player and vehicle
if @current_vehicle != nil
@current_vehicle.move_right
end
# Update coordinates
@x += 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x+1, @y)
end
end
#--------------------------------------------------------------------------
# * Move up
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# Turn up
if turn_enabled
turn_up
if @current_vehicle != nil
@current_vehicle.turn_up
end
end
# If passable
if passable?(@x, @y, 8)
# Turn up
turn_up
# Move both player and vehicle
if @current_vehicle != nil
@current_vehicle.move_up
end
# Update coordinates
@y -= 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y-1)
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Remember whether or not moving in local variables
last_moving = moving?
# If moving, event running, move route forcing, and message window
# display are all not occurring
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
# Move player in the direction the directional button is being pressed
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
end
# Remember coordinates in local variables
last_real_x = @real_x
last_real_y = @real_y
super
# If character moves down and is positioned lower than the center
# of the screen
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
# Scroll map down
$game_map.scroll_down(@real_y - last_real_y)
end
# If character moves left and is positioned more let on-screen than
# center
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
# Scroll map left
$game_map.scroll_left(last_real_x - @real_x)
end
# If character moves right and is positioned more right on-screen than
# center
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
# Scroll map right
$game_map.scroll_right(@real_x - last_real_x)
end
# If character moves up and is positioned higher than the center
# of the screen
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
# Scroll map up
$game_map.scroll_up(last_real_y - @real_y)
end
# If not moving
unless moving?
# If player was moving last time
if last_moving
# Event determinant is via touch of same position event
result = check_event_trigger_here([1,2])
# If event which started does not exist
if result == false
# Disregard if debug mode is ON and ctrl key was pressed
unless $DEBUG and Input.press?(Input::CTRL)
# Encounter countdown
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
# If C button was pressed
if Input.trigger?(Input::C)
# Same position and front event determinant
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
check_vehicle_trigger_there
end
# If A button was pressed
if Input.trigger?(Input::A)
# If player is in a vehicle, dismount vehicle
unless $game_player.current_vehicle == nil
# Calculate front event coordinates
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# Check if player can dismount on a passable terrain
if passable_without_vehicle?(new_x, new_y, @direction)
dismount_vehicle
end
end
end
end
end
#--------------------------------------------------------------------------
# * Front Vehicle Starting Determinant
#--------------------------------------------------------------------------
def check_vehicle_trigger_there()
result = false
# If event is running
if $game_system.map_interpreter.running?
return result
end
# Calculate front event coordinates
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# If event coordinates and triggers are consistent
# For all possible vehicles in map
for vehicle in $game_map.vehicles
# Check if vehicle is in front of player to enter it.
if vehicle.x == new_x and vehicle.y == new_y
#If so, make sure that player isn't already in a vehicle
unless @current_vehicle != nil
mount_vehicle(vehicle)
result = true
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Get in vehicle
#--------------------------------------------------------------------------
def mount_vehicle(vehicle)
@graphic = @character_name
vehicle.embark
@through = true
move_forward
$game_system.bgm_play(vehicle.bgm)
@through = false
@current_vehicle = vehicle
@character_name = ""
@move_speed = vehicle.move_speed
end
#--------------------------------------------------------------------------
# * Get out of vehicle
#--------------------------------------------------------------------------
def dismount_vehicle
@character_name = @graphic
@current_vehicle.disembark
@current_vehicle = nil
@through = true
move_forward
$game_map.autoplay
@through = false
@move_speed = 4
end
end
#******************************************************************************
# IV Part Four
#------------------------------------------------------------------------------
# This part contains modifications to the Scene_Map and Scene_Menu.
#******************************************************************************
#============================================================================
# ** Scene_Map
#----------------------------------------------------------------------------
# Altered to handle transfering both player and vehicle.
#============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Player Place Move
#--------------------------------------------------------------------------
def transfer_player
# Clear player place move call flag
$game_temp.player_transferring = false
# If move destination is different than current map
if $game_map.map_id != $game_temp.player_new_map_id
# If player is in a vehicle
if $game_player.current_vehicle != nil
# Set variable to $data_vehicles vehicle at player's current ID index.
vehicle = $data_vehicles[$game_player.current_vehicle.id]
# Set variable to player's vehicle ID for retrieval purposes later.
vehicle_id = $game_player.current_vehicle.id
# Set new location, x, and y coordinates for the vehicle
vehicle.location = $game_temp.player_new_map_id
vehicle.x = $game_temp.player_new_x
vehicle.y = $game_temp.player_new_y
# Set up a new map
$game_map.setup($game_temp.player_new_map_id)
# Loop through all vehicles located on the map
for i in 0...$game_map.vehicles.size
# If any of the vehicles ID is the same as the player's vehicle
if $game_map.vehicles[i].id == vehicle_id
# Assign that vehicle to player on the new map
$game_player.current_vehicle = $game_map.vehicles[i]
end
end
else
$game_map.setup($game_temp.player_new_map_id)
end
end
# Set up player position
$game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
# Set player direction
case $game_temp.player_new_direction
when 2 # down
$game_player.turn_down
when 4 # left
$game_player.turn_left
when 6 # right
$game_player.turn_right
when 8 # up
$game_player.turn_up
end
# Straighten player position
$game_player.straighten
# Update map (run parallel process event)
$game_map.update
# Remake sprite set
@spriteset.dispose
@spriteset = Spriteset_Map.new
# If processing transition
if $game_temp.transition_processing
# Clear transition processing flag
$game_temp.transition_processing = false
# Execute transition
Graphics.transition(20)
end
# Run automatic change for BGM and BGS set on the map
$game_map.autoplay
# Frame reset
Graphics.frame_reset
# Update input information
Input.update
end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# Saving disabled while in vehicle.
#==============================================================================
class Scene_Menu
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "Save"
s6 = "End Game"
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
@command_window.index = @menu_index
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
end
# If save is forbidden
if $game_system.save_disabled || $game_player.current_vehicle != nil
# Disable save
@command_window.disable_item(4)
end
# Make play time window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 0
@playtime_window.y = 224
# Make steps window
@steps_window = Window_Steps.new
@steps_window.x = 0
@steps_window.y = 320
# Make gold window
@gold_window = Window_Gold.new
@gold_window.x = 0
@gold_window.y = 416
# Make status window
@status_window = Window_MenuStatus.new
@status_window.x = 160
@status_window.y = 0
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
@playtime_window.dispose
@steps_window.dispose
@gold_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to item screen
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window.active = true
@status_window.index = 0
when 4 # save
# If saving is forbidden
if $game_system.save_disabled || $game_player.current_vehicle != nil
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to save screen
$scene = Scene_Save.new
when 5 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to end game screen
$scene = Scene_End.new
end
return
end
end
end
#******************************************************************************
# V Part Five
#------------------------------------------------------------------------------
# This part is composed of the alterations that deal with starting a new game
# saving, and loading.
#******************************************************************************
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# Added creation of $data_vehicles and initialiation of all vehicle
# starting positions.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
def command_new_game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Stop BGM
Audio.bgm_stop
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each type of game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Assign array to global variable
$data_vehicles = RPG::Data_Vehicles::Vehicle_Database
# Initialize vehicle starting positions
for vehicle in $data_vehicles
vehicle.x = vehicle.starting_x
vehicle.y = vehicle.starting_y
vehicle.location = vehicle.starting_location
end
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position
$game_map.setup($data_system.start_map_id)
# Move player to initial position
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
end
#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
# Now includes saving of $data_vehicles.
#==============================================================================
class Scene_Save < Scene_File
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
# Make character data for drawing save file
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
# Write character data for drawing save file
Marshal.dump(characters, file)
# Wrire frame count for measuring play time
Marshal.dump(Graphics.frame_count, file)
# Increase save count by 1
$game_system.save_count += 1
# Save magic number
# (A random value will be written each time saving with editor)
$game_system.magic_number = $data_system.magic_number
# Write each type of game object
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($data_vehicles, file)
end
end
#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
# Now includes loading of $data_vehicles.
#==============================================================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
def read_save_data(file)
# Read character data for drawing save file
characters = Marshal.load(file)
# Read frame count for measuring play time
Graphics.frame_count = Marshal.load(file)
# Read each type of game object
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
$data_vehicles = Marshal.load(file)
# If magic number is different from when saving
# (if editing was added with editor)
if $game_system.magic_number != $data_system.magic_number
# Load map
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# Refresh party members
$game_party.refresh
end
end