Last active
August 29, 2015 14:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 [<Token ID> ... ]</span></b><br>' | |
| +'<b><span style="font-family: serif;">!mediumbands [<Token ID> ... ]</span></b><br>' | |
| +'<b><span style="font-family: serif;">!rangebands [<Token ID> ... ]</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;"><Token ID></span></b> — A Token ID, usually supplied with something like @{target|Target 1|token_id}.' | |
| +'</li> ' | |
| +'</ul>' | |
| +'</div>' | |
| +'<b><span style="font-family: serif;">!clearbands [<Token ID> ... ]</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;"><Token ID></span></b> — A Token ID, usually supplied with something like @{target|Target 1|token_id}.' | |
| +'</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