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

[Scriplet] Update to KeithCurtis' Doornoise

February 25 (1 month ago)

In preparation for running a one-shot for my group, I came across this very useful API script by Keith Curtis (https://app.roll20.net/forum/post/11244006/scriptlet-doornoise/?pageforid=11244006#post-11244006). Although it was exactly what I needed, I realized it could only have 1 set of open/close sounds. Every door in the map would use the same files. I, unfortunately, had different "types" of doors. One was regular doors, the others were vent entrances. I wanted to have a different sound for open/closing a "vent". So, I changed the code to be what it is now. It allows you to have up to 7 different individual sets of sounds based on the doors color.

The colors available are: Black (#000000), Blue (#0000FF), Green (#00FF00), Orange (#FFA500), Purple (#800080), Red (#FF0000), and Yellow (#FFFF00). You place a door down, change the "Door Line Color" to one of these, and then label the corresponding sound file in your jukebox to "[Color]-Door-Open" and "[Color]-Door-Close" (i.e. "Red-Door-Open" "Red-Door-Close"). 

Selecting any other color that isn't listed on here will default the sound played to the corresponding Black door sound files.


Anyway, here's the code. Hope it helps someone :D

on('ready', () => {
    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...');
        }
    }
    
    on("change:door:isOpen", function (obj, prev) {
        if (!prev.isSecret) {
            let doorColor = (obj.get('color') || '#000000').toUpperCase();
            
            let colorMap = {
                '#FF0000': "Red-Door",
                '#0000FF': "Blue-Door",
                '#00FF00': "Green-Door",
                '#FFFF00': "Yellow-Door",
                '#FFA500': "Orange-Door",
                '#800080': "Purple-Door"
            };
            
            let baseName = colorMap[doorColor] || "Door";
            let openSound = baseName + "-Open";
            let closeSound = baseName + "-Close";
            
            if (prev.isOpen) {
                playSound(closeSound, 'play');
            } else {
                playSound(openSound, 'play');
            }
        }
    });
});

February 25 (1 month ago)

I do have another script using Keith's Doornoise, but for windows. It's a very minor change to the code, but here you go. This one is made using the base code for Doornoise, so it can only play 1 set of open/close sound files.

on('ready', () => {
    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('Windowsound', '/w gm No Track Found...');
            log("No track found " + trackname);
        }
    }
    on("change:window:isOpen", function (obj, prev) {
        if (!prev.isSecret) {
            if (prev.isOpen) {
                playSound("Window-Close", 'play');
            } else {
                playSound("Window-Open", 'play');
            }
        }
    });
});


February 26 (1 month ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Nice changes. My future plans for the script were contingent upon trying a locked door becoming a triggerable action. If this were to happen, a lock picking DC could be assigned by color.