Ok, the final result of all my hard work, and I am now over an hour past my bed time, so this DOES count as hard work, is... Some thankyous first: Thanks Aaron, you been a great help, couldn't have done it without you buddy. Thanks to my boss for not giving a shit when I take a 2 hour lunch break to work on this instead of whatever I'm being paid a small fortune (its all relative) to work on. And thank you to... ehm... Who else... My Mom! Cause why not? The results look like this btw: Without further ado, the script: on('chat:message', function(msg){
var parts = msg.content.split(" ");
var name = parts[2];//should be the bit after "&{template:default} {{name="
//IE the name of the macro / template / whatever
if(name.toLowerCase() === "attack")
{
var result = msg.inlinerolls[0].results.total;
if (result > 0)
{
var numRolls = Math.max(Math.floor(result/10), 1);
var damage = " ?{Damage Roll|2d6} ";
sendChat("player|"+msg.playerid, "[Roll Damage!](!err" + damage + numRolls+")");
}
}
else return;
});
on('chat:message', function(msg) {
if (msg.type !== 'api') return;
var parts = msg.content.split(' ');
var command = parts.shift().substring(1);
if (command.toLowerCase() === 'err' && parts.length > 1) {
var roll = parts.slice(0, parts.length - 1);
var repeat = parseInt(parts.pop());
if (!repeat) return;
var location;
var output = genOutput(roll);
delayRoll('player|'+msg.playerid, output, repeat, true, roll);
}
function delayRoll(id, text, repeatsLeft, firstRoll, roll) {
if(repeatsLeft > 0)
{
if(firstRoll) sendChat(id, text);
else setTimeout(function(){ sendChat(id, text); }, 2000);
text = genOutput(roll);
delayRoll(id, text, repeatsLeft-1, false, roll);
}
}
function genOutput(roll)
{
var output = '/em ';
var tableRoll = randomInteger(100);
if(tableRoll <=50) location = "Body";
else if(tableRoll <=60 && tableRoll > 50) location = "Head";
else if(tableRoll <=70 && tableRoll > 60) location = "Left Arm";
else if(tableRoll <=80 && tableRoll > 70) location = "Right Arm";
else if(tableRoll <=90 && tableRoll > 80) location = "Left Leg";
else if(tableRoll <=100 && tableRoll > 90) location = "Right Leg";
else location = "Error";
return output += " Doing [[" + roll + "]] Damage to the <a>"+location+"</a>";
}
}); Thanks again, no doubt I will be back with more silly ideas for API thingies as my mate continues to develop his rule set. Smethane