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

[Script] New to API GM Note

Hello all, I am trying to get the GM Note API script to work with my campaign. The script is from this post <a href="https://app.roll20.net/forum/post/5047876/script-request-gm-notes-on-chat" rel="nofollow">https://app.roll20.net/forum/post/5047876/script-request-gm-notes-on-chat</a>, and it's function should allow me to click on a hidden token and then type !gmnote to receive a whispered chat message sent only to the GM. To my understanding I have added the API script to the game and set a macro that types !gmnote. When I click on this macro I should get a whispered message containing the GM Notes from the token correct? However when I use the macro all I recieve is a message that says the token's name but not the text from the gm notes section. I am really new to scripts and API so I have a feeling I am just not getting it. Any help would be appreciated. Also my interest in this came about from watching a GM run Curse of Strahd on youtube. In the video here <a href="https://youtu.be/YQxiV2teS9A?t=28m48s" rel="nofollow">https://youtu.be/YQxiV2teS9A?t=28m48s</a> the GM uses a Macro called Utility Menu. I am sure this is an API as well, and if anyone has a link to it this seems really useful. Of course it also seems like something that is really advanced for me, but I would still like to try and mess around with it. Thanks for any help in advance!
1532220526
The Aaron
Pro
API Scripter
I believe it’s !gmnote and not !gmnotes.&nbsp;
I edited the macro to !gmnote without the S and still have the same issue.
1532246715
MSG
Pro
Sheet Author
The Aaron, Would that script only work with a 5E-Shaped sheet?&nbsp; I'm seeing a &amp;{template:5e-shaped} in Line 10.
@MSG Thank you! That was my problem. Because I am using the OLG and not the 5e shaped character sheet I had to change the template to&nbsp; &nbsp;&amp;{template:traits}
1532272217
The Aaron
Pro
API Scripter
Ah!&nbsp; Good catch MSG! There are several versions of that script running about.&nbsp; Here's my current version.&nbsp; (I think this is using an OGL template): on('ready',()=&gt;{ const blockElements = [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div', 'fieldset', 'form', 'hr', 'noscript', 'table','br' ]; const rStart=new RegExp(`&lt;\\s*(?:${blockElements.join('|')})\\b[^&gt;]*&gt;`,'ig'); const rEnd=new RegExp(`&lt;\\s*\\/\\s*(?:${blockElements.join('|')})\\b[^&gt;]*&gt;`,'ig'); const getLines = (str) =&gt; (rStart.test(str) ? str .replace(/[\n\r]+/g,' ') .replace(rStart,"\r$&amp;") .replace(rEnd,"$&amp;\r") .split(/[\n\r]+/) : str .split(/(?:[\n\r]+|&lt;br\/?&gt;)/) ) .map((s)=&gt;s.trim()) .filter((s)=&gt;s.length) ; const cmdRegex = /^!(w?)gmnote(?:-(.*))?$/i; on('chat:message',(msg) =&gt; { if('api' === msg.type &amp;&amp; cmdRegex.test(msg.content) &amp;&amp; playerIsGM(msg.playerid) ){ let match=msg.content.match(cmdRegex), output = match[1].length ? '/w gm ' : '', regex; if(match[2]){ regex = new RegExp(`^${match[2]}`,'i'); } _.chain(msg.selected) .map( s =&gt; getObj('graphic',s._id)) .reject(_.isUndefined) .reject((o)=&gt;o.get('gmnotes').length===0) .each( o =&gt; { if(regex){ let lines = _.filter( getLines(unescape(o.get('gmnotes'))), (l) =&gt; regex.test(l.replace(/&lt;[^&gt;]*&gt;/g,'')) ).join('&lt;br&gt;'); sendChat(o.get('name'), `${output}${lines}`); } else { sendChat(o.get('name'), `${output} &amp;{template:desc}}{{desc=${unescape(o.get('gmnotes')).replace(/(?:[\n\r]+|&lt;br\/?&gt;)/g,'&lt;br&gt;')} }}`); } }); } }); });
@The Aaron Thank you! That works perfectly.
HI Aaron: I use the GMNotes template in combination with your Bump script. This allows me to have hidden tokens on the map and still interact with the token. I can then send GMNotes to the Chat window. I was using an older script and it seemed to work fine. Now I have used the one below and I can't seem to get the GMNOTEs to send to the chat if the token is "bumped" hidden. If i selecct the token and ensure it is on the Token Layer the GMNOTES script worked fine.&nbsp; Thoughts ? The Aaron said: Ah!&nbsp; Good catch MSG! There are several versions of that script running about.&nbsp; Here's my current version.&nbsp; (I think this is using an OGL template): on('ready',()=&gt;{ const blockElements = [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div', 'fieldset', 'form', 'hr', 'noscript', 'table','br' ]; const rStart=new RegExp(`&lt;\\s*(?:${blockElements.join('|')})\\b[^&gt;]*&gt;`,'ig'); const rEnd=new RegExp(`&lt;\\s*\\/\\s*(?:${blockElements.join('|')})\\b[^&gt;]*&gt;`,'ig'); const getLines = (str) =&gt; (rStart.test(str) ? str .replace(/[\n\r]+/g,' ') .replace(rStart,"\r$&amp;") .replace(rEnd,"$&amp;\r") .split(/[\n\r]+/) : str .split(/(?:[\n\r]+|&lt;br\/?&gt;)/) ) .map((s)=&gt;s.trim()) .filter((s)=&gt;s.length) ; const cmdRegex = /^!(w?)gmnote(?:-(.*))?$/i; on('chat:message',(msg) =&gt; { if('api' === msg.type &amp;&amp; cmdRegex.test(msg.content) &amp;&amp; playerIsGM(msg.playerid) ){ let match=msg.content.match(cmdRegex), output = match[1].length ? '/w gm ' : '', regex; if(match[2]){ regex = new RegExp(`^${match[2]}`,'i'); } _.chain(msg.selected) .map( s =&gt; getObj('graphic',s._id)) .reject(_.isUndefined) .reject((o)=&gt;o.get('gmnotes').length===0) .each( o =&gt; { if(regex){ let lines = _.filter( getLines(unescape(o.get('gmnotes'))), (l) =&gt; regex.test(l.replace(/&lt;[^&gt;]*&gt;/g,'')) ).join('&lt;br&gt;'); sendChat(o.get('name'), `${output}${lines}`); } else { sendChat(o.get('name'), `${output} &amp;{template:desc}}{{desc=${unescape(o.get('gmnotes')).replace(/(?:[\n\r]+|&lt;br\/?&gt;)/g,'&lt;br&gt;')} }}`); } }); } }); });
1536182015
The Aaron
Pro
API Scripter
Hmm.. Probably Bump is not keeping the gmnotes field in sync.&nbsp; If you go to Bump and change this: mirroredProps = [ 'name', 'left', 'top', 'width', 'height', 'rotation', 'flipv', 'fliph', 'bar1_value', 'bar1_max', 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', 'tint_color', 'lastmove', 'represents','bar1_link','bar2_link','bar3_link' ], to this: mirroredProps = [ 'name', 'left', 'top', 'width', 'height', 'rotation', 'flipv', 'fliph', 'bar1_value', 'bar1_max', 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', 'tint_color', 'lastmove', 'represents','bar1_link','bar2_link','bar3_link' , 'gmnotes' ], It should work on newly bumped or edited tokens.&nbsp; Let me know if that works and I'll make the patch to the published version as well.
That fixed it. Thanks you're the man!!&nbsp; The Aaron said: Hmm.. Probably Bump is not keeping the gmnotes field in sync.&nbsp; If you go to Bump and change this: mirroredProps = [ 'name', 'left', 'top', 'width', 'height', 'rotation', 'flipv', 'fliph', 'bar1_value', 'bar1_max', 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', 'tint_color', 'lastmove', 'represents','bar1_link','bar2_link','bar3_link' ], to this: mirroredProps = [ 'name', 'left', 'top', 'width', 'height', 'rotation', 'flipv', 'fliph', 'bar1_value', 'bar1_max', 'bar2_value', 'bar2_max', 'bar3_value', 'bar3_max', 'tint_color', 'lastmove', 'represents','bar1_link','bar2_link','bar3_link' , 'gmnotes' ], It should work on newly bumped or edited tokens.&nbsp; Let me know if that works and I'll make the patch to the published version as well.
1536265958
The Aaron
Pro
API Scripter
Great!&nbsp; I'll get that in the official Bump script.