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] Rollable table macros (using Tokenmod) not working with self whisper API

1573387128

Edited 1573387242
HI all!  I'm setting up a bunch of macros and general stuff to copy/paste in all of my games and I have a huge problem.  I set up a rollable table with more than 200 spell areas (like fire cones, ice spheres, etc...) and use the token created from that rollable table as the token for a general character sheet. The idea (that I stole from somebody, sorry I couldn't find who you were anymore ^^") is to give access to that sheet to all players so when they cast a spell they can just drop it on the map and, with a macro, choose the element, the kind of area and the lenght of the area, and the token will change into the right template to quickly set up areas of effect.  I then set up a bunch of macros, nesting them one in the other, to creat one single macro that could call all of the others for simple use. This is how the final macro looks like /w gm &{template:npcaction} {{rname=Aree d'effetto degli incantesimi}} {{description=**Target Base** [Target](! #SA-Base) **Element** [Acid](! #SAAcidSpellList) | [Poison](! #SAAcidSpellList) | [Cold](! #SAIceSpellList) | [Fire](! #SAFireSpellList) | [Lightning](! #SALightningSpellList) | [Thunder](! #SALightningSpellList) | [Necrotic/Darkness](! #SADarkSpellList) | [Radiant/Light](! #SALightSpellList) | [Arcane](! #SAMagicSpellList) }} It creates a chat menu where the players can choose the element of the spell. The nested macros prompt a question about the kind of area (cone, cube, line, etc...) and then call other macros that ask the length/diameter of the spell. And it works perfectly.  The big problem was that every time a player uses the macro, it appears in my chat box (me being the GM) and it's bothering. I looked online for a solution and I found this script, made (of course :D ) by The Aaron on('ready', () => { const processInlinerolls = (msg) => { if(_.has(msg,'inlinerolls')){ return _.chain(msg.inlinerolls) .reduce(function(m,v,k){ let ti=_.reduce(v.results.rolls,function(m2,v2){ if(_.has(v2,'table')){ m2.push(_.reduce(v2.results,function(m3,v3){ m3.push(v3.tableItem.name); return m3; },[]).join(', ')); } return m2; },[]).join(', '); m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } else { return msg.content; } }; let lastPlayerId; on('chat:message', (msg) => { if('api' !== msg.type ){ return; } let args = processInlinerolls(msg).split(/\s+/); switch(args.shift()){ case '!me': { const who=(getObj('player',('API'===msg.playerid ? lastPlayerId : msg.playerid))||{get:()=>'API'}).get('_displayname'); let content = args.join(' '); if(_.has(msg,'rolltemplate') && _.isString(msg.rolltemplate) && msg.rolltemplate.length){ content = content.replace(/\{\{/,'&{template:'+msg.rolltemplate+'} {{'); } sendChat(msg.who,`/w "${who}" ${content}`); } break; default: if(/\s!me\b/.test(msg.content)){ lastPlayerId = msg.playerid; } break; } }); }); From what I understood it should send the message (in my case the chat menu) as a whisper to whomever uses it without needing to select his token or to make different macros for each different player. I installed the script and changed my chat menu macro, changing "/w gm" with "!me"... and now it doesn't work anymore. The single macros inside of it, if called by themselves, still work perfectly, but if I try to call them from the main macro, the only one working is the first one (#SA-Base). Can anyone help me understand why? I know nothing of scripting, I just copy, paste and cut stuff I find online^^ Thanks
1573387779

Edited 1573388131
GiGs
Pro
Sheet Author
API Scripter
The reason the original macro appears as a whisper to you is because of the "/w gm" at the start. If you remove that, it should work for everyone, and you wont need the script.
1573387917

Edited 1573388102
GiGs said: The reason the original macro appears as a whisper to you is because of the "/w gm" at the start. If you remove that, it should work for everyone, and you wont need the script. Problem is, if I just remove the /w gm, every time a player uses it it will appear in everybody's chat. The script was supposed to help making it so the chat menu appears only in the chat of the player who uses it, without having it appear in everybody's chat. That's why I changed the /w gm with the !me UPDATE I just discovered that the !me command is breaking also other chat menu macros I set up for my players. Is it possible that it just won't allow macro buttons to work?
1573389194
GiGs
Pro
Sheet Author
API Scripter
Regarding your UPDATE, it's more likely the structure of your macro is breaking the !me script. It's a weird structure, I've never seen used before. Those ! are very weird. The proper syntax for this [Target](! #SA-Base) is [Target](!
#SA-Base) If you are saving these in your universal macro section, whenever you open them, the html characters after ! will be being replaced, and will break the macro, so it';s best once saving them, either never open them again, or b) save them in a Character Sheet's Abilities section. Often people use one for macros, and set as editable by everyone (but not visible to everyone), so that players can call them. I don't fully follow Aaron's macro there, but try the above change to your macros and test it again.  If it still isnt working properly, you have three options to change the whisper so it changes to the player who is using it, instead of whispering to the GM. You could put a dropdown query there, replacing GM with ?{who?|player 1 name| player 2 name| etc} to let players choose themselves, create it as an ability and put a version on each players sheet with the /w GM replaced with /w (their name), so they whisper to themselves automatically, use a simpler custom script which has the macro code hardcoded, and detects the person clicking it and then prints out that macro 
Sir: you're a gentleman and a scholar!  That totally fixed it, you were right, the ! were the problems. I just copy/pasted the chat menu macro from somewhere else and changed it with my macros. Without the !me it works perfectly. Changing them to the html version fixed it. Thank you very much!
1573396856
GiGs
Pro
Sheet Author
API Scripter
That's great :)
1573402032

Edited 1573451444
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I usually preface macros that only need to be seen by the person running them with: /w "@{selected|character_name}" It will only work as a token macro, but that sounds like your use case anyway. Edited macro to include quote marks, in order to catch character names with spaces in them
1573403774
GiGs
Pro
Sheet Author
API Scripter
Oh yes, i should have remembered that, haha.