473,226 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

PhpMyChat and dice rolling...

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
1 1932
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
1
by: compac | last post by:
I have not found a useful forum for phpMyChat, so have tried to fill the gap. Please check it out here. Please remember that every forum has to start with the first post. Be a saint and make the...
101
by: Elijah Cardon | last post by:
Let's say I have m dice having n sides, such that n^m is not going to bust int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}. What is a good way to represent this in c so that...
17
by: Jose Durazo | last post by:
Hello, I'm doing an exercise to simulate rolling a pair of dice 36,000 times, then count and display how many times the simulation rolls each possible sum. For some reason each time I run my...
1
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
4
by: vegtard | last post by:
simple question. is it possible to write a script that rolls a six sided dice? if this is possible, is it possible to tell it to roll the six sided dice 4 times and ignore the dice that rolled...
38
by: d0ugg | last post by:
I'm writing a program that will have to roll the dice A and dice B one million times, and calculate the percentage of times that the dies will be equal. I'm having trouble to figure out how the...
2
by: sunnydude | last post by:
Anybody know how to write a 3 dice rolling program like this Sample output Welcome to the dice roller! First of all, please enter a seed for the random number generator. This should be a...
2
by: cowboyjeff05 | last post by:
the question is 1) build a Die class (6 sided). Then create a driver that tests your class. Start with one die in your driver then add a second die and notify the user and count when he or she rolls...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.