Here's a very simple script that should let you do selective chat output. Basic operation: !do-if <SOME CHECK> --<SOME OUTPUT> <SOME CHECK> should be replaced with something that will result in a number. If the number isn't 0, it will send whatever is after the -- to chat as whoever called the command. Example: !do-if @{selected|has_foo} --/w gm Selected character does have foo. or, perhaps: !do-if [[1-@{selected|has_foo}]] --/w gm Selected character does not have foo. In the case of things that might be evaluated by Roll20 chat, like inline rolls or template parts, you can escape them with \: !do-if @{selected|has_foo} --/w gm & \ {template:default}{ \ {name=has foo} \ }{\{roll=[\[1d20]\]}\} Code: on('ready',()=>{
const processInlinerolls = (msg) => {
if(msg.hasOwnProperty('inlinerolls')){
return msg.inlinerolls
.reduce((m,v,k) => {
let ti=v.results.rolls.reduce((m2,v2) => {
if(v2.hasOwnProperty('table')){
m2.push(v2.results.reduce((m3,v3) => [...m3,v3.tableItem.name],[]).join(", "));
}
return m2;
},[]).join(', ');
return [...m,{k:`$[[${k}]]`, v:(ti.length && ti) || v.results.total || 0}];
},[])
.reduce((m,o) => m.replace(o.k,o.v), msg.content);
} else {
return msg.content;
}
};
const splitOn = (str,regex) => {
let first = str.search(regex);
if(-1 === first){
return [str];
}
return [str.slice(0,first),str.slice(first).replace(regex,'')];
};
const sanitize = (str) => str.replace(/\\(.)/g,(m)=>m[1]);
on('chat:message',msg=>{
if('api'===msg.type && /^!do-if(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){
let parts = splitOn(processInlinerolls(msg),/\s+--/);
let args = parts[0].split(/\s+/);
if(parseInt(args[1])){
sendChat(msg.who,sanitize(parts[1]));
}
}
});
});