Skip to content

Instantly share code, notes, and snippets.

@shdwjk
Last active August 29, 2015 14:09
Show Gist options
  • Save shdwjk/7ddf557cc365f489659f to your computer and use it in GitHub Desktop.
Save shdwjk/7ddf557cc365f489659f to your computer and use it in GitHub Desktop.
Roll20 API: MovePlayers -- Allows macros to move the player ribbon for players.
// GIST: https://gist.github.com/shdwjk/7ddf557cc365f489659f
var MovePlayers = MovePlayers || (function() {
'use strict';
var version = 0.1,
ch = function (c) {
var entities = {
'<' : 'lt',
'>' : 'gt',
"'" : '#39',
'@' : '#64',
'{' : '#123',
'|' : '#124',
'}' : '#125',
'[' : '#91',
']' : '#93',
'"' : 'quot',
'-' : 'mdash',
' ' : 'nbsp'
};
if(_.has(entities,c) ){
return ('&'+entities[c]+';');
}
return '';
},
showHelp = function() {
sendChat('',
'/w gm '
+'<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%;">'
+'MovePlayers v'+version
+'</div>'
+'<div style="padding-left:10px;margin-bottom:3px;">'
+'<p>MovePlayers provides facilities for moving your players around at will.</p>'
+'</div>'
+'<b>Commands</b>'
+'<div style="padding-left:10px;">'
+'<b><span style="font-family: serif;">!move-players-to-same-page-as '+ch('<')+'Token ID'+ch('>')+'</span></b>'
+'<div style="padding-left: 10px;padding-right:20px">'
+'<p>Moves the Players ribbon to the same page as the token identified by <b>Token ID</b>.</p>'
+'<ul>'
+'<li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;">'
+'<b><span style="font-family: serif;">'+ch('<')+'Token ID'+ch('>')+'</span></b> '+ch('-')+' The token_id for the token whose page the players should be moved to.'
+'</li> '
+'</ul>'
+'</div>'
+'</div>'
+'</div>'
);
},
handleInput = function(msg) {
var args, obj;
if (msg.type !== "api" || !isGM(msg.playerid)) {
return;
}
args = msg.content.split(" ");
switch(args[0]) {
case '!move-players-to-same-page-as':
if('--help' === args[1] || args.length < 2) {
showHelp();
return;
}
obj=getObj('graphic',args[1]);
if(!obj) {
sendChat('','/w gm No token found for id: '+args[1]);
} else {
Campaign().set({
playerpageid: obj.get('pageid')
});
}
break;
}
},
registerEventHandlers = function() {
on('chat:message', handleInput);
};
return {
RegisterEventHandlers: registerEventHandlers
};
}());
on("ready",function(){
'use strict';
if("undefined" !== typeof isGM && _.isFunction(isGM)) {
MovePlayers.RegisterEventHandlers();
} else {
log('--------------------------------------------------------------');
log('MovePlayers requires the isGM module to work.');
log('isGM GIST: https://gist.github.com/shdwjk/8d5bb062abab18463625');
log('--------------------------------------------------------------');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment