Advertisement
roninator2

Land Vehicle

Nov 18th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.62 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Land Vehicle                           ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   Use a land vehicle                          ║    20 Jul 2023     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: nil                                                      ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║       Create a vehicle to use on land                              ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Change the values below for the vehicle location                 ║
  20. # ║                                                                    ║
  21. # ║   Put in a script call to transfer the vehicle                     ║
  22. # ║   to another map.                                                  ║
  23. # ║       script: set_land_vehicle(map id, x, y)                       ║
  24. # ║                                                                    ║
  25. # ╚════════════════════════════════════════════════════════════════════╝
  26. # ╔════════════════════════════════════════════════════════════════════╗
  27. # ║ Updates:                                                           ║
  28. # ║ 1.00 - 20 Jul 2023 - Script finished                               ║
  29. # ║                                                                    ║
  30. # ╚════════════════════════════════════════════════════════════════════╝
  31. # ╔════════════════════════════════════════════════════════════════════╗
  32. # ║ Credits and Thanks:                                                ║
  33. # ║   Roninator2                                                       ║
  34. # ║                                                                    ║
  35. # ╚════════════════════════════════════════════════════════════════════╝
  36. # ╔════════════════════════════════════════════════════════════════════╗
  37. # ║ Terms of use:                                                      ║
  38. # ║  Follow the original Authors terms of use where applicable         ║
  39. # ║    - When not made by me (Roninator2)                              ║
  40. # ║  Free for all uses in RPG Maker except nudity                      ║
  41. # ║  Anyone using this script in their project before these terms      ║
  42. # ║  were changed are allowed to use this script even if it conflicts  ║
  43. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  44. # ║  No part of this code can be used with AI programs or tools        ║
  45. # ║  Credit must be given                                              ║
  46. # ╚════════════════════════════════════════════════════════════════════╝
  47.  
  48. module R2_LAND_VEHICLE
  49.   LAND_MAP = 1      # Which map to have the vehicle start on
  50.   LAND_X = 10       # X coordinate of the Land Vehicle on the map
  51.   LAND_Y = 5        # Y coordinate of the Land Vehicle on the map
  52.   LAND_INDEX = 5    # graphic index of the Land Vehicle in the spritesheet
  53.   LAND_NAME = "Vehicle" # Name of graphic with the Land Vehicle
  54.   LAND_BGM = RPG::BGM.new("Ship", 100, 100) # BGM to play while in Land Vehicle
  55.   MOVE_SPEED = 4    # Movement speed of the Land Vehicle on the map
  56.   AVOID_BATTLES = true # True = no battles while in land vehicle
  57. end
  58.  
  59. # ╔════════════════════════════════════════════════════════════════════╗
  60. # ║                      End of editable region                        ║
  61. # ╚════════════════════════════════════════════════════════════════════╝
  62.  
  63. #==============================================================================
  64. # ** Game_Vehicle
  65. #==============================================================================
  66.  
  67. class Game_Vehicle < Game_Character
  68.   #--------------------------------------------------------------------------
  69.   # * Initialize Move Speed
  70.   #--------------------------------------------------------------------------
  71.   alias :r2_land_vehicle_move_speed :init_move_speed
  72.   def init_move_speed
  73.     r2_land_vehicle_move_speed
  74.     @move_speed = R2_LAND_VEHICLE::MOVE_SPEED if @type == :land
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * Get System Settings
  78.   #--------------------------------------------------------------------------
  79.   alias :r2_system_vehicle_land :system_vehicle
  80.   def system_vehicle
  81.     return land_vehicle    if @type == :land
  82.     r2_system_vehicle_land
  83.   end
  84.   def land_vehicle
  85.     if $game_system.land_vehicle == nil
  86.       $game_system.land_vehicle = $data_system.boat.dup
  87.       $game_system.land_vehicle.start_map_id = R2_LAND_VEHICLE::LAND_MAP
  88.       $game_system.land_vehicle.start_x = R2_LAND_VEHICLE::LAND_X
  89.       $game_system.land_vehicle.start_y = R2_LAND_VEHICLE::LAND_Y
  90.       $game_system.land_vehicle.character_index = R2_LAND_VEHICLE::LAND_INDEX
  91.       $game_system.land_vehicle.character_name = R2_LAND_VEHICLE::LAND_NAME
  92.       $game_system.land_vehicle.bgm = R2_LAND_VEHICLE::LAND_BGM
  93.     end
  94.     return $game_system.land_vehicle
  95.   end
  96. end # Game_Vehicle
  97.  
  98. #==============================================================================
  99. # ** Game_System
  100. #==============================================================================
  101.  
  102. class Game_System
  103.   #--------------------------------------------------------------------------
  104.   # * Public Instance Variables
  105.   #--------------------------------------------------------------------------
  106.   attr_accessor :land_vehicle            # Land Vehicle
  107. end # Game_System
  108.  
  109. #==============================================================================
  110. # ** Game_Map
  111. #==============================================================================
  112.  
  113. class Game_Map
  114.   #--------------------------------------------------------------------------
  115.   # * Create Vehicles
  116.   #--------------------------------------------------------------------------
  117.   alias :r2_land_vehicle_create :create_vehicles
  118.   def create_vehicles
  119.     r2_land_vehicle_create
  120.     @vehicles[3] = Game_Vehicle.new(:land)
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Get Vehicle
  124.   #--------------------------------------------------------------------------
  125.   alias :r2_land_vehicle_type :vehicle
  126.   def vehicle(type)
  127.     return @vehicles[3] if type == :land
  128.     r2_land_vehicle_type(type)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Get Boat
  132.   #--------------------------------------------------------------------------
  133.   def land
  134.     @vehicles[3]
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Determine if Passable by Boat
  138.   #--------------------------------------------------------------------------
  139.   def land_passable?(x, y, d)
  140.     check_passage(x, y, (1 << (d / 2 - 1)) & 0x0f)
  141.   end
  142. end # Game_Map
  143.  
  144. #==============================================================================
  145. # ** Game_Player
  146. #==============================================================================
  147.  
  148. class Game_Player < Game_Character
  149.   #--------------------------------------------------------------------------
  150.   # * Determine if Map is Passable
  151.   #     d:  Direction (2,4,6,8)
  152.   #--------------------------------------------------------------------------
  153.   def map_passable?(x, y, d)
  154.     case @vehicle_type
  155.     when :land
  156.       $game_map.land_passable?(x, y, d)
  157.     when :boat
  158.       $game_map.boat_passable?(x, y)
  159.     when :ship
  160.       $game_map.ship_passable?(x, y)
  161.     when :airship
  162.       true
  163.     else
  164.       super
  165.     end
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Determine if on Boat
  169.   #--------------------------------------------------------------------------
  170.   def in_land?
  171.     @vehicle_type == :land
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Board Vehicle
  175.   #    Assumes that the player is not currently in a vehicle.
  176.   #--------------------------------------------------------------------------
  177.   def get_on_vehicle
  178.     front_x = $game_map.round_x_with_direction(@x, @direction)
  179.     front_y = $game_map.round_y_with_direction(@y, @direction)
  180.     @vehicle_type = :boat    if $game_map.boat.pos?(front_x, front_y)
  181.     @vehicle_type = :ship    if $game_map.ship.pos?(front_x, front_y)
  182.     @vehicle_type = :airship if $game_map.airship.pos?(@x, @y)
  183.     @vehicle_type = :land    if $game_map.land.pos?(@x, @y)
  184.     if vehicle
  185.       @vehicle_getting_on = true
  186.       force_move_forward unless in_airship? or in_land?
  187.       @followers.gather
  188.     end
  189.     @vehicle_getting_on
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Get Off Vehicle
  193.   #    Assumes that the player is currently riding in a vehicle.
  194.   #--------------------------------------------------------------------------
  195.   def get_off_vehicle
  196.     if vehicle.land_ok?(@x, @y, @direction)
  197.       set_direction(2) if in_airship?
  198.       @followers.synchronize(@x, @y, @direction)
  199.       vehicle.get_off
  200.       unless in_airship? || in_land?
  201.         force_move_forward
  202.         @transparent = false
  203.       end
  204.       @vehicle_getting_off = true
  205.       @move_speed = 4
  206.       @through = false
  207.       make_encounter_count
  208.       @followers.gather
  209.     end
  210.     @vehicle_getting_off
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Determine if Event Start Caused by Touch (Overlap)
  214.   #--------------------------------------------------------------------------
  215.   def check_touch_event
  216.     return false if in_airship? || in_land?
  217.     check_event_trigger_here([1,2])
  218.     $game_map.setup_starting_event
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # * Determine if Front Event is Triggered
  222.   #--------------------------------------------------------------------------
  223.   def check_event_exist(d)
  224.     return if $game_map.interpreter.running?
  225.     @direction = d
  226.     x2 = $game_map.round_x_with_direction(@x, @direction)
  227.     y2 = $game_map.round_y_with_direction(@y, @direction)
  228.     return false if $game_map.events_xy(x2, y2).empty?
  229.     return true
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # * Move Straight
  233.   #--------------------------------------------------------------------------
  234.   def move_straight(d, turn_ok = true)
  235.     return if (vehicle && check_event_exist(d))
  236.     @followers.move if passable?(@x, @y, d)
  237.     super
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Execute Encounter Processing
  241.   #--------------------------------------------------------------------------
  242.   def encounter
  243.     return false if $game_map.interpreter.running?
  244.     return false if $game_system.encounter_disabled
  245.     return false if R2_LAND_VEHICLE::AVOID_BATTLES && in_land?
  246.     return false if @encounter_count > 0
  247.     make_encounter_count
  248.     troop_id = make_encounter_troop_id
  249.     return false unless $data_troops[troop_id]
  250.     BattleManager.setup(troop_id)
  251.     BattleManager.on_encounter
  252.     return true
  253.   end
  254. end # Game_Player
  255.  
  256. #==============================================================================
  257. # ** Game_Interpreter
  258. #==============================================================================
  259.  
  260. class Game_Interpreter
  261.   #--------------------------------------------------------------------------
  262.   # * Set Vehicle Location
  263.   #--------------------------------------------------------------------------
  264.   def set_land_vehicle(map, x, y)
  265.     $game_map.vehicles[3].set_location(map, x, y)
  266.   end
  267. end # Game_Interpreter
  268.  
  269. #==============================================================================
  270. # ** Spriteset_Battle
  271. #==============================================================================
  272.  
  273. class Spriteset_Battle
  274.  
  275.   #--------------------------------------------------------------------------
  276.   # * Get Filename of Field Battle Background (Floor)
  277.   #--------------------------------------------------------------------------
  278.   def overworld_battleback1_name
  279.     $game_player.vehicle ? $game_player.in_land? ? normal_battleback1_name : ship_battleback1_name : normal_battleback1_name
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * Get Filename of Field Battle Background (Wall)
  283.   #--------------------------------------------------------------------------
  284.   def overworld_battleback2_name
  285.     $game_player.vehicle ? $game_player.in_land? ? normal_battleback2_name : ship_battleback2_name : normal_battleback2_name
  286.   end
  287. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement