By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

PhpMyChat and dice rolling...

P: n/a
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.

Lee

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 13 Mar 2005 07:52:05 -0800, la*******@yahoo.com wrote:
"/roll 2D6" to have the computer roll two six sided dice.


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 - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.