Playing random sound when starting new game

Pooky

LadyDusk
Member
Joined
Sep 9, 2019
Messages
10
Reaction score
5
First Language
german
Primarily Uses
RMMV
Hello there!
Soo I have a new thing I wanna add into a game.
Now I'm pretty sure this needs a plugin, but I don't know if it exists yet.
Basically, what I want to do is, when you start the game, get to the menu and press "New game" I want it to play a sound file. But since it is a community project and many people are going to work on it, I want it to play a random soundfile out of a specific assortment.
Example: I want the game to randomly choose out of the files "Dana_Start.ogg", "Larry_Start.ogg" and "Patrick_Start.ogg" which one it will play when you press start. And every time you start the game again, it should randomly choose a soundfile out of these 3 again.
Ehh, I hope this wasn't too complicated now, it's kinda hard to explain... :elswt:
So I've been searching the web for this kind of plugin already but just found some that play one specific sound at the start, and don't have the function to randomly choose between several.

If someone could help me, that'd be great. If it's not possible, then that's fine too.
Have a nice day. :)
 

Ritter

Veteran
Veteran
Joined
Jan 17, 2017
Messages
64
Reaction score
30
First Language
English
Primarily Uses
RMMV
I created a little plugin to handle this for you, if you have any problems be sure to let me know, i think i made it rather simple to use. Just follow the instructions in the help.

Download the attached plugin file or copy/paste the code below and follow the instructions :)

Name this file: NewGame_RandomSE.js

Place this file in your js/plugins folder.

Set up the parameter with the filenames you wish to have added to the random selection and you're good to go.

Setup Volume, Pitch, and Pan parameters.

and you should be good to go.

JavaScript:
/*:
*
* @plugindesc Play Random SE on New Game.
*
* @author Ritter
*
*
* @param SE Filename List
* @desc List of SE filenames. ex: Cat, Cow, Crow
*
* @param SE Volume
* @type number
* @max 100
* @min 0
* @desc Volume of sound effect.
* 100 = Max volume. 0 = Sweet silence.
* 
*
* @param SE Pitch
* @desc Pitch of sound effect.
* 100 recommended.
* @type number
* @max 150
* @min 50
* 
*
* @param SE Pan
* @desc Pan of sound effect.
* 0 recommended.
* @type number
* @max 100
* @min -100
* 
*
*
* @help
*
* Play a random sound effect every time you hit new game on title screen!
* Just place a list of all Sound Effects you wish to randomly choose from
* in the plugin parameter separated as shown in the description example.
*
* Do not include the .ogg just the filename.
*
*
* Example: Cat, Cow, Crow
*
*
* Be sure to separate each with a comma.
*
* You can add as many sound effects to this list as you wish.
*/

// -----------------------------------------------------------------
// CODE STUFF
// -----------------------------------------------------------------

var Imported = Imported || {};
Imported.NewGame_RandomSE = true;

var Ritter = Ritter || {};          // Ritter main object
Ritter.Params = Ritter.Params || {};        // Ritter stuff

var parameters = PluginManager.parameters('NewGame_RandomSE');
Ritter.Params.filenames = String(parameters["SE Filename List"]);
Ritter.Params.SEvolume = Number(parameters["SE Volume"]);
Ritter.Params.SEpitch = Number(parameters["SE Pitch"]);
Ritter.Params.SEpan = Number(parameters["SE Pan"]);

(function() {



Window_Selectable.prototype.processOk = function() {
    if (this.isCurrentItemEnabled()) {
        if (Window_TitleCommand._lastCommandSymbol == 'newGame' && SceneManager._scene instanceof Scene_Title) {
            var filename = Ritter.randomSe();
            AudioManager.playSe({name: filename, volume: Ritter.Params.SEvolume, pitch: Ritter.Params.SEpitch, pan: Ritter.Params.SEpan});
        } else {
        this.playOkSound();
        }
        this.updateInputData();
        this.deactivate();
        this.callOkHandler();
    } else {
        this.playBuzzerSound();
    }
};

Ritter.randomSe = function() {
    var filenames = Ritter.Params.filenames.split(', ');
    var min = 0;
    var max = filenames.length;
    
    return filenames[Math.floor(Math.random() * max)];

};


})();
 

Attachments

Last edited:

AnNihilate

Villager
Member
Joined
Nov 8, 2018
Messages
7
Reaction score
1
First Language
日本語JP/中文CN
Primarily Uses
RMMV
Hi, I also did a mini plugin similar as the above that will satisfy your need. But in this plugin, you can set volume, pitch and pan on your own. The way to do this can be found in the plugin help area. You can simply copy the code or download it directly.

Hope this can solve your problems. Thanks.

JavaScript:
//=============================================================================
//  New Game Random Sound
//=============================================================================

