Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Randomized Door Sounds Script — Enhanced from keithcurtis' Original

March 28 (4 days ago)

Edited March 28 (4 days ago)

Hello, I've made a little update to a simple but awesome script I found on here posted over 2 years ago by the amazing keithcurtis.

Credit for the original script goes fully to keithcurtis.

In his words, his script "plays a door open noise when you open a door and a close noise when you close it. If the door is hidden, it stays silent. Note that you will have to upload your own jukebox tracks and the names of the tracks and the names in the script will need to match."

I wished to utilize multiple sounds for both opening and closing doors instead of the same sound each time, so I edited it a bit to allow for a random function to choose any of the sounds randomly. Note that you will still need to upload your own tracks into your game with matching track names for what is written in the script.

In the script, you can add more sounds to randomly choose from, and edit the names of the tracks uploaded to your game in lines 21 and 25.

You can view the original post by keithcurtis Here.


on('ready', () => {
    const getRandomTrack = (tracks) => tracks[Math.floor(Math.random() * tracks.length)];
    let playSound = function (trackname, action) {
        let track = findObjs({ type: 'jukeboxtrack', title: trackname })[0];
        if (track) {
            track.set('playing', false);
            track.set('softstop', false);
            if (action === 'play') {
                track.set('playing', true);
            }
        } else {
            sendChat('Doorsound', `/w gm No Track Found: ${trackname}`);
            log("No track found: " + trackname);
        }
    };
    on("change:door:isOpen", function (obj, prev) {
        if (!prev.isSecret) {
            if (prev.isOpen) {
                const closeSounds = ["Door-Close 1", "Door-Close 2", "Door-Close 3"];
                const randomClose = getRandomTrack(closeSounds);
                playSound(randomClose, 'play');
            } else {
                const openSounds = ["Door-Open 1", "Door-Open 2"];
                const randomOpen = getRandomTrack(openSounds);
                playSound(randomOpen, 'play');
            }
        }
    });
});
March 29 (3 days ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

seal of approval Blank Template - Imgflip