Super Simple Vehicle System & World Map

Introduction
This is a vehicle system that is similar to the Final Fantasy system. In this system, you get vehicles (a canoe, ship, and dragon), the world tileset for Aveyond 2 (free to use in freeware games), and some autotiles.

Demo
You can download the demo here: DOWNLOAD VEHICLE SYSTEM DEMO HERE

Screenshot
Image

Script
You really should download the demo, becuase this system uses a mixture of script, map events, common events, variables, and switches. However, if you think you can figure it out on your own, here is the vehicle system script:
Super Simple Vehicle System Spoiler
  1.  
  2. class Game_Character
  3.   def passable?(x, y, d)
  4.     
  5.      # Get new coordinates
  6.      new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  7.      new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  8.     
  9.      # If coordinates are outside of map
  10.      unless $game_map.valid?(new_x, new_y)
  11.         return false
  12.      end
  13.     
  14.      # If through is ON
  15.      if @through
  16.         return true
  17.      end
  18.           
  19.      # If unable to leave first move tile in designated direction
  20.      unless $game_map.passable?(x, y, d, self)
  21.         return false
  22.      end
  23.     
  24.      # If unable to enter move tile in designated direction
  25.      unless $game_map.passable?(new_x, new_y, 10 - d)
  26.         return false
  27.      end
  28.           
  29.      #check terrain for vehicle
  30.      check_terrain(new_x, new_y)      
  31.        
  32.      # Loop all events
  33.      for event in $game_map.events.values
  34.         # If event coordinates are consistent with move destination
  35.         if event.x == new_x and event.y == new_y
  36.            @state = true
  37.            # If through is OFF
  38.            unless event.through
  39.               # If self is event
  40.               if self != $game_player
  41.                  return false
  42.               end
  43.               # With self as the player and partner graphic as character
  44.               if event.character_name != ""
  45.                  return false
  46.               end
  47.            end
  48.         end
  49.      end
  50.     
  51.      if @state == false
  52.         return false
  53.      end         
  54.     
  55.      # If player coordinates are consistent with move destination
  56.      if $game_player.x == new_x and $game_player.y == new_y
  57.         # If through is OFF
  58.         unless $game_player.through
  59.            # If your own graphic is the character
  60.            if @character_name != ""
  61.               return false
  62.            end
  63.         end
  64.      end
  65.        
  66.     
  67.      return true
  68.     
  69.   end
  70.  
  71.   #--------------------------------------------------------------------------
  72.   # * Check the terrain for the vehicle
  73.   #    @terrain (0=none, 1=river, 2=ocean, 3=air, 4=ground)
  74.   #    @vehicle (0=foot, 1=canoe, 2=boat, 3=dragon)
  75.   #    @state (true=passable tile, false=unpassable tile)
  76.   #--------------------------------------------------------------------------
  77.   def check_terrain(new_x, new_y)   
  78.      @state = false
  79.      @terrain = $game_map.terrain_tag(new_x, new_y)
  80.      @vehicle = $game_variables[1]
  81.     
  82.      @state = true if @vehicle == 0 && @terrain == 4   #foot & ground
  83.      @state = true if @vehicle == 1 && @terrain == 3   #canoe & river
  84.      @state = true if @vehicle == 2 && @terrain == 2   #boat & ocean
  85.      @state = true if @vehicle == 3                            #dragon
  86.      @state = true if @terrain == 0
  87.   end
  88.  
  89. end
  90.  
  91. class Game_Player < Game_Character
  92.  
  93.   alias in_vehicle_alias update
  94.   #--------------------------------------------------------------------------
  95.   # * Memorize actor graphic
  96.   #--------------------------------------------------------------------------         
  97.   def actor_memorize
  98.      @actor_name = $game_actors[1].character_name
  99.      @actor_hue = $game_actors[1].character_hue
  100.      @battler_name = $game_actors[1].battler_name
  101.      @battler_hue = $game_actors[1].battler_hue
  102.      return true
  103.   end
  104.  
  105.   #--------------------------------------------------------------------------
  106.   # * Restore actor graphic
  107.   #--------------------------------------------------------------------------         
  108.   def actor_restore
  109.      actor = $game_actors[1]
  110.      actor.set_graphic(@actor_name.to_s, @actor_hue, @battler_name.to_s, @battler_hue)
  111.      $game_player.refresh
  112.      return true
  113.   end      
  114.  
  115.   #--------------------------------------------------------------------------
  116.   # * Enter a vehicle
  117.   #--------------------------------------------------------------------------            
  118.   def enter_vehicle(type)
  119.     
  120.      $game_system.menu_disabled = true
  121.      $game_system.save_disabled = true      
  122.     
  123.      if type != "dragon"
  124.         @through = true
  125.         move_forward
  126.         @through = false      
  127.      end
  128.     
  129.      actor_memorize
  130.      actor = $game_actors[1]      
  131.      actor.set_graphic(type, @actor_hue, @battler_name.to_s, @battler_hue)
  132.     
  133.      $game_switches[1] = false      #Canoe Off      
  134.      $game_switches[2] = false      #Boat Off      
  135.      $game_switches[3] = false      #Dragon Off            
  136.     
  137.      if type == "canoe"
  138.         $game_variables[1] = 1          #set terrian
  139.         $game_switches[1] = true      #Canoe On
  140.         Audio.bgm_play("Audio/BGM/047-Positive05", 100, 100) #play canoe music
  141.  
  142.      elsif type == "boat"
  143.         $game_variables[1] = 2          #set terrian
  144.         $game_switches[2] = true      #Boat On         
  145.         Audio.bgm_play("Audio/BGM/046-Positive04", 100, 100) #play ship music
  146.        
  147.      elsif type == "dragon"
  148.         $game_variables[1] = 3          #set terrian
  149.         $game_switches[3] = true      #Dragon On   
  150.         Audio.bgm_play("Audio/BGM/045-Positive03", 100, 100) #play dragon music
  151.        
  152.      end
  153.     
  154.      $game_player.refresh
  155.      $game_map.refresh
  156.     
  157.      return true
  158.   end
  159.  
  160.   #--------------------------------------------------------------------------
  161.   # * Enter a vehicle
  162.   #--------------------------------------------------------------------------            
  163.   def exit_vehicle
  164.  
  165.      $game_system.menu_disabled = false      
  166.      $game_system.save_disabled = false
  167.     
  168.      if @terrain == 4
  169.                 
  170.         if $game_switches[1] == true         #getting off canoe
  171.            canoe = $game_map.events[1]       #get canoe event
  172.            canoe.moveto(x, y)                     #move to player's x, y coords
  173.            $game_switches[1] = false          #Canoe Off   
  174.            $game_variables[2] = x               #set canoe x coord
  175.            $game_variables[3] = y               #set canoe y coord
  176.            @through = true
  177.            move_forward
  178.            @through = false               
  179.           
  180.         elsif $game_switches[2] == true    #getting off boat
  181.            boat = $game_map.events[2]         #get boat event
  182.            boat.moveto(x, y)                      #move to player's x, y coords            
  183.            $game_switches[2] = false          #Boat Off      
  184.            $game_variables[4] = x               #set boat x coord
  185.            $game_variables[5] = y               #set boate y coord   
  186.            @through = true
  187.            move_forward
  188.            @through = false                           
  189.           
  190.         elsif $game_switches[3] == true    #getting off dragon
  191.            dragon = $game_map.events[3]      #get dragon event
  192.            dragon.moveto(x, y)                   #move to player's x, y coords            
  193.            $game_switches[3] = false          #Dragon Off      
  194.            $game_variables[6] = x               #set dragon x coord
  195.            $game_variables[7] = y               #set dragon y coord            
  196.         end
  197.        
  198.         # get off vehicle
  199.         actor_restore
  200.     
  201.         # reset terrain
  202.         $game_variables[1] = 0               
  203.     
  204.         # play walking music
  205.         Audio.bgm_play("Audio/BGM/044-Positive02", 100, 100) #play music
  206.        
  207.         $game_player.refresh   
  208.         $game_map.refresh      
  209.     
  210.      end
  211.  
  212.   end
  213.  
  214.   #--------------------------------------------------------------------------
  215.   # * Frame Update
  216.   #--------------------------------------------------------------------------
  217.   def update
  218.      in_vehicle_alias
  219.      # if not on ground terrain, check for boat exit
  220.      if $game_variables[1] != 0
  221.         if Input.trigger?(Input::C)
  222.            exit_vehicle
  223.         end   
  224.      end
  225.   end
  226.  
  227. end
  228.  
