This is the code for a generic dice roller:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
if (/^\/roll ((\d+)?d(\d+)(\+(\d+))?)$/i.test(Message)) {
var Number = RegExp.$2 ? RegExp.$2 : 1;
var Side = RegExp.$3;
var Modifier = RegExp.$5 ? RegExp.$5 : 0;
var Result = new Array();
for (var i = 0; i < Number; i++) Result[i] = Math.ceil(Math.random() * Side) + Modifier * 1;
return RegExp.$1 + " = [" + Result + "]";
}
}
If you wish to use this, the format is "/roll <number>d<side>[+<modifier>]" (ie. "/roll d6", "/roll 2d6" and "/roll 4d10+3").
Now for your specific dice roller. Here is the code:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
if (/^\/roll (\d+)$/i.test(Message)) {
var Number = RegExp.$1;
var Result = new Array();
for (var i = 0; i < Number; i++) Result[i] = Math.ceil(Math.random() * 10);
Result = Result.join(", ");
var Success = 0;
try { Success = Result.match(/8|9|10/g).length; } catch (e) { }
return "\/me rolls " + Number + " di" + (Number == 1 ? "" : "c") + "e [" + Result.replace(/8|9|10/g, "[b]$&[\/b]") + "] and gets [u]" + Success + "[\/u] success" + (Success == 1 ? "" : "es") + ".";
}
}
I've attached the script at the bottom of this post, which is easier to distribute.
I haven't implemented the 10 again thing, because I don't quite understand how it works with the 9 again and 8 again. If you want to explain it in more detail, I'll be happy to try to put it in the script as well.
Also, this script will use the "/me" command to display the results. Hopefully this is what you wanted.