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

[Help] Using roll results of inline rolls

1445604098
Scaby79
Sheet Author
API Scripter
Hello everybody, I have problems with triggering sound effects by roll results or chat messages if the trigger itself is inside an inline roll or an inline expression of a rollable table. Here is a simple script that I tried to get to work on("ready", function() { on("chat:message", function (msg) { if (msg.type === "api" && msg.content === "!crit") { PlaySound('crit', 4000); }; if (msg.type === "emote" && msg.content.match(/critical/i)) { PlaySound('crit', 4000); }; if (msg.type === "rollresult" && msg.content.match(/v\":10/)) { PlaySound('crit', 4000); }; if (msg.type === "general" && msg.content.match(/"v":10}/)) { PlaySound('crit', 4000); }; if (msg.type === "rollresult" && msg.content.match(/v\":1/)) { PlaySound('fumble', 4000); }; if (msg.type === "general" && msg.content.match(/"v":1}/)) { PlaySound('fumble', 4000); }; if (msg.type === "api" && msg.content === "!dead") { PlaySound('dead', 3000); }; }); }); function PlaySound(trackname, time) { var track = findObjs({type: 'jukeboxtrack', title: trackname})[0]; track.set('playing',false); track.set('softstop',false); track.set('volume', 100); log(track); if(track) { track.set('playing',true); log('playing'); setTimeout(function() {track.set('playing',false);log('stopping sound');}, time); log(track); } else { log("No track found"); } } It is working fine for roll results coming out of commands like  /roll 1d10 but not for inline rolls like [[1d10]] Further /em makes a critical hit  is working fine too but /em [[1t[crittable]]] doesn't trigger the sound if the table roll result contains the word critical. I'm pretty sure the solution lies somewhere  here , but as I can hardly manage to adjust existing scripts to my individual needs and sadly have basically NO skills in scripting myself I wasn't able to put those two together :( If the answer is more complicated than a few lines, never mind: It is just not THAT important. But if there maybe is a simple solution I would be very happy about some help with this problem. Thank you very much in advance! 
1445606019

Edited 1445621810
The Aaron
Pro
API Scripter
Actually, I believe the issue is with your detection: if (msg.type === "general" && msg.content.match(/"v":1}/)) { PlaySound('fumble', 4000); } With inline rolls, the data for the roll is stored as an object (not a JSON string as in the case of a roll result).  That object is in the property inlinerolls : inlinerolls (content contains one or more inline rolls only) An array of objects containing information about all inline rolls in the message. The closest way to your current method of handling this is: if (msg.type === "general" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } Side note:  /"v":1/ will match "v":10 , and will not match "v": 1 /\bv\b"\s*:\s*\b1\b/ will probably be more effective.  \b is a word boundary, so matches the beginning or end of a word.
1445614408
Scaby79
Sheet Author
API Scripter
Thank you very much for your quick reply! with "stringify" instead of "stringfiy" (just in case someone with a similar problem is trying your fix) it worked!   Thx
1445615437
DK Heinrich
Marketplace Creator
Sheet Author
Can you share the completed script, along with description of what to do to set it up? I think I have backed into it but want to be sure I am not barking up the wrong tree.
1445621137
Scaby79
Sheet Author
API Scripter
Hey DK Heinrich, I'll give it a try: The following script is for playing some soundeffects on special events like roll results. You have to set up everything in the code of the script itself, so I just use it for some fix soundeffects like when someone rolls a crit or a fumble. For more flexible adjustments (even ingame) I recommend the  Script Triggered SFX from Brian . This is the code of the script: on("ready", function() { on("chat:message", function (msg) { if (msg.type === "api" && msg.content === "!crit") { PlaySound('crit', 4000); }; if (msg.type === "general" && msg.content.match(/TRAP/)) { PlaySound('trap', 4000); }; if (msg.type === "emote" && msg.content.match(/critical/i)) { PlaySound('crit', 4000); PlaySound('dead',2000); }; if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/critical/)) { PlaySound('crit', 4000); PlaySound('dead',2000); } if (msg.type === "emote" && msg.content.match(/fumbles/i)) { PlaySound('fumble', 4000); }; if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/fumbles/)) { PlaySound('fumble', 4000); } if (msg.type === "rollresult" && msg.content.match(/v\":10/)) { PlaySound('crit', 4000); }; if (msg.type === "general" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*10\b/)) { PlaySound('crit', 4000); } if (msg.type === "whisper" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*10\b/)) { PlaySound('crit', 4000); } if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*10\b/)) { PlaySound('crit', 4000); } if (msg.type === "rollresult" && msg.content.match(/v\":1}/)) { PlaySound('fumble', 4000); }; if (msg.type === "general" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } if (msg.type === "whisper" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } if (msg.type === "api" && msg.content === "!dead") { PlaySound('dead', 3000); }; }); }); function PlaySound(trackname, time) { var track = findObjs({type: 'jukeboxtrack', title: trackname})[0]; track.set('playing',false); track.set('softstop',false); track.set('volume', 100); log(track); if(track) { track.set('playing',true); log('playing'); setTimeout(function() {track.set('playing',false);log('stopping sound');}, time); log(track); } else { log("No track found"); } } I'll try to explain the setup step by step further below...
1445621858
The Aaron
Pro
API Scripter
Scaby79 said: Thank you very much for your quick reply! with "stringify" instead of "stringfiy" (just in case someone with a similar problem is trying your fix) it worked!   Thx Ah, fixed above!  =D  Glad to help!
1445624022

Edited 1445624164
Scaby79
Sheet Author
API Scripter
if (msg.type === "api" && msg.content === " !crit ") { PlaySound(' crit ', 4000 ); } Here you can set up a command like " !crit " that plays a track in the jukebox withe the name " crit " for 4000 milliseconds (4 seconds) if (msg.type === "general" && msg.content.match(/ TRAP /)) { PlaySound(' trap ', 4000); } As I use the  Trap detection script from Stephen L which gives the message "IT'S A TRAP" in the chat, when a character triggers a trap, this lines of code make sure that the track with the name "trap" (wich is the original sound of Admiral Ackbar ;)) is played whenever a trap is triggered by the script from Stephen. if (msg.type === " emote " && msg.content.match(/ critical /i)) { PlaySound(' crit ', 4000); PlaySound(' dead ',2000); } Here you can setup that the tracks named " crit " AND " dead " are played, whenever the word " critical " enters the chat as type of emote . (see next explanation below)  if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/critical/)) { PlaySound('crit', 4000); PlaySound('dead',2000); } As I use rollable tables to verify a critical hit (and the table is set up that for every crit the text in the item of the rollable table contains the word " critical ") this lines tell the api to play the tracks named " crit " AND " dead " whenever the word " critical " appears in an emote chat message. I give out the items of the rollable table as emotes, so you have to change " emote " to "general" or "whisper" or "desc" regarding the type of text in which the trigger enters the chat. if (msg.type === "rollresult" && msg.content.match(/v\": 10 /)) { PlaySound(' crit ', 4000); }; This is for triggering the track " crit " whenever a roll result rolled by the command "/roll " shows a " 10 ". if (msg.type === "general" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s* 10 \b/)) { PlaySound(' crit ', 4000); } This is for triggering the track " crit " whenever a roll result rolled by an inline command like "[[1d10]] " shows a " 10 ". if (msg.type === "whisper" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*10\b/)) { PlaySound('crit', 4000); } Like above just for when the inline roll is whispered. if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*10\b/)) { PlaySound('crit', 4000); } Like above just for when the inline roll is given to the chat like an emote. if (msg.type === "rollresult" && msg.content.match(/v\": 1} /)) { PlaySound(' fumble ', 4000); }; This is for triggering the track " fumble " whenever a roll result rolled by the command "/roll " shows a " 1 ". Note:  I added the "}" after the "1" to not trigger that track too when there is a 10 as roll result. I assume there is a better way using word boundaries like Aaron described above. I just did not understand them completely yet. if (msg.type === "general" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } Same as above for inline rolls. if (msg.type === "whisper" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } Same as above for whispered inline rolls. if (msg.type === "emote" && msg.inlinerolls && JSON.stringify(msg.inlinerolls).match(/\bv"\s*:\s*1\b/)) { PlaySound('fumble', 4000); } Same as above for inline rolls in emotes. track.set('volume', 100); Here you can set up a percentage value for the volume the tracks are played. I hope that helps and I apologize in advance for possibly bad sentences (I'm not a native speaker) and if this is placed wrong here. I don't have a gisthub account (yet) and I really don't think that someone could really use some of my code, especially because it is somewhat specific to my own needs and so NOT fexible. But I just wanted to answer DK H. just in case he has in fact interest in this code.
1445627897
DK Heinrich
Marketplace Creator
Sheet Author
That is great, and I will be using it. I really just want sound for when particular things happen. I also use very specific terms on my output (success, failure, critical, etc) - so this should be a solid base for me.  Thank you for the breakdown and I will let you know when I break it and need help :)