PhpMyChat and dice rolling...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am new to PHP and am an avid RPG gamer.  I am looking to use
PhpMyChat to be able to game with friends all over the US.  With that
having been said, PhpMyChat seems to offer a lot of what I am looking
for.  It allows you to send a message to individual players (chatters).
 It allows for actions using "/me".  The only thing it really needs is
the capability to do a dice roll.  Can someone point me to a site which
might have some examples of commands?  I would like to create one that
is "/roll 2D6" to have the computer roll two six sided dice.  The dice
type in most role playing games are, 2, 4, 6, 8, 10, 12, 20, 100 sided
dice.  The format for rolling is always going to be "nDs", where "n" is
the number of dice to roll, and "D" is the seperator, and finally "s"
is the number of sides to roll.  I imagine the output would be...  "2D6
= 4 + 2 = 6".  In this example 4 and 2 are the random dice rolled and
the final 6 is the total.  Anyone who could help, or point me in the
right direction, would be greatly appreciated.  Thank you in advance.


Re: PhpMyChat and dice rolling...

On 13 Mar 2005 07:52:05 -0800, wrote:
Quoted text here. Click to load it

if ( preg_match( '/^\/roll ((\d+)D(\d+))$/', $inputline, $m ) )
    $dice = (int)$m[2];
    $sides = (int)$m[3];
    if ( $dice > 0 && $sides > 0 )
        $total = rand( 1, $sides );
        $output = $m[1].' = '.$total;
        for ( $i = 1; $i < $dice; ++$i )
            $j = rand( 1, $sides );
            $total += $j;
            $output .= ' + '.$j;
        $output .= ' = '.$total;

Firefox Web Browser - Rediscover the web - /
Thunderbird E-mail and Newsgroups - /

Site Timeline