Elemental Crisis 14 Posted December 5, 2011 Script Name: Volume Control Author: Ru/ã‚€ã£ãRu (English Translation By: Elemental Crisis) Version: 1.0.0 Number Of Scripts: 1 Description: This script will allow you to add a volume control setting. Screenshots: Instructions: 1. This first step is optional but I like to keep all my scripts organized so make a new section above MAIN and call it "Volume Control". 2. Copy the script EXACTLY how its shown into the "Volume Control" section. Frequently Asked Questions: None Script: Volume Control.txt 3 Share this post Link to post Share on other sites
EBelle 12 Posted December 6, 2011 Neat script. Thanks for the translation, Elemental. Share this post Link to post Share on other sites
killer bon bon 27 Posted December 6, 2011 Little features like this really make a game better. Thank you. Share this post Link to post Share on other sites
ShadeTerror 1 Posted December 7, 2011 Yay no more getting caught debugging projects in class -.- Really useful script thank you for translating Elemental Crisis.(Awesome name btw) Share this post Link to post Share on other sites
xmartyr7 45 Posted December 8, 2011 This would be great if it was a bar instead of a 100 - 0 number. Any chance you could use Syvkal's menu bars and make it with bars instead of numbers? Share this post Link to post Share on other sites
kal 40 Posted December 9, 2011 Very cool script! Thanks for taking the time to translate it. I went through this script to figure out how it works and I made some small changes to it. If anyone is interested you can find my version here: https://gist.github.com/1453058 I mostly changed the formatting so it's a little closer to the Ruby convention, and I refactored some parts of the code that were duplicated unnecessarily. I also fixed one bug in this section: alias hzm_Vol_Audio_bgm_play bgm_play def bgm_play(filename, volume=100, pitch=100, pos=0) volume = self.volBGM * volume / 100 hzm_Vol_Audio_bgm_play(filename, volume, pitch, pos) end My guess is that the author intended this code to work in the following way: if someone calls the bgm_play (or the other play methods) and supplies a volume value less than 100, it should divide that value by 100 and then multiply it with the volBGM value (which is what the player sets in the script). In that way if someone called bgm_play with a volume of 50, it would play the BGM at a sound level of 50 % of the volBGM value, which makes sense. However, he forgot to convert the value into a float, so in the current version if another script calls bgm_play with a value less than hundred the volume / 100 expression will evaluate to 0, which in turn will set volume to 0. To get a rational value one of the operands needs to be a float, which is easily done by changing that line ike this: volume = self.volBGM * volume.to_f / 100 This would be great if it was a bar instead of a 100 - 0 number. Any chance you could use Syvkal's menu bars and make it with bars instead of numbers? That's a good idea. I might look in to this and see if I can implement it, but I'm not promising anything! Share this post Link to post Share on other sites
kal 40 Posted December 10, 2011 I made my own bars because it's so easy. # encoding: utf-8 #=============================================================================== # �¡ Volume Control For RGSS3 #------------------------------------------------------------------------------- #�@2011/12/01�@Ru/‚ނÂÂR #------------------------------------------------------------------------------- # English Translation By: Elemental Crisis (http://RPGMakerVXAce.com) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # Bug fixes and menu bars added by Kal. #------------------------------------------------------------------------------- # #�@Adds the ability to change volume control. # #�@�œ The following methods are added to the Audio Module #�@Audio.volBGM �c�c Maximum BGM volume setting. #�@Audio.volBGS �c�c Maximum BGS volume setting. #�@Audio.volSE �c�c Maximum SE volume setting. #�@Audio.volME �c�c Maximum ME volume setting. #�@Audio.volBGM=�â€â€™l �c�cSet BGM maximum volume (0-100) #�@Audio.volBGM=�â€â€™l �c�c Set BGS maximum volume (0-100) #�@Audio.volSE=�â€â€™l �c�c Set SE maximum volume (0-100) #�@Audio.volME=�â€â€™l �c�c Set ME maximum volume (0-100) # #�@�œ Volume control is added to the main menu. # #------------------------------------------------------------------------------- # �yKnown Issues�z #�@Created before VXAce's official release so unable to properly test. #------------------------------------------------------------------------------- #============================================================================== # �œ Settings #============================================================================== module HZM_VXA module AudioVol # Display Volume Control on Main Menu? # �@true �c�c Display. # �@false �c�c Don't Display. MENU_FLAG = true # Volume Control Name in Main Menu. MENU_NAME = "Volume Settings" # Volume Control Settings Name. CONFIG_BGM_NAME = "BGM" CONFIG_BGS_NAME = "BGS" CONFIG_SE_NAME = "SE" CONFIG_ME_NAME = "ME" CONFIG_EXIT_NAME = "Exit" # Volume Change Variation. # ADD_VOL_NORMAL �c�c Variation of Left/Right Keys. # ADD_VOL_HIGH �c�c Variation of LR Key. ADD_VOL_NORMAL = 5 ADD_VOL_HIGH = 25 # Use bars or numbers. # :bars => use bars # :numbers => use numbers DISPLAY = :bars # Bar display options. # The higher BAR_X the more to the right the bar is drawn. # BAR_WIDTH sets the width of the bar. # Y_ADJUST allows you to precisely adjust the y value (how high or low # the bar is rendered). BAR_X = 55 BAR_WIDTH = 70 Y_ADJUST = -3 end end #============================================================================== # �ª �@ Settings Above �@ �ª # �« Script Below �« #============================================================================== # Additonal Methods. # class << Audio means we open up the Audio module and all methods defined # get defined on self (that is, the Audio module itself) class << Audio def volBGM=(vol) @hzmVolBGM = normalize_volume(vol) end def volBGS=(vol) @hzmVolBGS = normalize_volume(vol) end def volSE=(vol) @hzmVolSE = normalize_volume(vol) end def volME=(vol) @hzmVolME = normalize_volume(vol) end def volBGM @hzmVolBGM.nil? ? @hzmVolBGM = 100 : @hzmVolBGM end def volBGS @hzmVolBGS.nil? ? @hzmVolBGS = 100 : @hzmVolBGS end def volSE @hzmVolSE.nil? ? @hzmVolSE = 100 : @hzmVolSE end def volME @hzmVolME.nil? ? @hzmVolME = 100 : @hzmVolME end # Make sure volume does not go over 100 or under 0. def normalize_volume(vol) vol = 100 if vol > 100 vol = 0 if vol < 0 vol end # Playback alias hzm_Vol_Audio_bgm_play bgm_play def bgm_play(filename, volume=100, pitch=100, pos=0) volume = self.volBGM * volume.to_f / 100 hzm_Vol_Audio_bgm_play(filename, volume, pitch, pos) end alias hzm_Vol_Audio_bgs_play bgs_play def bgs_play(filename, volume=100, pitch=100) volume = self.volBGS * volume.to_f / 100 hzm_Vol_Audio_bgs_play(filename, volume, pitch) end alias hzm_Vol_Audio_se_play se_play def se_play(filename, volume=100, pitch=100) volume = self.volSE * volume.to_f / 100 hzm_Vol_Audio_se_play(filename, volume, pitch) end alias hzm_Vol_Audio_me_play me_play def me_play(filename, volume=100, pitch=100) volume = self.volME * volume.to_f / 100 hzm_Vol_Audio_me_play(filename, volume, pitch) end end # Add To Menu. if HZM_VXA::AudioVol::MENU_FLAG class Window_MenuCommand alias hzm_Vol_Window_MenuCommand_add_original_commands add_original_commands def add_original_commands hzm_Vol_Window_MenuCommand_add_original_commands add_command(HZM_VXA::AudioVol::MENU_NAME, :hzm_vxa_vol) end end class Scene_Menu alias hzm_Vol_create_command_window create_command_window def create_command_window hzm_Vol_create_command_window @command_window.set_handler(:hzm_vxa_vol, method(:hzm_vxa_vol)) end def hzm_vxa_vol SceneManager.call(HZM_VXA::AudioVol::Scene_VolConfig) end end end # Volume Change Window module HZM_VXA module AudioVol class Window_VolConfig < Window_Command def initialize super(0, 0) self.x = (Graphics.width - self.window_width)/2 self.y = (Graphics.height - self.window_height)/2 end def make_command_list add_command(HZM_VXA::AudioVol::CONFIG_BGM_NAME, :bgm) add_command(HZM_VXA::AudioVol::CONFIG_BGS_NAME, :bgs) add_command(HZM_VXA::AudioVol::CONFIG_SE_NAME, :se) add_command(HZM_VXA::AudioVol::CONFIG_ME_NAME, :me) add_command(HZM_VXA::AudioVol::CONFIG_EXIT_NAME, :cancel) end def draw_item(index) super return unless index < 4 case index when 0 vol = Audio.volBGM when 1 vol = Audio.volBGS when 2 vol = Audio.volSE when 3 vol = Audio.volME end # Draws vol as a number or as a bar. if DISPLAY == :bars y = (index * line_height) + Y_ADJUST draw_gauge(BAR_X, y, BAR_WIDTH, vol / 100.0, normal_color, normal_color) else draw_text(item_rect_for_text(index), vol, 2) end end def volAdd(index, val) case index when 0 Audio.volBGM += val now = RPG::BGM.last Audio.bgm_play('Audio/BGM/' + now.name, now.volume, now.pitch, now.pos) if now when 1 Audio.volBGS += val when 2 Audio.volSE += val when 3 Audio.volME += val end Sound.play_cursor redraw_item(index) end def cursor_left(wrap = false) volAdd(@index, -HZM_VXA::AudioVol::ADD_VOL_NORMAL) end def cursor_right(wrap = false) volAdd(@index, HZM_VXA::AudioVol::ADD_VOL_NORMAL) end def cursor_pageup volAdd(@index, -HZM_VXA::AudioVol::ADD_VOL_HIGH) end def cursor_pagedown volAdd(@index, HZM_VXA::AudioVol::ADD_VOL_HIGH) end end class Scene_VolConfig < Scene_MenuBase def start super @command_window = Window_VolConfig.new @command_window.viewport = @viewport @command_window.set_handler(:cancel, method(:return_scene)) end def terminate super @command_window.dispose end end end end # Reading/Saving class << DataManager alias hzm_Vol_make_save_contents make_save_contents def make_save_contents contents = hzm_Vol_make_save_contents contents[:hzm_vxa_vol] = { :bgm => Audio.volBGM, :bgs => Audio.volBGS, :se => Audio.volSE, :me => Audio.volME } contents end alias hzm_Vol_extract_save_contents extract_save_contents def extract_save_contents(contents) hzm_Vol_extract_save_contents(contents) Audio.volBGM = contents[:hzm_vxa_vol][:bgm] Audio.volBGS = contents[:hzm_vxa_vol][:bgs] Audio.volSE = contents[:hzm_vxa_vol][:se] Audio.volME = contents[:hzm_vxa_vol][:me] end end Syvkal's menu bars are a little overkill for this script I think. (by the way I put in an option so you can choose whether you want numbers or bars) And I hope the guy who wrote the script doesn't mind that I edited the script. I put my name in the script header, not because I want credit or anything, just so people can see that it's not the original script. If you want to see it done differently or you think it can be improved in some way let me know and I'll look at it. 1 Share this post Link to post Share on other sites
xmartyr7 45 Posted December 14, 2011 (edited) Kudos to both Elemental Crisis and kal. Good job, guys. Edited December 14, 2011 by monstrumgod Share this post Link to post Share on other sites
Azaarious 1 Posted February 2, 2012 Thanks man this is awesome, IDK how many times people have downloaded my demos and asked if they could turn down the sound. Great job. Share this post Link to post Share on other sites
Tobyej 4 Posted February 4, 2012 Found a bug where the game crashes if a BGS would play: 'Script Interpretor' line: 1010 Argument Error occurred Wrong number of arguments (4 for 3) I spent quite a while in panic mode after for some unknown reason my earlier maps would crash ^^ Share this post Link to post Share on other sites
NS 6 Posted March 15, 2012 Lol. I know this is necroposting in general, but since there isn't a patch to this, I thought I could post some snippets here that can fix the BGS-playing problem... Highlight all of the code in lines 127-129, and replace it with this modified snippet. def bgs_play(filename, volume=100, pitch=100, pos=0) volume = self.volBGS * volume.to_f / 100 hzm_Vol_Audio_bgs_play(filename, volume, pitch, pos) Hit enter after line 213 of the code, and paste this in there. now = RPG::BGS.last Audio.bgs_play('Audio/BGS/' + now.name, now.volume, now.pitch, now.pos) if now Or you could just take the easy way out and download the text file for a simple copy-and-paste overwrite. Volume Control Patched.txt In any case, thanks for the script translation Elemental Crisis. And thanks Kal, for the graphical bars modification. This makes for a neat little addition to my project. Share this post Link to post Share on other sites
Kalez 16 Posted March 15, 2012 (edited) Lol. I know this is necroposting in general, but since there isn't a patch to this, I thought I could post some snippets here that can fix the BGS-playing problem... Highlight all of the code in lines 127-129, and replace it with this modified snippet. def bgs_play(filename, volume=100, pitch=100, pos=0) volume = self.volBGS * volume.to_f / 100 hzm_Vol_Audio_bgs_play(filename, volume, pitch, pos) Hit enter after line 213 of the code, and paste this in there. now = RPG::BGS.last Audio.bgs_play('Audio/BGS/' + now.name, now.volume, now.pitch, now.pos) if now Or you could just take the easy way out and download the text file for a simple copy-and-paste overwrite. Volume Control Patched.txt In any case, thanks for the script translation Elemental Crisis. And thanks Kal, for the graphical bars modification. This makes for a neat little addition to my project. Not sure what the problem is, but when i installed your fixed version, every time i tried to alter the BGM or BGS volume it errored saying it couldnt find the Audio/BGM or Audio/BGS files. Edit: nvm my fix didnt work, but yours is still erroring... Edit2: it only seems to error when using numbers. bars work fine. Edited March 15, 2012 by Kalez Share this post Link to post Share on other sites
NS 6 Posted March 15, 2012 It seems to work perfectly on my project here. D: Are you running the trial version or full version? I'm running the full version here myself, and my project isn't bound to trial-rules, so I'm not sure if it'll work for the trial version... And did you place the script over main but under materials? (I know it's a noob question, but I always gotta ask these...I do this myself all the time, and I often have to troubleshoot myself with those.) Share this post Link to post Share on other sites
Kalez 16 Posted March 15, 2012 It seems to work perfectly on my project here. D: Are you running the trial version or full version? I'm running the full version here myself, and my project isn't bound to trial-rules, so I'm not sure if it'll work for the trial version... And did you place the script over main but under materials? (I know it's a noob question, but I always gotta ask these...I do this myself all the time, and I often have to troubleshoot myself with those.) its working... i think maybe i typed ":number" instead of ":numbers". i do feel like a noob now lol. Share this post Link to post Share on other sites
NS 6 Posted March 15, 2012 Ah. Lol. No matter how much experience you have with programming, you will always fall victim to the tiny syntax error part every now and then. XD Glad to know it's working for you. Share this post Link to post Share on other sites
Kalez 16 Posted March 15, 2012 (edited) it happens to the best of us Edited March 15, 2012 by Kalez Share this post Link to post Share on other sites
Abi 0 Posted December 16, 2012 Lol. I know this is necroposting in general, but since there isn't a patch to this, I thought I could post some snippets here that can fix the BGS-playing problem... Highlight all of the code in lines 127-129, and replace it with this modified snippet. def bgs_play(filename, volume=100, pitch=100, pos=0) volume = self.volBGS * volume.to_f / 100 hzm_Vol_Audio_bgs_play(filename, volume, pitch, pos) Hit enter after line 213 of the code, and paste this in there. now = RPG::BGS.last Audio.bgs_play('Audio/BGS/' + now.name, now.volume, now.pitch, now.pos) if now Or you could just take the easy way out and download the text file for a simple copy-and-paste overwrite. Volume Control Patched.txt In any case, thanks for the script translation Elemental Crisis. And thanks Kal, for the graphical bars modification. This makes for a neat little addition to my project. Not sure what the problem is, but when i installed your fixed version, every time i tried to alter the BGM or BGS volume it errored saying it couldnt find the Audio/BGM or Audio/BGS files. Edit: nvm my fix didnt work, but yours is still erroring... Edit2: it only seems to error when using numbers. bars work fine. I know this is yet some more necroposting, but just in case anyone else is still experiencing this problem occasionally and wondering wth is going on... the problem is when "now" is an empty object. Or technically when ANY RPG::AudioFile object is empty and you attempt to "play" it, it'll throw a file not found. It took quite a bit of digging for me to figure out how to test for an empty AudioFile object correctly, because the code already attempts to do this as written, but it's incorrectly written. However if you look in the VX Ace Help file, under RGSS Reference Manual, Game Library, RPGVXAce Data Structures, RPG::AudioFile, RPG::BGM... Inside the code snippet that follows the documentation you'll notice the method, "@name.empty?" is used as a test... So I figured, hey, maybe we can call it ourselves too and this is the method we're looking for? And sure enough, it works! So now if you use this script when on a map without BGM or BGS, it will no longer throw errors using my fixed version below. I also changed up some other stuff to make line lengths match up with some decent coding standards. Or, just change lines 211 and 215 of NS's version above like follows for "just the fix k'thx'bai": 211 was: Audio.bgm_play('Audio/BGM/' + now.name, now.volume, now.pitch, now.pos) if now necessary change: Audio.bgm_play('Audio/BGM/' + now.name, now.volume, now.pitch, now.pos) if !now.name.empty? 215 was: Audio.bgs_play('Audio/BGS/' + now.name, now.volume, now.pitch, now.pos) if now necessary change: Audio.bgs_play('Audio/BGS/' + now.name, now.volume, now.pitch, now.pos) if !now.name.empty? I might do some more generalized cleanup later and post a new thread with a pretty well completely revamped script. I'm kinda actually thinking it'd be better to just do a complete rewrite though. Share this post Link to post Share on other sites
Shinma 3 Posted January 7, 2013 Very useful, thank you both! Share this post Link to post Share on other sites
Nosleinad 1 Posted February 27, 2013 (edited) (Sry about reviving the topic, but as this is the original i didn't want to create another one just for this) Is there a way to call the scene manuallt, as i am using Xs Menu Delux? I tryed this script command but it didn't work: SceneManager.call(Scene_VolConfig) Edited February 27, 2013 by Nosleinad Share this post Link to post Share on other sites
BigDon 3 Posted March 6, 2013 (edited) Thanks all for the nice script and for the updates / patch-notes to get it working properly with Rpg-VX-Ace. I was wondering, what is the terms-of-use of this script? Who is proper credit to be given to? And is this script allowed to be used in Commecial Projects as well? Edited March 6, 2013 by BigDon Share this post Link to post Share on other sites
GreenGERMBUBBLE 0 Posted September 8, 2013 Hey so probably a dumb problem. But I'm new to Ruby and RPG Maker. So, I added the script. AND it doesn't work. Here's the error I'm getting for this "Script 'Volume Control' line 147: NameError occured. undefined method 'add_original_commands' for class 'Window_MenuCommand' Thanks for any help Share this post Link to post Share on other sites