by Dargor
Version 1.1
Introduction
Another script I made for the FFVI SDK but this version is a lot more customizable!
This script let you pause the game (duh!). And when I say pause the game, I mean EVERYTHING is paused; animations, playtime/frame count, windows, etc.
Features
- Determine which scenes can be paused
- Change Graphics brightness when paused
- Change BGM volume when paused
- Customizable Pause key
- Can have a Pause window
Script
Code:
#==============================================================================
# ** Pause Game
#------------------------------------------------------------------------------
# © Dargor, 2008
#Â 17/06/08
#Â Version 1.0
#------------------------------------------------------------------------------
#Â VERSION HISTORY:
#Â - 1.0 (17/05/08), Initial release
#Â - 1.1 (17/05/08), Added "Stack Reset" prevention
#------------------------------------------------------------------------------
#Â INSTRUCTIONS:
#Â - Paste this above main
#Â - Edit the constants in the Pause_Game module
#------------------------------------------------------------------------------
#Â NOTES:
#Â Â This script modifies the Graphics module and rewrites the main
#Â Â method of Scene_Base.
#==============================================================================
#==============================================================================
# ** Pause Game Configuration Module
#==============================================================================
module Pause_Game
 # Scenes in which the Pause option will be enabled
 Allowed_Scenes = [Scene_Map, Scene_Battle]
 # Graphics Brightness when paused
 Graphics_Brightness = 160
 # BGM Volume when paused
 BGM_Volume = 70
 # Pause Key
 Key = Input::SHIFT
 # Pause window
 Pause_Window = true
end
#==============================================================================
# ** Graphics
#------------------------------------------------------------------------------
#Â This module carries out graphics processing.
#==============================================================================
module Graphics
 class << self
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  if @graphics_stack.nil?
   alias dargor_vx_pause_graphics_initialize initialize
   alias dargor_vx_pause_graphics_update update
   @graphics_stack = true
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
   @paused = false
   dargor_vx_pause_graphics_initialize
  end
  #--------------------------------------------------------------------------
  # * Pause
  #--------------------------------------------------------------------------
  def pause
   return @paused
  end
  #--------------------------------------------------------------------------
  # * Pause =
  #--------------------------------------------------------------------------
  def pause=(bool)
   # Set brightness and BGM volume
   if bool
    self.brightness = Pause_Game::Graphics_Brightness
    Sound.set_bgm_volume(Pause_Game::BGM_Volume)
   else
    self.brightness = 255
    Sound.reset_bgm_volume
   end
   # Refresh screen
   update
   # Set pause flag
   @paused = bool
  end
  #--------------------------------------------------------------------------
  # * Pause Disabled
  #--------------------------------------------------------------------------
  def pause_disabled?
   return !Pause_Game::Allowed_Scenes.include?($scene.class)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
   return if @paused
   dargor_vx_pause_graphics_update
  end
 end
end
#==============================================================================
# ** Sound
#------------------------------------------------------------------------------
#Â This module plays sound effects. It obtains sound effects specified in the
# database from $data_system, and plays them.
#==============================================================================
module Sound
 #--------------------------------------------------------------------------
 # * Set BGM Volume
 #--------------------------------------------------------------------------
 def self.set_bgm_volume(volume)
  RPG::BGM.last.last_volume = RPG::BGM.last.volume
  RPG::BGM.last.volume = volume
  RPG::BGM.last.play
 end
 #--------------------------------------------------------------------------
 # * Reset BGM Volume
 #--------------------------------------------------------------------------
 def self.reset_bgm_volume
  RPG::BGM.last.volume = RPG::BGM.last.last_volume
  RPG::BGM.last.play
 end
end
#==============================================================================
# ** RPG::AudioFile
#------------------------------------------------------------------------------
#Â Superclass of BGM, BGS, ME, and SE.
#==============================================================================
class RPG::AudioFile
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :last_volume
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias dargor_vx_pause_audiofile_initialize initialize
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize(*args)
  dargor_vx_pause_audiofile_initialize
  @last_volume = @volume
 end
end
#==============================================================================
# ** Scene_Base
#------------------------------------------------------------------------------
#Â This is a superclass of all scenes in the game.
#==============================================================================
class Scene_Base
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
  start            # Start processing
  perform_transition      # Perform transition
  post_start          # Post-start processing
  Input.update         # Update input information
  loop do
   update_pause        # Update game pause state
   Graphics.update      # Update game screen
   Input.update        # Update input information
   next if Graphics.pause   # Cancel scene update if game is paused
   update           # Update frame
   break if $scene != self  # When screen is switched, interrupt loop
  end
  Graphics.update
  pre_terminate        # Pre-termination processing
  Graphics.freeze       # Prepare transition
  terminate          # Termination processing
 end
 #--------------------------------------------------------------------------
 # * Frame Update (Pause)
 #--------------------------------------------------------------------------
 def update_pause
  # Update spriteset if it exists
  unless Graphics.pause
   terminate_pause_window
  end
  # Cancel pause update if pause is disabled
  return if Graphics.pause_disabled?
  # Update Pause effect
  if Input.trigger?(Pause_Game::Key)
   create_pause_window unless Graphics.pause
   Graphics.pause = !Graphics.pause
   return
  end
 end
 #--------------------------------------------------------------------------
 # * Create Pause Window
 #--------------------------------------------------------------------------
 def create_pause_window
  return unless @pause_window.nil?
  return unless Pause_Game::Pause_Window
  @pause_window = Window_Help.new
  @pause_window.width = 272
  @pause_window.x = Graphics.width / 2 - @pause_window.width / 2
  @pause_window.y = Graphics.height / 2 - @pause_window.height / 2
  @pause_window.create_contents
  @pause_window.set_text('Pause...',1)
 end
 #--------------------------------------------------------------------------
 # * Terminate Pause Window
 #--------------------------------------------------------------------------
 def terminate_pause_window
  return if @pause_window.nil?
  @pause_window.dispose
  @pause_window = nil
 end
end
Notes
This script rewrites the Scene_Base main method and modifies the Graphics.update method.
Enjoy!
-Dargor