Script to solve problems with boat and ship battlebacks.

By default, in VX Ace, the battle background in battles while riding ship and boat will always be the two default battlebacks named "Ship". I'm using Yanfly Region Battlebacks, a script that allows me to change the battleback based on the region ID that I choose.

I'm using this script because I use several kinds of backgrounds for the same tiles, including water tiles. More specifically, I'm trying to use several custom battle backgrounds in battles with boat and ship, backgrounds of blue sea, green sea, red sea, rivers, mud... but the game always forces the default one (named "Ship") and only it, no matter what I do. Neither the Yanfly script can change this. Neither the option to put a default ship battleback works (despite I don't want to use it, because as I said before, I'm using multiple battlebacks for boat, ship and water tiles). I tested both my main project and a clean project with only this Yanfly script... but no use.

Probably is because the way the game processes battle backgrounds for boat&ship and characters are different, so I think the solution is taking the process of creation of battle backgrounds for on-foot battles and using it in the boat and ship. So, the boat/ship will be affected by the Yanfly script just like on-foot chars. Can someone find a way to do this via scripting?
I'm using this script because I use several kinds of backgrounds for the same tiles, including water tiles. More specifically, I'm trying to use several custom battle backgrounds in battles with boat and ship, backgrounds of blue sea, green sea, red sea, rivers, mud... but the game always forces the default one (named "Ship") and only it, no matter what I do. Neither the Yanfly script can change this. Neither the option to put a default ship battleback works (despite I don't want to use it, because as I said before, I'm using multiple battlebacks for boat, ship and water tiles). I tested both my main project and a clean project with only this Yanfly script... but no use.

Probably is because the way the game processes battle backgrounds for boat&ship and characters are different, so I think the solution is taking the process of creation of battle backgrounds for on-foot battles and using it in the boat and ship. So, the boat/ship will be affected by the Yanfly script just like on-foot chars. Can someone find a way to do this via scripting?
The script itself doesn't use the list of battlebacks for the region numbers. And if you read through you would have seen that.

This works though if you want to use various battlebacks on the vehicles. Say like 1-3 for boat 4-6 for ship and 7-9 for airship
Spoiler: Vehicle Battle Back Addon
Ruby:
module YEA
  module BATTLEBACKS
    
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Default Region Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # This will set the default backdrops for maps without custom region
    # settings. These settings will always be used unless there is a forced
    # battleback or the map specifies certain battlebacks. Note that if your
    # party encounters battles while on a ship, the ship battleback will take
    # priority over all of these. Adjust the ship battlebacks further below.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    VEHICLE ={
    # RegionID => [  Battleback1,   Battleback2],
             0 => [  "Grassland",   "Grassland"],
             1 => [  "Grassland",     "Forest1"],
             2 => [  "Dirtfield",     "Forest2"],
             3 => [  "Dirtfield",     "Forest2"],
             4 => [      "Dirt1",       "Cliff"],
             5 => [     "Desert",      "Desert"],
             6 => [  "Wasteland",   "Wasteland"],
             7 => [      "Lava1",        "Forest1"],
             8 => [  "Dirtfield",        "Lava"],
             9 => [  "Snowfield",   "Snowfield"],
            10 => ["PoisonSwamp", "PoisonSwamp"],
    } # Do not remove this.
  end
end

#==============================================================================
# ■ RPG::Map
#==============================================================================

class RPG::Map
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :vehicle_battlebacks
 
  #--------------------------------------------------------------------------
  # common cache: load_notetags_rbb
  #--------------------------------------------------------------------------
  alias :r2_load_vehicle_notetags_rbb :load_notetags_rbb
  def load_notetags_rbb
    r2_load_vehicle_notetags_rbb
    @vehicle_battlebacks = YEA::BATTLEBACKS::VEHICLE.clone
  end
end

#==============================================================================
# ■ Spriteset_Battle
#==============================================================================

class Spriteset_Battle
 
  #--------------------------------------------------------------------------
  # overwrite method: ship_battleback1_name
  #--------------------------------------------------------------------------
  alias :r2_ship_battleback1  :ship_battleback1_name
  def ship_battleback1_name
    $game_map.vehicle_battleback1 || r2_ship_battleback1
  end
 
  #--------------------------------------------------------------------------
  # alias method: ship_battleback2_name
  #--------------------------------------------------------------------------
  alias :r2_ship_battleback1  :ship_battleback1_name
  def ship_battleback2_name
    $game_map.vehicle_battleback2 || r2_ship_battleback2
  end
 
