Lookups is actually very easy: In chat !lookup poison [[1d20+@{selected|con}]] Whispered to gm and player !glookup poison [[1d20+@{selected|con}]] Whispered only to the gm, notice to the player about a blind roll: !blookup poison [[1d20+@{selected|con}]] Script: on('ready',()=>{
const rollableTable = (function( ){
let tables = {},
IDtoTableName = {};
const nullTableRoller = function(){
return '';
},
buildTableRoller = function(tablename){
let tobj = _.first(findObjs({
type: 'rollabletable',
name: tablename
}));
tables[tablename]=nullTableRoller;
if(tobj){
IDtoTableName[tobj.id]=tablename;
tables[tablename] = (function(){
let values = _.reduce(
findObjs({
type: 'tableitem',
rollabletableid: tobj.id
}),
function(m,e){
IDtoTableName[e.id]=tablename;
_.times(e.get('weight'),function(){m.push(e.get('name'));});
return m;
},
[]
);
return function(num){
return values[Math.min(values.length,Math.max(1,num))-1];
};
}());
}
},
handleItemChange = function(obj){
if(IDtoTableName[obj.get('rollabletableid')]){
buildTableRoller(IDtoTableName[obj.get('rollabletableid')]);
}
},
handleTableChange = function(obj){
if(IDtoTableName[obj.id]){
buildTableRoller(IDtoTableName[obj.id]);
}
};
on('change:rollabletable',handleTableChange);
on('change:tableitem',handleItemChange);
on('add:tableitem',handleItemChange);
on('destroy:tableitem',handleItemChange);
return function( tablename ){
if(!tables[tablename]){
buildTableRoller(tablename);
}
return (function(tab,nam){
return function(n){
return tab[nam](n);
};
}(tables,tablename));
};
}());
const outer = (contents) => `<div style="margin-bottom: .3em;border:1px solid #999;background-color: #ffe;padding: .2em; border-radius:.2em;">${contents}</div>`;
const result = (contents) => `<div style="display:inline-block;font-size: 1.5em; border: 1px solid #999; background-color: #fef; font-weight: bold; border-radius: .2em; padding: .4em .2em;margin-right: .2em;">${contents}</div>`;
on('chat:message',(orig_msg)=>{
if(/![gb]?lookup\b/i.test(orig_msg.content)){
let msg=_.clone(orig_msg);
if(_.has(msg,'inlinerolls')){
msg.content = _.chain(msg.inlinerolls)
.reduce(function(m,v,k){
var 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();
}
let args=msg.content.split(/\s+/);
let table=args[1]||'';
let num=args[2]||1;
let text=rollableTable(table)(num);
let blind=/^!b/i.test(msg.content);
let whisper=/^!g/i.test(msg.content);
let who=(getObj('player',orig_msg.playerid)||{get:()=>'API'}).get('_displayname');
let output=outer(`${result(num)} <b>${table}</b>:${text}`);
if(blind || whisper){
sendChat(who,`/w gm ${output}`);
if(!playerIsGM(msg.playerid)){
if(whisper){
sendChat('',`/w "${who}" ${output}`);
} else {
sendChat('',`/w "${who}" ${outer('Blind roll sent to GM')}`);
}
}
} else {
sendChat('',output);
}
}
});
});