Vehicle Call Script 2.0
Provided by BigEd781
Updated
- Now call any vehicle
IntroductionThis is a simple script that will allow you to call any vehicle from the map with an animation.
This is most useful for something like an item that can call a vehicle from anywhere.
Anyone can use this script, I don't care about credit in your game, but if you do post it on another forum please attribute the script to me.
Features-> Easy to use, two line script call.
-> Reliable, will only call the vehicle if it is appropriate. Otherwise, an error message is displayed.
-> Shows an animation when the vehicle is called.
-> Easily configurable.
How To UsePlace the script in the materials section. To call the vehicle, use the "Script..." event command and use this code:
CODE
vehicle_caller = Vehicle_Caller.new
Depending on which vehicle you would like to call, place one of the following lines after "vehicle_caller = Vehicle_Caller.new".
Boat:
CODE
vehicle_caller.call_boat
Ship:
CODE
vehicle_caller.call_ship
Airship:
CODE
vehicle_caller.call_airship
ConfigurationThere are really only three things to configure currently. These can be found in the beginning of the script, in the CONFIGURE module.
CODE
module CONFIG
#----------------------------------------------------------------------------
# Configuration Settings
#----------------------------------------------------------------------------
#World Map map id to control when the airship can be called
WORLD_MAP_IDs = [1]
#Change these to show a different animation using the database id
BOAT_ANIMATION_ID = 75
SHIP_ANIMATION_ID = 75
AIRSHIP_ANIMATION_ID = 75
#Change this to alter the error message
B_ERROR_TEXT = ['',' You cannot call the boat from here']
S_ERROR_TEXT = ['',' You cannot call the ship from here']
A_ERROR_TEXT = ['',' You cannot call the airship from here']
end
WORLD_MAP_ID - This is an array of map ids from which the airship can be called. This is used so that the player cannot call the airship from any map but those designated by you as ok.
To add to this array, just use a comma and the new map id, like so:
CODE
WORLD_MAP_IDs = [1, 2, 3]
Now you can call the airship from map 1, 2, or 3.
BOAT_ANIMATION_ID - This is the animation that is displayed when the boat is called. Uses the database id.
SHIP_ANIMATION_ID - This is the animation that is displayed when the ship is called. Uses the database id.
AIRSHIP_ANIMATION_ID - This is the animation that is displayed when the airship is called. Uses the database id.
B_ERROR_TEXT - The text displayed when the user attempts to call the boat from an invalid location.
S_ERROR_TEXT - The text displayed when the user attempts to call the ship from an invalid location.
A_ERROR_TEXT - The text displayed when the user attempts to call the airship from an invalid location.
The error text is a string array. The first entry (the \'\') is just a line break.
Change the text after that, between the two apostrophes (\') to change what is displayed.
The extra spaces are just padding so that the text is centered. I am sure there is a function for this, but I couldn't find one (quickly), so meh.
Demo and ScreenshotsNot really necessary.
ScriptCODE
module CONFIG
#----------------------------------------------------------------------------
# Configuration Settings
#----------------------------------------------------------------------------
#World Map map id to control when the airship can be called
WORLD_MAP_IDs = [1]
#Change these to show a different animation using the database id
BOAT_ANIMATION_ID = 75
SHIP_ANIMATION_ID = 75
AIRSHIP_ANIMATION_ID = 75
#Change this to alter the error message
B_ERROR_TEXT = ['',' You cannot call the boat from here']
S_ERROR_TEXT = ['',' You cannot call the ship from here']
A_ERROR_TEXT = ['',' You cannot call the airship from here']
end
class Vehicle_Caller
def initialize
@vehicle_loc = nil
end
def show_error_message(message)
unless $game_message.busy
$game_message.position = 1
$game_message.texts = message
$game_message.visible = true
end
end
def call_boat
px = $game_player.x
py = $game_player.y
#Check the tiles surrounding the player.
#and see if the boat can pass through the tile.
#If it can, place it there.
if $game_map.boat_passable?(px, py - 1) #up
@vehicle_loc = [px, py - 1]
elsif $game_map.boat_passable?(px + 1, py) #right
@vehicle_loc = [px + 1, py]
elsif $game_map.boat_passable?(px, py + 1) #down
@vehicle_loc = [px, py + 1]
elsif $game_map.boat_passable?(px - 1, py) #left
@vehicle_loc = [px - 1, py]
else
@vehicle_loc = nil
end
if @vehicle_loc != nil
#Set the boat location
$game_map.vehicles[0].set_location(
$game_map.map_id, @vehicle_loc[0], @vehicle_loc[1])
$game_map.vehicles[0].animation_id = CONFIG::BOAT_ANIMATION_ID
else
#nowhere to put the boat, show an error message
show_error_message(CONFIG::B_ERROR_TEXT)
end
end
def call_ship
px = $game_player.x
py = $game_player.y
#Check the tiles surrounding the player.
#and see if the ship can pass through the tile.
#If it can, place it there.
if $game_map.ship_passable?(px, py - 1) #up
@vehicle_loc = [px, py - 1]
elsif $game_map.ship_passable?(px + 1, py) #right
@vehicle_loc = [px + 1, py]
elsif $game_map.ship_passable?(px, py + 1) #down
@vehicle_loc = [px, py + 1]
elsif $game_map.ship_passable?(px - 1, py) #left
@vehicle_loc = [px - 1, py]
else
@vehicle_loc = nil
end
if @vehicle_loc != nil
#Set the ship location
$game_map.vehicles[1].set_location(
$game_map.map_id, @vehicle_loc[0], @vehicle_loc[1])
$game_map.vehicles[1].animation_id = CONFIG::SHIP_ANIMATION_ID
else
#nowhere to put the ship, show an error message
show_error_message(CONFIG::S_ERROR_TEXT)
end
end
def call_airship
px = $game_player.x
py = $game_player.y
#if this a world map...
if CONFIG::WORLD_MAP_IDs.include?($game_map.map_id)
#...check the tiles surrounding the player.
#if a tile is passable when the 0x01 flag is passed
#to the function, the player can walk there. If that is true,
#we then check to see if the airship could land there.
#After that, make sure that there is no event on that tile.
#If these conditions are all true, place it there.
if $game_map.passable?(px, py - 1, 0x01) and #up
$game_map.airship_land_ok?(px, py - 1)and #can land
$game_map.events_xy(px, py - 1) == [] #no event
@vehicle_loc = [px, py - 1]
elsif $game_map.passable?(px + 1, py, 0x01) and #right
$game_map.airship_land_ok?(px + 1, py)and #can land
$game_map.events_xy(px + 1, py) == [] #no event
@vehicle_loc = [px + 1, py]
elsif $game_map.passable?(px, py + 1, 0x01) and #down
$game_map.airship_land_ok?(px, py + 1)and #can land
$game_map.events_xy(px, py + 1) == [] #no event
@vehicle_loc = [px, py + 1]
elsif $game_map.passable?(px - 1, py, 0x01) and #left
$game_map.airship_land_ok?(px - 1, py)and #can land
$game_map.events_xy(px - 1, py) == [] #no event
@vehicle_loc = [px - 1, py]
else
@vehicle_loc = nil
end
else
show_error_message(CONFIG::A_ERROR_TEXT)
return
end
if @vehicle_loc != nil
#Set the airship location
$game_map.vehicles[2].set_location(
$game_map.map_id, @vehicle_loc[0], @vehicle_loc[1])
$game_map.vehicles[2].animation_id = CONFIG::AIRSHIP_ANIMATION_ID
else
#nowhere to put the airship, show an error message
show_error_message(CONFIG::A_ERROR_TEXT)
end
end
end
Future PlansWell...there are none. I am pretty busy, but I will take feature requests if there are any.
There is one behavior that could be considered a glitch. The tile that is chosen for the vehicle location is simply the first valid one.
So, this means that if you were surrounded by valid tiles, the boat would always appear above the player (the script checks surrounding tiles in a counter clockwise fashion).
If this
really needed to be fixed, I could check which way the player is facing, but I don't think it is necessary.