end # Spriteset_Battle

#==============================================================================
# ■ Game_Map
#==============================================================================

class Game_Map
 
  #--------------------------------------------------------------------------
  # new method: region_battlebacks
  #--------------------------------------------------------------------------
  def vehicle_battlebacks
    @map.load_notetags_rbb if @map.vehicle_battlebacks == nil
    return @map.vehicle_battlebacks
  end
 
  #--------------------------------------------------------------------------
  # new method: region_battleback1
  #--------------------------------------------------------------------------
  def vehicle_battleback1
    return vehicle_battlebacks[$game_player.region_id][0]
  end
 
  #--------------------------------------------------------------------------
  # new method: region_battleback2
  #--------------------------------------------------------------------------
  def vehicle_battleback2
    return vehicle_battlebacks[$game_player.region_id][1]
  end
 
end # Game_Map
The script itself doesn't use the list of battlebacks for the region numbers. And if you read through you would have seen that.

This works though if you want to use various battlebacks on the vehicles. Say like 1-3 for boat 4-6 for ship and 7-9 for airship
Spoiler: Vehicle Battle Back Addon
Ruby:
module YEA
  module BATTLEBACKS
   
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # - Default Region Settings -
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    # This will set the default backdrops for maps without custom region
    # settings. These settings will always be used unless there is a forced
    # battleback or the map specifies certain battlebacks. Note that if your
    # party encounters battles while on a ship, the ship battleback will take
    # priority over all of these. Adjust the ship battlebacks further below.
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    VEHICLE ={
    # RegionID => [  Battleback1,   Battleback2],
             0 => [  "Grassland",   "Grassland"],
             1 => [  "Grassland",     "Forest1"],
             2 => [  "Dirtfield",     "Forest2"],
             3 => [  "Dirtfield",     "Forest2"],
             4 => [      "Dirt1",       "Cliff"],
             5 => [     "Desert",      "Desert"],
             6 => [  "Wasteland",   "Wasteland"],
             7 => [      "Lava1",        "Forest1"],
             8 => [  "Dirtfield",        "Lava"],
             9 => [  "Snowfield",   "Snowfield"],
            10 => ["PoisonSwamp", "PoisonSwamp"],
    } # Do not remove this.
  end
end

#==============================================================================
# ■ RPG::Map
#==============================================================================

class RPG::Map
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :vehicle_battlebacks
 
  #--------------------------------------------------------------------------
  # common cache: load_notetags_rbb
  #--------------------------------------------------------------------------
  alias :r2_load_vehicle_notetags_rbb :load_notetags_rbb
  def load_notetags_rbb
    r2_load_vehicle_notetags_rbb
    @vehicle_battlebacks = YEA::BATTLEBACKS::VEHICLE.clone
  end
end

#==============================================================================
# ■ Spriteset_Battle
#==============================================================================

class Spriteset_Battle
 
  #--------------------------------------------------------------------------
  # overwrite method: ship_battleback1_name
  #--------------------------------------------------------------------------
  alias :r2_ship_battleback1  :ship_battleback1_name
  def ship_battleback1_name
    $game_map.vehicle_battleback1 || r2_ship_battleback1
  end
 
  #--------------------------------------------------------------------------
  # alias method: ship_battleback2_name
  #--------------------------------------------------------------------------
  alias :r2_ship_battleback1  :ship_battleback1_name
  def ship_battleback2_name
    $game_map.vehicle_battleback2 || r2_ship_battleback2
  end
 
end # Spriteset_Battle

#==============================================================================
# ■ Game_Map
#==============================================================================

class Game_Map
 
  #--------------------------------------------------------------------------
  # new method: region_battlebacks
  #--------------------------------------------------------------------------
  def vehicle_battlebacks
    @map.load_notetags_rbb if @map.vehicle_battlebacks == nil
    return @map.vehicle_battlebacks
  end
 
  #--------------------------------------------------------------------------
  # new method: region_battleback1
  #--------------------------------------------------------------------------
  def vehicle_battleback1
    return vehicle_battlebacks[$game_player.region_id][0]
  end
 
  #--------------------------------------------------------------------------
  # new method: region_battleback2
  #--------------------------------------------------------------------------
  def vehicle_battleback2
    return vehicle_battlebacks[$game_player.region_id][1]
  end
 
end # Game_Map
Thank you again, it works fine. I'm in debt with you.

Original thread: https://forums.rpgmakerweb.com/threads/script-to-solve-problems-with-boat-and-ship-battlebacks.159595/