What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Request] Multiple d10 Dice Roller

[Request] Multiple d10 Dice Roller
Author: Message:
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: [Request] Multiple d10 Dice Roller
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.

.plsc File Attachment: Multiple d10 Dice Roller.plsc (988 bytes)
This file has been downloaded 186 time(s).

This post was edited on 02-02-2008 at 12:36 AM by phalanxii.
02-02-2008 12:34 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Request] Multiple d10 Dice Roller - by Dastion on 02-01-2008 at 01:30 PM
RE: [Request] Multiple d10 Dice Roller - by phalanxii on 02-02-2008 at 12:34 AM
RE: [Request] Multiple d10 Dice Roller - by Dastion on 02-02-2008 at 09:14 AM
RE: [Request] Multiple d10 Dice Roller - by phalanxii on 02-02-2008 at 12:17 PM
RE: [Request] Multiple d10 Dice Roller - by Dastion on 02-02-2008 at 01:17 PM
RE: [Request] Multiple d10 Dice Roller - by phalanxii on 02-03-2008 at 03:03 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On