Ingame System Audio Definition
Version: 2.0
Author: modern algebra
Date: June 5, 2010
Description
This script allows you to change what audio files are associated with the system at any time during the game. That's a bit abstract, so an easier way to explain it would be that if, for whatever reason, you want to be able to change the sound effect that is played when you press enter on something, then this script allows you to change that in-game. In other words, you don't have to have only one decision SE for the entire game. The same goes for all of the BGMs, MEs, and SEs that are set in the System tab of the Database, except for the title ones.
Features
- Allows you to change the system audio at any point in game
- Can set pitch and volume along with the new SE
- Could easily be adapted into an options menu that allows the user to select his own system audio
- Very easy to use interface
Instructions
Place this script in its own slot in the Script Editor (F11), above Main but below Materials.
You can change any of the system audio files in-game using the following code in a call script:
change_audio (:type, "filename", volume, pitch)
type - this is how you set which sound effect to change. The possible values are (they correspond to their name in System):
:cursor, :decision, :cancel, :buzzer, :equip, :save, :load, :battle_start, :escape, :enemy_attack, :enemy_damage, :enemy_collapse, :actor_damage, :actor_collapse, :recovery, :miss, :evasion, :shop, :item_use, :skill_use, :boat, :ship, :airship, :battle, :battle_end, :gameover
filename - the name of the audio file to change to it must be within quotation marks. If excluded, it erases the sound altogether.
volume - the volume you want the audiofile to play at. If excluded, this defaults to 100
pitch - the pitch you want the audiofile to play at. If excluded, this defaults to 100
EXAMPLES:
change_audio (:cursor, "Cursor2", 60)
change_audio (:gameover,"Victory1",120,80)
You will want to avoid having it go over more than one line in the script call, so if it doesn't fit, set the name or other attributes to a new variable, like this:
n = "Decision2"
change_audio (:decision, n, 65, 100)
Script
#==============================================================================
# Ingame System Audio Definition
# Author: modern algebra (rmrk.net)
# Version: 2.0
# Date Released: June 5, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# This script allows you to change what audio files are associated with the
# system at any time during the game. That's a bit abstract, so an easier way
# to explain it would be that if, for whatever reason, you want to be able to
# change the sound effect that is played when you press enter on something,
# then this script allows you to change that in-game. In other words, you
# don't have to have only one decision SE for the entire game. The same goes
# for all of the BGMs, MEs, and SEs that are set in the System tab of the
# Database, except for the title ones.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Place this script in its own slot in the Script Editor (F11), above Main
# but below Materials.
#
# You can change any of the system audio files in-game using the following
# code in a call script:
#
# change_audio (:type, "filename", volume, pitch)
# type - this is how you set which sound effect to change. The
# possible values are (they correspond to their name in System):
# :cursor, :decision, :cancel, :buzzer, :equip, :save, :load,
# :battle_start, :escape, :enemy_attack, :enemy_damage,
# :enemy_collapse, :actor_damage, :actor_collapse, :recovery,
# :miss, :evasion, :shop, :item_use, :skill_use, :boat, :ship,
# :airship, :battle, :battle_end, :gameover
# filename - the name of the audio file to change to it must be within
# quotation marks. If excluded, it erases the sound altogether.
# volume - the volume you want the audiofile to play at. If excluded,
# this defaults to 100
# pitch - the pitch you want the audiofile to play at. If excluded,
# this defaults to 100
#
# EXAMPLES:
# change_audio (:cursor, "Cursor2", 60)
# change_audio (:gameover,"Victory1",120,80)
#
# You will want to avoid having it go over more than one line in the script
# call, so if it doesn't fit, set the name or other attributes to a new
# variable, like this:
# n = "Decision2"
# change_audio (:decision, n, 65, 100)
#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# new attr_reader - ma_sounds; ma_music
# aliased method - initialize
# new method - set_audiofile
#==============================================================================
class Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_reader :ma_sounds
attr_reader :ma_music
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias malrab_igsd2_inze_4xc9 initialize
def initialize (*args)
malrab_igsd2_inze_4xc9 (*args) # Run Original Method
initialize_system_audio
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Initialize System Audio
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize_system_audio
@ma_sounds = Marshal.load (Marshal.dump($data_system.sounds))
@ma_music = [$data_system.boat.bgm.dup, $data_system.ship.bgm.dup,
$data_system.airship.bgm.dup, $data_system.battle_bgm.dup,
$data_system.battle_end_me.dup, $data_system.gameover_me.dup]
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Set AudioFile
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def set_audiofile (id, name = "", *args)
if id >= @ma_sounds.size
id -= @ma_sounds.size
@ma_music[id] = id < 4 ? RPG::BGM.new (name, *args) : RPG::ME.new (name, *args)
case id
when 0 then $data_system.boat.bgm = $game_system.ma_music[0]
when 1 then $data_system.ship.bgm = $game_system.ma_music[1]
when 2 then $data_system.airship.bgm = $game_system.ma_music[2]
when 3 then $data_system.battle_bgm = $game_system.ma_music[3]
when 4 then $data_system.battle_end_me = $game_system.ma_music[4]
when 5 then $data_system.gameover_me = $game_system.ma_music[5]
end
else
@ma_sounds[id] = RPG::SE.new (name, *args)
$data_system.sounds[id] = @ma_sounds[id]
end
end
end
#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# new method - change_audio
#==============================================================================
class Game_Interpreter
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Change Audio
# type : symbol or integer representing type
# args : the attributes of the new file
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def change_audio (type = nil, *args)
if type.is_a? (Symbol)
id = [:cursor, :decision, :cancel, :buzzer, :equip, :save, :load,
:battle_start, :escape, :enemy_attack, :enemy_damage, :enemy_collapse,
:actor_damage, :actor_collapse, :recovery, :miss, :evasion, :shop,
:item_use, :skill_use, :boat, :ship, :airship, :battle, :battle_end,
:gameover].index (type)
else
id = type
end
return if !id.is_a? (Integer)
$game_system.set_audiofile (id, *args)
end
end
#==============================================================================
# ** Scene File
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - read_save_data
#==============================================================================
class Scene_File
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Read Save Data
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modrabra_isad_rdsvda_5uj8 read_save_data
def read_save_data (*args)
modrabra_isad_rdsvda_5uj8 (*args) # Run Original Method
if $game_system.ma_sounds.nil?
$game_system.initialize_system_audio
else
$data_system.sounds = $game_system.ma_sounds
$data_system.boat.bgm = $game_system.ma_music[0]
$data_system.ship.bgm = $game_system.ma_music[1]
$data_system.airship.bgm = $game_system.ma_music[2]
$data_system.battle_bgm = $game_system.ma_music[3]
$data_system.battle_end_me = $game_system.ma_music[4]
$data_system.gameover_me = $game_system.ma_music[5]
end
end
end
Credit
Thanks
- Zylos, for pointing out the problem
Support
Just post in this topic.
Known Compatibility Issues
I don't forsee any compatibility problems that can't be fixed by putting this script below any of your other custom scripts, but still above Main.
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.