Save-Point
KMapAudio - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: KMapAudio (/thread-8091.html)



KMapAudio - kyonides - 07-06-2020

KMapAudio

by Kyonides Arkanthes


Introduction

Did you ever wanted not to keep the current map's BGM or BGS because the in game atmosphere had changed?
Let's say you wanted to let the player know that a previously visited town has changed. Perhaps it's now decadent or somber. Confused 
OK, you could just change the playing BGM but let's be honest, that's a tremendous job to keep track of all of the changes that implies! Sad 
Well, not anymore! With my scriptlet you can change it once in a single place that will be executed just once! Shocked
The best part is it lets you save and load this change automatically! Grinning

Script for XP

Code:
# * KMapAudio XP
#   Scripter : Kyonides Arkanthes
#   v0.1.0

# * Script Calls * #

# To set a new Map BGM or BGS
# # You can also add Volume and Pitch as optional parameters!
#   KMap.new_bgm(MapID, BGMname)
#   KMap.new_bgs(MapID, BGSname)

module KMap
 def self.setup_audio_file(name, args)
   volume = args[0] || 80
   pitch = args[1] || 100
   RPG::AudioFile.new(name, volume, pitch)
 end

 def self.new_bgm(map_id, name, *args)
   file = setup_audio_file(name, args)
   $game_system.set_alt_bgm(map_id, file)
 end

 def self.new_bgs(map_id, name, *args)
   file = setup_audio_file(name, args)
   $game_system.set_alt_bgs(map_id, file)
 end
end

class Game_System
 alias :kyon_md_gm_sys_init :initialize
 def initialize
   kyon_md_gm_sys_init
   @alternate_bgm = {}
   @alternate_bgs = {}
 end

 def set_alt_bgm(map_id, file)
   @alternate_bgm[map_id] = file
   bgm_play(file)
 end

 def set_alt_bgs(map_id, file)
   @alternate_bgs[map_id] = file
   bgs_play(file)
 end
 attr_reader :alternate_bgm, :alternate_bgs
end

class Game_Map
 alias :kyon_md_gm_map_setup :setup
 def setup(map_id)
   kyon_md_gm_map_setup(map_id)
   alt_bgm = $game_system.alternate_bgm[map_id]
   alt_bgs = $game_system.alternate_bgs[map_id]
   @map.bgm = alt_bgm if alt_bgm
   @map.bgs = alt_bgs if alt_bgs
 end
end


Script for VX or ACE

Code:
# * KMapAudio ACE
#   Scripter : Kyonides Arkanthes
#   v0.1.0

# * Script Calls * #

# To set a new Map BGM or BGS
# # You can also add Volume and Pitch as optional parameters!
#   KMap.new_bgm(MapID, BGMname)
#   KMap.new_bgs(MapID, BGSname)

module KMap
 def self.new_bgm(map_id, name, *args)
   volume = args[0] || 80
   pitch = args[1] || 100
   file = RPG::BGM.new(name, volume, pitch)
   $game_system.alternate_bgm[map_id] = file
   file.play
 end

 def self.new_bgs(map_id, name, *args)
   volume = args[0] || 80
   pitch = args[1] || 100
   file = RPG::BGS.new(name, volume, pitch)
   $game_system.alternate_bgs[map_id] = file
   file.play
 end
end

class Game_System
 alias :kyon_md_gm_sys_init :initialize
 def initialize
   kyon_md_gm_sys_init
   @alternate_bgm = {}
   @alternate_bgs = {}
 end
 attr_reader :alternate_bgm, :alternate_bgs
end

class Game_Map
 alias :kyon_md_gm_map_setup :setup
 def setup(map_id)
   kyon_md_gm_map_setup(map_id)
   alt_bgm = $game_system.alternate_bgm[map_id]
   alt_bgs = $game_system.alternate_bgs[map_id]
   @map.bgm = alt_bgm if alt_bgm
   @map.bgs = alt_bgs if alt_bgs
 end
end




Terms & Conditions

Happy with a sweat I guess it's free for non commercial games.
By the way, I only support the latest version of my scripts. Laughing
Give me a free copy of your completed game if you include at least 2 of my scripts! Laughing + Tongue sticking out