Expand to see the code.


Add An Additional Vehicle
1. Create a switch for your new vehicle. Call it "using vehicle" (replace vehicle with the name of your vehicle).

2. Create two variables for your vehicle. Call them "vehicle x" and "vehicle y" (replace vehicle with the name of your vehicle).

3. Add an event on your map for your new vehicle. Set it up to look like the other vehicle events. Modify the switches on the event so that they are for your vehicle, not the dragon, canoe, or boat vehicle. Modify the script call in the event so that it is for your vehicle. For example:
  1.  
  2. $game_player.enter_vehicle("hovercraft")
  3.  
Expand to see the code.


4. Put your vehicle sprite in your project's "characters" folder. Make sure that the name of the vehicle is exactly what you specified in step 3. For example, hovercraft.png

5. Get a peice of paper and write down the slot numbers for your switch, your variables, and the event you created for your vehicle. You will need to reference them later in your code.

6. Open the script editor and go to the Vehicle Script section.

7. In def check_terrain, add a new if statement for your vehicle. For example:
  1.  
  2.      @state = true if @vehicle == 4 && @terrain == 5   #hovercraft & swamp
  3.  
Expand to see the code.


8. In def enter_vehicle, add the switch you created for your vehicle to the list. For example:
  1.  
  2.      $game_switches[283] = false      #turn off the "using hovercraft" switch
  3.  
