
In preparation for running a one-shot for my group, I came across this very useful API script by Keith Curtis (<a href="https://app.roll20.net/forum/post/11244006/scriptlet-doornoise/?pageforid=11244006#post-11244006" rel="nofollow">https://app.roll20.net/forum/post/11244006/scriptlet-doornoise/?pageforid=11244006#post-11244006</a>). 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');
}
}
});
});