By dabid on

Not that I've been able to find anything like this for any other site or message board software, but I'd really be interested in someday applying a dice roller to one of my sites, for the purpose of play-by-post roleplaying and such. If I'm missing something notable, could someone point it out to me? (..not limited to drupal.. I haven't been able to find a dice roller for anything!.. even something as common as phpbb..) If I knew how to go about it, I'd build it myself.. but I still have my hands slightly full getting used to customizing themes. For someone that is fully capable of envisioning and for that matter executing such a task, at very least (if you don't want to just go ahead and make it for me.. :D ) could you give me an idea of a difficulty level?

Some features I had imagined it could have..
~simple XdY format.. probably a string of text in brackets .. [roll=2d4]
~multiple dice in one roll .. [roll=1d4,2d6,8d100]
~have some sort a history table in the database or something? the rolls would be numbered in sequence.. perhaps a page could display the numbers, each of these numbers could then be linked to the article or post in which they were rolled.

My followup question basically being, would the history feature be the downfall of an attempt at such a project? I MIGHT have a person or two to beg to do this for me, but I have to be able to convince them that it's not a waste of time first. ;)

Any thoughts or suggestions would be very cool.

Categories: Drupal 4.6.x

Comments

paperguy’s picture

dice

paperguy commented

Perhaps this can get you started...

A real implementation would need error-checking and all that unfun stuff.

<?php
print_r(roll_dice('1d4,2d6,8d100'));
function roll_dice($roll) {
 $rolls = explode(",", $roll);
 for ($i = 0; $i < count($rolls); $i++) {
 preg_match('/^\s*(\d+)\s*d\s*(\d+)\s*/i', $rolls[$i], $match);
 $n = 0;
 for ($j = 0; $j < $match[1]; $j++) {
 $n += rand(1, $match[2]);
 }
 $rolls[$i] = $n;
 }
 return $rolls;
}
?>
Brodie’s picture

Good idea!

Brodie commented

I like this idea. It seems like a custom input format to me. Tracking the history seems a little overkill to me, though. Perhaps adding dice widgets to HTMLAREA or FCK Editor would be good too.

Steel Rat’s picture

I realize this is a very old

Steel Rat commented

I realize this is a very old thread, but I haven't found any others relating to die rollers.

I'm very interested in this too for the same reasons originally stated.

I have already written a PHP/Javascript die roller I use on an independent page, it emails the results, but I need something integrated into Drupal, either as a content type, or CCK type.

I'm trying to experiment using the integer CCK type to make a couple simplt numeric fields to enter the number of sides on the die and the number of rolls. But how can I reference the fields mathematically inside the body of the content?

Steel Rat
My Drupal Sites:
RPGMapShare.com
Infinite Ordnance
Malvern Rouge Valley Youth Center