!exr -help');
/**
* The core functionality of the script. Intercepts API messages meant for it, extracts the core of the command, and passes it to
* the appropriate function for handling.
*/
on('chat:message', function(msg) {
var apiWake = '!exr ';
if (msg.type == 'api' && msg.content.indexOf(apiWake) != -1) {
var slc = msg.content.slice(msg.content.indexOf(apiWake) + apiWake.length);
var rawCmd = slc.trim();
var patt = /^.*\#/;
if (patt.test(rawCmd)) {
parseCmd = rawCmd.replace('#', 'd10>7');
var rollStr = '/roll ' + parseCmd;
performRoll(msg, rollStr);
} else if (rawCmd.indexOf('-help') != -1) {
var outHTML = buildHelp();
sendChat('EX3Dice API', '/w ' + msg.who + ' ' + outHTML);
} else {
printError(msg, msg.who);
} // if
} // if
}); // on
/**
* The rolling function. Handles making the roll and passing the results to the anonymous callback function. Extracts the commands from
* the original roll string, and sends them along to be parsed and executed by the appropriate functions in the script.
*
* @param Roll20 Message Object msg The original message object.
* @param string cmd The properly parsed /roll command, to pass to the QuantumRoller.
*
* @return void
*/
function performRoll(msg, cmd) {
sendChat(msg.who, cmd, function(ops) {
if (ops[0].type == 'rollresult') {
var result = JSON.parse(ops[0].content);
var addSucc = 0;
var strSplit = ops[0].origRoll.split('-');
var cmds = [];
_.each(strSplit, parseCmds, cmds);
if (!_.isEmpty(cmds)) {
processCmds(cmds, result);
} else {
// If there are no commands passed, the script defaults to doubling 10s, which is what this call represents.
doDoubles(result, true, 0);
} // if
// This gets the player's color, for styling the roll result HTML output in buildHTML().
var player = getObj("player", msg.playerid);
var outHTML = buildHTML(result, msg.content, ops[0].origRoll, player.get('color'));
// Passes the final, formatted HTML as a direct message to the chat window.
sendChat(msg.who, '/direct ' + outHTML);
} else {
// Error handling.
printError(ops[0], msg.who);
} // if
});
} // performRoll
/**
* This is the function called by _.each(), above, to parse each command string into the command and its arguments (if any). In the
* _.each() call above, the cmds array is passed as the function's context.
*
* @param Array element Exalted 3rd Edition Dice Roller Help
'; outhtml += 'The basic syntax of most rolls you will make is:
'; outhtml += '!exr [no. of dice]#
The # marks the end of the dice statement, and this syntax provides the most common type of roll in ';
outhtml += 'Exalted: that many dice, with a target number of 7+, and 10s count double. In the majority of cases, this is all you need.
Charms, however, can throw a wrench in this, so I designed the script to be able to compensate. With the additional '; outhtml += 'commands and arguments, you can customize the way the roller treats your results and counts your successes, in order to match that behavior.
'; outhtml += 'The full syntax of rolls is as follows:
'; outhtml += '!exr [no. of dice]# -[cmd1] [arg1],[arg2]... -[cmd2] [arg3],[arg4]...
You can also type !exr -help to pull up this menu again, if necessary.
The following table explains the various commands.
'; var outhtml2 = '| Command | Explanation |
|---|---|
| ';
outhtml2 += '
| ';
outhtml2 += '';
outhtml2 += ' These commands cover doubling of successful results. The optional | ';
outhtml2 += '
| ';
outhtml3 += '
| ';
outhtml3 += '';
outhtml3 += ' These cover rerolls. The optional | ';
outhtml3 += '