Expand to see the code.


9. In def enter_vehicle, add a new if statement for your vehicle. For example:
  1.  
  2.      elsif type == "hovercraft"
  3.         $game_variables[1] = 5          #set terrian
  4.         $game_switches[4] = true      #Hovercraft On   
  5.         Audio.bgm_play("Audio/BGM/045-Positive03", 100, 100)
  6.  
Expand to see the code.


10. In def exit_vehicle, add a new if statement for your vehicle. For example:
  1.  
  2.         elsif $game_switches[4] == true    #getting off hovercraft
  3.            dragon = $game_map.events[4]   #get hovercraft event
  4.            dragon.moveto(x, y)                         #move to player's x, y coords            
  5.            $game_switches[4] = false            #turn "using hovercraft" off      
  6.            $game_variables[8] = x                   #set hovercraft x coord
  7.            $game_variables[9] = y                   #set hovercraft y coord      
  8.  
Expand to see the code.


Credits
SephirothSpawn: I made this script after studying SephirothSpawn's (mr. talented!) vehicle script.
DerVVulfman: Enhancing the system!

Bugs
If you find a bug, let me know! I'm crazy busy right now, but I will try to fix any problems. Or, if an advanced scripter wants to take over this project, feel free to do so (again, i'm crazy busy with work). There are some gotchas with this system:
1. Don't use terrain flags on any map but your world map. (if you do, put an if statement in the code so that the vehicle system only works with your world map.
2. If you use a tileset background for an event on your world map, your vehicle will go over it. Use an empty character sprite if you run into problems.
That's good, is there anyway to make the map loop? By the way, the dragon(air-ship) manage to get into the ice-cave. Is that how it's suppost to be?
The dragon can also take the boat... and when it comes out it does not seem to fly anymore (it gets stopped by the trees)... and secondly another dragon in the map appears.
Maybe you should disable the possibility of taking a vehicle when already on a vehicle.
However i like it.
Fixed! You can no longer fly into a cave, nor will the dragon land on the ship.

I could make the map loop, but I think that is for another script. There is one available, right?

:)
Its a cool script, is it possible to add more vehicles?
Yes! I'll add steps above.
Cool, I will see it soon.
Cool script lamb.
though if i might ask one question
is there a way to make the flight type vehicle go faster with a button press?
Sure, just add a speed call into your script. Put it in the enter_vehicle and exit_vehicle methods. I'm not quite sure what the call is off the top of my head. Anyone else know?
WOW!!!! this script is awesome.... :thumb: Thumbs up good job :yes::D
Bug Report:
When you land in front of a unpassable Tile The Hero will Walk through it.

http://i17.tinypic.com/4ue5jec.jpg[/IMG]
I see the issue.

The problem occurs as you exit the vehicle. When you do, the character doesn't stay 'directly' under the vehicle, but takes a step forward... crossing terrain impassible borders (as it were). Boarding a vehicle doesn't create an issue (even though the vessel also moves forward one tile) as the vessel follows its own terrain rules. But leaving a vehicle with this problem could cause a problem.

While the 'forward step' feature would work fine with vehicles such as boats and ships (cosmetically as well as technically), you may wish to have a separate 'exit vehicle' system for air-based vessels.

