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

Map Ambience - A Script for Dynamic Soundscapes on Pages

1722612108

Edited 1722612941
Coryphon
Pro
Sheet Author
Compendium Curator
Hi All, I've been working on a script that dynamically changes Jukebox Track volumes, and plays one-off sound effects based on the proximity of hero tokens to 'ambient sources'. The script and instructions are available  here . A demo video is available  here . So,  Map Ambience allows you to create ambient audio sources on a page which your players, via their hero tokens,  experience dynamically based on their proximity to the sources.  Hero tokens are defined as tokens which are linked to character sheets where the 'controlledby' field has a  value. The ambient sources and hero tokens are loaded on a page change event automatically. While designing the page you can create a macro that executes: !mapam buildAmbientState which will process and run the sources. Ambient sources are defined by their name starting with ‘Ambient’ (case-sensitive!) and have a number of parameters that  control their behaviour. There are four different types of ambient sources: 1. Whole map ambiences which are always on such as environmental sounds, wind, rain, dripping water in a cave  and so on. we use the bar1 value to hold the volume, the tooltip to hold the track name and set the aura1 radius to  ALL, signifying an ‘always on source’. 2. Basic proximity ambiences that change their volume based on hero token proximity, e.g. rivers,  monsters, birds in trees etc. These sources can be linked to polygonal paths to provide dynamic sounds for  rivers for example. For a simple source it is as above except bar1 value and bar1 max hold the minimum and maximum  volume respectively. For a source linked to a polygonal path bar3 value holds the id of the path object (see 3. below).  We can use a simple macro /w gm @{selected|token_id} to find our path id. 3. 'Trigger' ambiences that play a sound once (e.g. not looped) based on hero token movement such as footsteps  in water or a repeatedly fireable trap. Again we use bar1 for min/max volume, tooltip and aura1 radius but also add  a bar2 value of ‘noloop’ meaning the sound is only played once. But the source will re-trigger each time we  are in proximity, for something like a re-loading trap or similar!. 4. 'Trigger' ambiences as above but they only fire once are then 'forgotten' such as a pit trap or bomb. These can also  execute a macro to create a visual effect such as showing or changing a token e.g. a pit trap or breaking something  for example. These are set up as above but we add 'forget' to the bar2 max . Macro example in GM Notes which moves a token with dynamic lighting (for example) to the map layer: Hope you may find this interesting, any questions, fire away! ;-) Regards, ~ Coryphon ~
1722614493
Gold
Forum Champion
This Mod script sounds really good (pun intended)
Aw man! Another awesome script of yours I need to check out. Would it be possible for dynamic lighting lines and doors/windows to block sounds until a door or window is opened? For example, a token does not hear the music playing in the tavern until the door is opened. Or, can that be accomplished without dynamic lighting?
1722810643

Edited 1722810681
Coryphon
Pro
Sheet Author
Compendium Curator
Doug E. said: Aw man! Another awesome script of yours I need to check out. Would it be possible for dynamic lighting lines and doors/windows to block sounds until a door or window is opened? For example, a token does not hear the music playing in the tavern until the door is opened. Or, can that be accomplished without dynamic lighting? Hi Doug, Thank you! I did ponder this, but the computation required would be too great. I’ll have a think but it’s a tough one ;-) It is really designed for more open areas… It would be possible to have a trigger distance separated from the ambient sound distance, e.g a source triggers when 5’ away but the sound can then be heard in a 20’ radius so your source is behind the tavern door and when triggered the sound can be heard at a greater distance as it were… That’s probably the closest I could get….but I will think on it… Regards, ~ Coryphon ~
1722883113
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Neat idea! Suggestion: You might want to expand the criteria for a hero token: Hero tokens are defined as tokens which are linked to character sheets where the 'controlledby' field has a  value. Many times, GMs will specifically add themselves as a controller to a token to avoid certain quirks of dynamic lighting. I would suggest that it filter out tokens where the character has a single controller that "isGM".
1722883534
Coryphon
Pro
Sheet Author
Compendium Curator
keithcurtis said: Neat idea! Suggestion: You might want to expand the criteria for a hero token: Hero tokens are defined as tokens which are linked to character sheets where the 'controlledby' field has a  value. Many times, GMs will specifically add themselves as a controller to a token to avoid certain quirks of dynamic lighting. I would suggest that it filter out tokens where the character has a single controller that "isGM". Excellent idea Keith, thank you! 🙏🏽  Was going to allow hero tokens to be registered by selection or ids, but that definitely makes sense… ~ C ~
1722930242
Coryphon
Pro
Sheet Author
Compendium Curator
Hi All, The script has been updated with Keith's suggestion. Interestingly this threw up a bug whereby a callback for add:graphic  does not work as the 'name' field is not populated on the incoming graphic even through it is there. E.g. dropping a monster in from the Monster Manual with name 'Rust Monster', that name is not on the incoming graphic object...odd... ~ C ~
1722949124
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I think that might be a race condition. I'll see if I can summon a Smart Person™ to come and comment.
I think Kurt J ran into similar with add:graphic  in ScriptCards as well. It seemed like the only property that was reliably there was the Graphic object ID.
1722955918
Coryphon
Pro
Sheet Author
Compendium Curator
Thank you Keith & Joshua, I suspected as much. To be honest my original idea of making the script dynamic enough to auto-process new hero tokens and ambient sources was not really going to work with the amount of finessing of attributes. Good to know for future scripts though. Thank you! ~ C ~
1722958943
timmaugh
Pro
API Scripter
Well, you could fire an asynchronous setTimeout() after you detect the add:graphic  event. Give it enough time to populate the rest of the properties, then return to the token in your callback and evaluate whether you need to take further action.