var Imported = Imported || {};
Imported.RandomSound = true;
var Sound = Sound || {};

//==============================================================================
/*:
 * @author AnN
 *
 * @plugindesc Randomly play se when player press the "New Game" button
 *
 * @param Sound Files
 *
 * @desc List all sound files here you wish to play randomly. 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 ";"
 */

(function() {
    //=============================================================================
    //    Read Files and Initialsing
    //=============================================================================
    Sound.Param = PluginManager.parameters('RandomSound');
    sounds = String(Sound.Param['Sound Files']);
    sounds = sounds.split(';');
    
    for (i = 0; i < sounds.length; i++) {
        var property = new Object(sounds[i].split(','));
        sounds[i] = {};
        sounds[i].name = String(property[0].trim());
        sounds[i].volume = Number(property[1].trim());
        sounds[i].pitch = Number(property[2].trim());
        sounds[i].pan = Number(property[3].trim());
    };

    //=============================================================================
    //    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.playRandomSound();
        };
    };

    //=============================================================================
    //    Algorithm for randomly playing sound
    //=============================================================================
    Window_TitleCommand.prototype.playRandomSound = function() {
        var maxRate = 0;
        
        if (sounds.length > 1) {
            for (i = 0; i < sounds.length; i++) {
                sounds[i].rate = 0;
                sounds[i].rate = Math.floor(Math.random() * 11);
                if (sounds[i].rate > maxRate) maxRate = sounds[i].rate;
            };
        } else if (sounds.length === 1) {
            AudioManager.playSe( {"name":sounds[0].name, "volume":sounds[0].volume, "pitch":sounds[0].pitch, "pan":sounds[0].pan} );
        };
        
        for (i = 0; i < sounds.length; i++) {
            if (sounds[i].rate === maxRate) {
                AudioManager.playSe( {"name":sounds[i].name, "volume":sounds[i].volume, "pitch":sounds[i].pitch, "pan":sounds[i].pan} );
                break;
            };
        };
    };

})();
 

Attachments

Pooky

LadyDusk
Member
Joined
Sep 9, 2019
Messages
10
Reaction score
5
First Language
german
Primarily Uses
RMMV
Thank both of you! It works perfectly! Exactly what I was looking for. :)

Edit: I hope I don't sound greedy now, but is it possible to achieve the same thing for the "continue" option? If it's too much work, just ignore this!
 
Last edited:

Ritter

Veteran
Veteran
Joined
Jan 17, 2017
Messages
64
Reaction score
30
First Language
English
Primarily Uses
RMMV
it would be an incredibly easy edit of either one of our tiny plugins xD

if you used mine edit this line

if (Window_TitleCommand._lastCommandSymbol == 'newGame' && SceneManager._scene instanceof Scene_Title) {

to look like this

if ((Window_TitleCommand._lastCommandSymbol == 'newGame' || Window_TitleCommand._lastCommandSymbol == 'continue') && SceneManager._scene instanceof Scene_Title)

Or if you used AnN's edit this line

if (this.isCurrentItemEnabled() && Window_TitleCommand._lastCommandSymbol == 'newGame')

to look like this

if (this.isCurrentItemEnabled() && (Window_TitleCommand._lastCommandSymbol == 'newGame' || Window_TitleCommand._lastCommandSymbol == 'continue'))

be sure not to delete/remove the { which follows at the end of each line, its important.

I can also look into doing it for when you select a save file as well in the save scene if you'd like :)
 
Last edited:

Pooky

LadyDusk
Member
Joined
Sep 9, 2019
Messages
10
Reaction score
5
First Language
german
Primarily Uses
RMMV
it would be an incredibly easy edit of either one of our tiny plugins xD

if you used mine edit this line

if (Window_TitleCommand._lastCommandSymbol == 'newGame' && SceneManager._scene instanceof Scene_Title) {

to look like this

if ((Window_TitleCommand._lastCommandSymbol == 'newGame' || Window_TitleCommand._lastCommandSymbol == 'continue') && SceneManager._scene instanceof Scene_Title)

Or if you used AnN's edit this line

if (this.isCurrentItemEnabled() && Window_TitleCommand._lastCommandSymbol == 'newGame')

to look like this

if (this.isCurrentItemEnabled() && (Window_TitleCommand._lastCommandSymbol == 'newGame' || Window_TitleCommand._lastCommandSymbol == 'continue'))

be sure not to delete/remove the { which follows at the end of each line, its important.

I can also look into doing it for when you select a save file as well in the save scene if you'd like :)
Aaa, I seriously can't thank you enough! It's perfect. :D
And no need for the save scene, this is all I needed, thank you! :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,456
Members
137,821
Latest member
Capterson
Top