That's ironic! Sure thing, give this a whirl: // Github: <a href="https://github.com/shdwjk/Roll20API/blob/master/Measure/Measure.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Measure/Measure.js</a>
// By: The Aaron, Arcane Scriptomancer
// Contact: <a href="https://app.roll20.net/users/104025/the-aaron" rel="nofollow">https://app.roll20.net/users/104025/the-aaron</a>
const Measure = (()=> {
const version = '0.3.2';
const lastUpdate = 1551746777;
const modByRange = [
{r:1, m:0},
{r:2, m:0},
{r:3, m:-1},
{r:5, m:-2},
{r:7, m:-3},
{r:10, m:-4},
{r:15, m:-5},
{r:20, m:-6},
{r:30, m:-7},
{r:50, m:-8},
{r:70, m:-9},
{r:100, m:-10},
{r:150, m:-11},
{r:200, m:-12},
{r:300, m:-13},
{r:500, m:-14},
{r:700, m:-15},
{r:1000, m:-16},
{r:1500, m:-17},
{r:2000, m:-18},
{r:3000, m:-19},
{r:5000, m:-20},
{r:7000, m:-21},
{r:10000, m:-22},
{r:15000, m:-23},
{r:20000, m:-24}
];
const getModForDistance = (d) => {
const entry = modByRange.find((o)=>o.r>=d );
return (undefined != entry ? entry.m : -24);
};
const checkInstall = function() {
log('-=> MeasureGURPS v'+version+' <=- ['+(new Date(lastUpdate*1000))+']');
};
const handleInput = (msg) => {
var args,
pageid,
page,
measurements,
whisper = false,
who;
if (msg.type !== "api") {
return;
}
args = msg.content.split(/\s+/);
switch(args.shift()) {
case '!wmeasure':
whisper = true;
who=(getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
// break; // Intentional fall through
case '!measure':
measurements = _.chain(_.union(args,_.pluck(msg.selected,'_id')))
.uniq()
.map(function(t){
return getObj('graphic',t);
})
.reject(_.isUndefined)
.map(function(t){
pageid=t.get('pageid');
return {
name: t.get('name') || "Token @ "+Math.round(t.get('left')/70)+','+Math.round(t.get('top')/70),
x: t.get('left'),
y: t.get('top')
};
})
.reduce(function(m,t,k,l){
_.each(_.rest(l,k+1),function(t2){
m.push({
name1: t.name,
name2: t2.name,
distance: (Math.sqrt( Math.pow( (t.x-t2.x),2)+Math.pow( (t.y-t2.y),2))/70)
});
});
return m;
},[])
.value()
;
page=getObj('page',pageid);
if(page) {
_.chain(measurements)
.reduce(function(m,e){
var d=Math.round(page.get('scale_number')*e.distance,2);
m.push(`<li>${e.name1} to ${e.name2}: <b>${d} ${page.get('scale_units')}</b> (<b>${getModForDistance(d)}</b>)</li>`);
return m;
},[])
.join('')
.tap(function(o){
sendChat('',(whisper ? '/w "'+who+'"' : '/direct')+' <div><ul>'+o+'</ul></div>');
});
}
break;
}
};
const registerEventHandlers = () => {
on('chat:message', handleInput);
};
on('ready',function() {
checkInstall();
registerEventHandlers();
});
return { };
})();