The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: TDS on February 21, 2012, 05:07:10 AM

Title: Region Battleback
Post by: TDS on February 21, 2012, 05:07:10 AM
Region Battlebacks
Version: 1.0
Author: TDS
Date: February 20, 2012

Version History



Description


This script allows you to set battlebacks based on region id.

Features



Instructions

Just put the script in the materials area of the script editor and follow the instructions on the script.

Script


Code: [Select]
#==============================================================================
# ** TDS Region Battlebacks
#    Ver: 1.0
#------------------------------------------------------------------------------
#  * Description:
#  This script allows you to set battlebacks based on region id.
#------------------------------------------------------------------------------
#  * Features:
#  Setting battle backgrounds based on region id's.
#------------------------------------------------------------------------------
#  * Instructions:
#  To set the battleback for regions add this to the notes box on the map
#  properties:
#
#  S_REGION_BG:
#  region_id-battleback_index: battleback_filename
#  region_id-battleback_index: battleback_filename
#  E_REGION_BG:
#
#  region_id: ID of the region to set batteback for.
#  battleback_index: index of the battleback to set. (1: Wall, 2: Floor)
#  battleback_filename: name of the battleback image.
#
#
#  Example:
#
#  S_REGION_BG:
#  1-1: Demonicworld1
#  1-2: Demoncastle3
#  2-1: Clouds
#  2-2: Clouds

#  E_REGION_BG:
#------------------------------------------------------------------------------
#  * Notes:
#  None
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#==============================================================================


#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :region_battlebacks                  # Region Battle Backs Hash
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias tds_region_battleback_game_map_setup                            setup
  #--------------------------------------------------------------------------
  # * Setup
  #     map_id : map ID
  #--------------------------------------------------------------------------
  def setup(*args)
    # Run Original Method
    tds_region_battleback_game_map_setup(*args)
    # Setup Region Battlebacks
    setup_region_battlebacks
  end 
  #--------------------------------------------------------------------------
  # * Setup Region Battlebacks
  #--------------------------------------------------------------------------
  def setup_region_battlebacks   
    # Make Region Battlebacks Hash
    @region_battlebacks = {}
    # Get Region Battleback Text
    @map.note[/S_REGION_BG:(.*)E_REGION_BG/m] ; battleback_text = $1
    # Return if battleback text is nil
    return if battleback_text.nil?
    # Scan Battleback Text for region battleback information
    battleback_text.scan(/(?'region_id'[0-9]+)-(?'battleback'[0-9]): (?'filename'\w+)/) {|t|
      # Get Match Information
      m = Regexp.last_match
      # Make Default Region Battleback Name
      @region_battlebacks[m[:region_id].to_i] ||= ["", ""]
      # Set Region Battleback Name
      @region_battlebacks[m[:region_id].to_i][m[:battleback].to_i-1] = m[:filename].strip
    }
  end
  #--------------------------------------------------------------------------
  # * Set Map Region Battleback
  #--------------------------------------------------------------------------
  def set_map_region_battleback(region = region_id($game_player.x, $game_player.y))
    # Get Battleback for Region
    battleback = @region_battlebacks[region]
    # If Battleback for region is nil
    if battleback.nil?
      # Setup Default Battleback
      setup_battleback
    else
      # Change Battleback
      change_battleback(battleback.at(0), battleback.at(1))
    end   
  end
end


#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias tds_region_battleback_scene_map_update_encounter     update_encounter
  #--------------------------------------------------------------------------
  # * Update Encounter
  #--------------------------------------------------------------------------
  def update_encounter
    # Run Original Method
    tds_region_battleback_scene_map_update_encounter
    # Set Map Region Battleback if a battle is starting from the map
    $game_map.set_map_region_battleback if SceneManager.scene_is?(Scene_Battle)   
  end 
end

Credit



Support


On this topic.

Known Compatibility Issues

None that I'm aware of so far.

Restrictions

Only for use in non-commercial games.
Title: Re: Region Battleback
Post by: Nessiah on February 21, 2012, 08:12:43 AM
Hey, thank you for this awesome script~ It's nice to have alternatives :D