Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- PhpMyChat and dice rolling...
March 13, 2005, 1:52 pm
rate this thread
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, firstname.lastname@example.org wrote:
if ( preg_match( '/^\/roll ((\d+)D(\d+))$/', $inputline, $m ) )
$dice = (int)$m;
$sides = (int)$m;
if ( $dice > 0 && $sides > 0 )
$total = rand( 1, $sides );
$output = $m.' = '.$total;
for ( $i = 1; $i < $dice; ++$i )
$j = rand( 1, $sides );
$total += $j;
$output .= ' + '.$j;
$output .= ' = '.$total;
Firefox Web Browser - Rediscover the web - http://getffox.com /
Thunderbird E-mail and Newsgroups - http://gettbird.com /