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

AnnouncRoll aka AnnounceNats a Mod snippit when someone rolls a Natural 20 or Nat 1

1740011192
Gold
Forum Champion
Someone Ash Styles requested this API Mod script snippit in the Roll20 official discord and it seems better to give the code-snippint for copy-pasting from Roll20 Community Forums so I will re-share this here. This is a version where I made very slight modifications of a snippit The Aaron wrote and shared here long-ago.&nbsp; This is a way to detect when someone rolls a Natural 20 or a Natural 1, it shares a bold color-text message into the chat room. Maybe you can modify the code to do other celebrations.&nbsp; AnnounceNats.js AKA AnnouncRoll.js&nbsp; // Github:&nbsp; &nbsp;<a href="https://github.com/shdwjk/Roll20API/blob/master/AnnouncRoll/AnnouncRoll.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/AnnouncRoll/AnnouncRoll.js</a> // By:&nbsp; &nbsp; &nbsp; &nbsp;The Aaron, Arcane Scriptomancer // Contact:&nbsp; <a href="https://app.roll20.net/users/104025/the-aaron" rel="nofollow">https://app.roll20.net/users/104025/the-aaron</a> var AnnounceRoll = AnnounceRoll || (function() { &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp; var version = '0.2.2', &nbsp; &nbsp; &nbsp; &nbsp; lastUpdate = 1427604233, &nbsp; &nbsp; checkInstall = function() {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log('-=&gt; AnnounceRoll v'+version+' &lt;=-&nbsp; ['+(new Date(lastUpdate*1000))+']'); &nbsp; &nbsp; }, &nbsp; &nbsp; handleInput = function(msg) { &nbsp; &nbsp; &nbsp; &nbsp; var rolldata,out=[]; &nbsp; &nbsp; &nbsp; &nbsp; if (msg.type !== "rollresult") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; rolldata = JSON.parse(msg.content); &nbsp; &nbsp; &nbsp; &nbsp; _.each(rolldata.rolls,function(r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if('R' === r.type &amp;&amp; 20 === r.sides) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(r.results, function(roll){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(roll.v) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out.push('&lt;div style="color: #009900;font-weight: bold"&gt;Nat 1.. What wizardry is this? (Narrative)&lt;/div&gt;'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 20: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out.push('&lt;div style="color: #009900;font-weight: bold"&gt;NATURAL 20! (Narrative opportunity)&lt;/div&gt;'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; if(out.length) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('',out.join('')); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }, &nbsp; &nbsp; registerEventHandlers = function() { &nbsp; &nbsp; &nbsp; &nbsp; on('chat:message', handleInput); &nbsp; &nbsp; }; &nbsp; &nbsp; return { &nbsp; &nbsp; &nbsp; &nbsp; CheckInstall: checkInstall, &nbsp; &nbsp; &nbsp; &nbsp; RegisterEventHandlers: registerEventHandlers &nbsp; &nbsp; }; }()); on('ready',function() { &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp; AnnounceRoll.CheckInstall(); &nbsp; &nbsp; AnnounceRoll.RegisterEventHandlers(); });
1740011266
Gold
Forum Champion
Just figured out how to say, you can also go to The Aaron 's GitHub to get it straight from the original coder and potentially follow any updates: <a href="https://github.com/shdwjk/Roll20API/tree/master/AnnounceRoll" rel="nofollow">https://github.com/shdwjk/Roll20API/tree/master/AnnounceRoll</a>
Thanks!