Skip to content

Instantly share code, notes, and snippets.

@shdwjk
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save shdwjk/437a80205ab5b7947466 to your computer and use it in GitHub Desktop.

Select an option

Save shdwjk/437a80205ab5b7947466 to your computer and use it in GitHub Desktop.
Roll20 API: EoERangeBands -- A reorganization of Dylan C. and Trent F.'s Edge of the Empire Range Bands script.
// GIST: https://gist.github.com/shdwjk/437a80205ab5b7947466
var EoERangeBands = EoERangeBands || (function() {
'use strict';
var version = 0.2,
shortRange = 10,
mediumRange = 50,
shortBand = {
aura1_radius: shortRange,
aura1_square: false,
aura1_color: '#FF0000',
playersedit_aura1: false,
showplayers_aura1: true
},
mediumBand = {
aura2_radius: mediumRange,
aura2_square: false,
aura2_color: '#FFFF00',
playersedit_aura2: false,
showplayers_aura2: true
},
clearBands = {
aura1_radius: '',
aura2_radius: ''
},
showHelp = function(who) {
sendChat('',
'/w ' + who + ' '
+'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'
+'<div style="font-weight: bold; border-bottom: 1px solid black;font-size: 130%;">'
+'EoERangeBands v'+version
+'</div>'
+'<div style="padding-left:10px;margin-bottom:3px;">'
+'<p>This script adds range bands as auras around the selected or specified tokens.</p>'
+'</div>'
+'<b>Commands</b>'
+'<div style="padding-left:10px;">'
+'<b><span style="font-family: serif;">!shortbands [&lt;Token ID&gt; ... ]</span></b><br>'
+'<b><span style="font-family: serif;">!mediumbands [&lt;Token ID&gt; ... ]</span></b><br>'
+'<b><span style="font-family: serif;">!rangebands [&lt;Token ID&gt; ... ]</span></b>'
+'<div style="padding-left: 10px;padding-right:20px">'
+'<p>These commands add short, medium, or both range bads to each selected and/or specified token.</p>'
+'<ul>'
+'<li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;">'
+'<b><span style="font-family: serif;">&lt;Token ID&gt;</span></b> &mdash; A Token ID, usually supplied with something like &#64;&#123;target&#124;Target 1&#124;token_id&#125;.'
+'</li> '
+'</ul>'
+'</div>'
+'<b><span style="font-family: serif;">!clearbands [&lt;Token ID&gt; ... ]</span></b>'
+'<div style="padding-left: 10px;padding-right:20px">'
+'<p>Clears both bands from all selected and/or specified tokens.</p>'
+'<ul>'
+'<li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;">'
+'<b><span style="font-family: serif;">&lt;Token ID&gt;</span></b> &mdash; A Token ID, usually supplied with something like &#64;&#123;target&#124;Target 1&#124;token_id&#125;.'
+'</li> '
+'</ul>'
+'</div>'
+'</div>'
+'</div>'
);
},
handleInput = function(msg) {
var args,
who,
errors = [],
bands = {},
tokens;
if(msg.type !== "api") {
return;
}
// get the name of the person executing the
who=getObj('player',msg.playerid).get('_displayname').split(' ')[0];
args=_.union(
msg.content.split(/\s+/),
(msg.selected && _.pluck(msg.selected,'_id')) || []
);
if(!_.contains(['!rangebands','!shortbands','!mediumbands','!clearbands'], args[0])) {
return;
}
tokens=_.chain(args)
.rest()
.uniq()
.map(function(a){
var t=getObj('graphic',a);
if(! t) {
errors.push('Argument [<b>'+a+'</b>] is not a valid token id.');
}
return t;
},errors)
.filter(function(t){
return undefined !== t;
})
.value();
if(errors.length) {
sendChat('','/w ' + who + ' '
+'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'
+'<div><span style="font-weight:bold;color:#990000;">Error:</span> '
+errors.join('</div><div><span style="font-weight:bold;color:#990000;">Error:</span> ')
+'</div>'
+'</div>'
);
}
if(0 === tokens.length) {
showHelp(who);
return;
}
switch(args[0]) {
case '!rangebands': // turn on short and medium
bands=_.extend({},shortBand,mediumBand);
break;
case '!shortbands':
bands=_.extend({},clearBands,shortBand);
break;
case '!mediumbands':
bands=_.extend({},clearBands,mediumBand);
break;
case '!clearbands':
bands=clearBands;
break;
}
_.each(tokens,function(t){
t.set(bands);
});
},
registerEventHandlers = function() {
on('chat:message', handleInput);
};
return {
RegisterEventHandlers: registerEventHandlers
};
}());
on('ready', function() {
'use strict';
EoERangeBands.RegisterEventHandlers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment