//=============================================================================// New Game Random Sound//=============================================================================var Imported = Imported || {};Imported.RandomSound = true;var Sound = Sound || {};//==============================================================================/*: * @author お兄ちゃん大好き * * @plugindesc (V1.2) Randomly play se when player press the "New Game" button * * @param Sound Files for New Game * * @desc List all sound files here you wish to play randomly for New Game. Seperate each sound file with ";". * * @param Sound Files for Continue * * @desc List all sound files here you wish to play randomly For Continue. Seperate each sound file with ";". * * @help * This plugin only has one parameter, which is sound list that will be played * randomly when player press the "New Game" button. * * **The form of the parameter** * FileName1, volume, pitch, pan; FileName2, volume, pitch, pan * E.g. Attack1,100,100,0; Attack2,90,120,0 * * Spaces are allowed but NO TRAILING ";" * * //========================================================================= * // Change Log * //========================================================================= * 2020-5-15 v1.0 * Plugin finished * * 2020-5-16 v1.1 * Optimisation of the algorithm for randomly playing sound effect * * 2020-5-16 v1.2 * New function that randomly play sound effect for Continue button, same as * the "New Game" */ //============================================================================= // Read Files and Initialsing //============================================================================= Sound.Param = PluginManager.parameters('RandomSound'); newGame = String(Sound.Param['Sound Files for New Game']); newGame = newGame.split(';'); conti = String(Sound.Param['Sound Files for Continue']); conti = conti.split(';'); for (i = 0; i < newGame.length; i++) { var property = new Object(newGame[i].split(',')); newGame[i] = {}; newGame[i].name = String(property[0].trim()); newGame[i].volume = Number(property[1].trim()); newGame[i].pitch = Number(property[2].trim()); newGame[i].pan = Number(property[3].trim()); }; for (i = 0; i < conti.length; i++) { var property = new Object(conti[i].split(',')); conti[i] = {}; conti[i].name = String(property[0].trim()); conti[i].volume = Number(property[1].trim()); conti[i].pitch = Number(property[2].trim()); conti[i].pan = Number(property[3].trim()); }; (function() { //============================================================================= // Override the new game function //============================================================================= var randomSound_NewGame = Window_TitleCommand.prototype.processOk; Window_TitleCommand.prototype.processOk = function() { randomSound_NewGame.call(this); if (this.isCurrentItemEnabled() && Window_TitleCommand._lastCommandSymbol == 'newGame') { this.playRandomSoundNewGame(); } else if (this.isCurrentItemEnabled() && Window_TitleCommand._lastCommandSymbol == 'continue') { this.playRandomSoundContinue(); }; }; //============================================================================= // Algorithm for randomly playing sound //============================================================================= Window_TitleCommand.prototype.playRandomSoundNewGame = function() { var rate = 0; if (newGame.length > 1) { rate = Math.floor(Math.random() * newGame.length); }; if (newGame.length != 0) AudioManager.playSe( {"name":newGame[rate].name, "volume":newGame[rate].volume, "pitch":newGame[rate].pitch, "pan":newGame[rate].pan} ); }; Window_TitleCommand.prototype.playRandomSoundContinue = function() { var rate = 0; if (conti.length > 1) { rate = Math.floor(Math.random() * conti.length); }; if (conti.length != 0) AudioManager.playSe( {"name":conti[rate].name, "volume":conti[rate].volume, "pitch":conti[rate].pitch, "pan":conti[rate].pan} ); };})();复制代码