Or an option for such by the end-user's choice.
I've updated the script and demo with the dragon bug fix. :)
Theres still an issue with the vehicles. I was in the dragon, got in the canoe from it, the canoe went on land, i got back in the dragon, then I went to its island and got out and I was in the canoe, and the canoe could only go on land. Plus the bugs with other maps I read about I don't think I will be using this which is a bummer because I like it...
well, this really isn't an issue, but when you are using a vehicle, the menu shows a vehicle instead of the main characters graphic. anyway to prevent this? or should i just disable the menu while in a vehicle?
Awsome man.
Really cool script you've made there,
Thumbs up for you too =D
:thumb: ;)
Looping map! Where can I get looping map to go with this?
Okay, I just fixed the canoe and menu problems. You can no longer enter the canoe (you fly over it), and the menu won't open when you are in a vehicle. :)

(I just got crazy busy with work, but I will add a speed boost to the dragon and map wrapping in a week, since I'll need this for my game as well.)
Hey sorry if this is a really easy thing I messed up on doing but I am having problems with the script when I put it into my own game. after I put it in and hopefully put the terrian tags on right I got in the canoe and noticed I can go through the ship but thats not a big problem but the big one I have is after I've been in the canoe everytime I get off onto land It turns my character graphic into a canoe.

So if you could please help me that would be great :D
If you need anymore info or maybe a screenshot or something let me know.
I found another bug... this is sorta like the canoe problem except it gets messed up with the boat too.

Land the dragon one tile next to the boat or canoe (so you're under the dragon and next to the boat). Face the boat and press the action key-- you should ride the dragon. Then if you land the dragon you become the boat! And you can run around on land as the boat and access the menu. It's nothing major, but still bad for gameplay.
I'm sorry...but this is really confusing for us non-scripters...or for us idiots lol. I'm having problems following your directions....

I'm just trying to make a boat, but I'm using the word Ship instead of boat in all my switches and stuff. I'm having trouble knowing what parts in the script are the places where I need to change "boat" to "Ship", and where to change the switches and variable numbers to my own.
[QUOTE=sillypieman;284693]I'm sorry...but this is really confusing for us non-scripters...or for us idiots lol. I'm having problems following your directions....

I'm just trying to make a boat, but I'm using the word Ship instead of boat in all my switches and stuff. I'm having trouble knowing what parts in the script are the places where I need to change "boat" to "Ship", and where to change the switches and variable numbers to my own.[/QUOTE]
The names of switches are purely for the programmer's reference and have no bearing on the outcome of events - the program doesn't match names (it only matches numbers - you don't even have to name switches and they will work like normal), so if there is a problem that is occurring, it is not due to the switch names.
No, I meant knowing where to change numbers. Cuz the original script assumes you are using switch 2 for the boat one right? My boat switch is number 279.

Okay, here's what's going on. I can get on the boat, but then I can't move in the water, and if I hold CTRL to go up to the land and push enter I can't get off...so in other words it's not working for me lol.
[QUOTE=sillypieman;284701]No, I meant knowing where to change numbers. Cuz the original script assumes you are using switch 2 for the boat one right? My boat switch is number 279.

Okay, here's what's going on. I can get on the boat, but then I can't move in the water, and if I hold CTRL to go up to the land and push enter I can't get off...so in other words it's not working for me lol.[/QUOTE]
I'm not familiar with this particular vehicle script (I use my own), but it's hard to tell unless I had your project, since the problem could be any number of things related to switches. Just do your best to make sure that any reference in his events to switch 2 are now set to switch 279. Make sure to check every page of every event on the map. Chances are you missed just one of them and it's messing things up.
It sounds like you don't have the correct terrain number assigned to your vehicle or the tiles in your tileset...
I thought I did....I had the water as number 2.

Well, I'm using Seph's right now...I just need to do some more complex switches and events and conditional branches, but I've almost got a system worked out. I use only specific landing places, so that really makes it easier.

But if there's an airship in my game, I probably will need to use this script instead.

Edit: Who do I give credit to for using the Ship characterset?
[QUOTE=KAIRE;282790]Looping map! Where can I get looping map to go with this?[/QUOTE]

Bad news is, you cannot use this and KGC Maploop together, since both rewrites Game_Character::passible?.
Wow, how come i didn't notice this script? :/

Good stuff Lambchop, i may have to use this some time.
I've run into an issue...

I copied the script completely from the demo (I mean like, Events, switches, EVERYTHING. I even set the terrain tags...)

The only problem is, my character doesn't move on the map once I set all the terrain tags!

Can anyone help me?

If it helps, I'm using Mr. Mo's ABS. I'm not sure if that is the cause of the problem?

~EDIT

Another note, Im not using SBABS, Just the normal ABS.
you should make this compatible with mr.mo's SBABS, i tried to use it in it, but of course, the allies "refuse" to get in the boat, i'll try to figure it out.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=28741