Page 8 of 12

Re: [RC1] Dice MOD

Posted: Sat Jan 12, 2008 11:24 pm
by Madhaus
Okay, I MAY be continuing my Warhammer Fantasy RPG, which ran from May 2003 until August 5th, 2006, and it was an excellent game with excellent players. I'm looking to upgrade to phpBB3, which is why I came here looking for a dice mod.

First concern is I've seen two statements that contradict each other throughout all seven of these pages, and to clarify I need to know... if I've made a post in which there are one or more dice rolls, and I go back to edit that post, do the previously rolled numbers remain, or are they generated new?

The second concern I have is that I need open-ended/meta/exploding dice available for my game; meta-dice are also used for over a dozen RPGs that could find their way to the internet, and it's the entire gammit of polyhedron's, not just d10s or d6s. For those who don't know, open-ended/meta/exploding dice are those in which if the maximum number for that dice is rolled (such as a 4 on 1d4 or an 8 on 1d8), that dice is rolled again and added to the previous roll as well as any remaining dice in the set.

A friend of mine, Niagol, who has/had a presence on these forums but doesn't visit that often, I think, came up with a solution for the exploding dice problem, and the following code is what he came up with... (NOTE that this is from around phpBB 2.0.16 release time, k?

This goes in includes/bbcode.php, just paste it over the old code.

Code: Select all

 function replace_dice_results($text, $uid) 
{ 
   global $lang; 
   // Take the desired Die string ($text) and generate values for each roll. 

   $Expressions = explode('=', $text); 
   if( (isset($Expressions[0])) && (isset($Expressions[1])) ) 
   { 
      $Dice_Rolls = $Expressions[0]; 
      $MT_Seed = intval($Expressions[1]);//(double)microtime()*1000000; doesn't work as it causes the rolls to be re-rolled every time the topic/post is re-loaded// 
      $Fixed = $Expressions[2]; 
   } 
   else 
   { 
      return; 
   } 

   // Make sure we restore the MT gen to a random state after we are done... 
   $Future_Seed = mt_rand(); 
   mt_srand( $MT_Seed ); 

   $Original_Roll_String = (isset($Fixed)) ? $Dice_Rolls . ' <b><span style="color: #AA0000">' . $lang['Dice_Mod_Fixed'] . '</span></b>': $Dice_Rolls; 
   $Die_Rolls = explode(' ', trim($Dice_Rolls)); 
   //Break off Original Roll string seperate from Roll results 
   $headerroll = '<b>' . $lang['Dice_Mod_Roll_String'] . '</b>: ' . $Original_Roll_String; 

   while( $Die = array_shift($Die_Rolls)) 
   { 
      $footer = ''; 
      $header = ''; 
      $Die_Count = substr($Die,0,strpos($Die,'d')); 
      $Die_Type = substr($Die,strpos($Die,'d')+1); 
      if( strpos($Die_Type, '+') ) 
      { 
         $Method = 1; 
         $Modifier = substr($Die_Type,strpos($Die_Type,'+')+1); 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'+')); 
      } 
      else if( strpos($Die_Type, '-') ) 
      { 
         $Method = 2; 
         $Modifier = substr($Die_Type,strpos($Die_Type,'-')+1); 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'-')); 
      } 
      else if( strpos($Die_Type, '*') ) 
      { 
         $Method = 3; 
         $Modifier = substr($Die_Type,strpos($Die_Type,'*')+1); 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'*')); 
      } 
      else if( strpos($Die_Type, 'x') ) 
      { 
         $Method = 3; 
         $Modifier = substr($Die_Type,strpos($Die_Type,'x')+1); 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'x')); 
      } 
      else if( strpos($Die_Type, '/') ) 
      { 
         $Method = 4; 
         $Modifier = substr($Die_Type,strpos($Die_Type,'/')+1); 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'/')); 
      } 
      else if( strpos($Die_Type, 'e') ) 
      { 
         $Method = 5; //Checking for the Exploding Dice 
         $Modifier = 0; 
         $Die_Type = substr($Die_Type,0,strpos($Die_Type,'e')); 
      } 
      else 
      { 
         $Method = 0; 
         $Modifier = 0; 
      } 
      $header = '<br /><b>' . $Die_Type . '-Sided Dice Results: </b>'; 
      $footer = ''; 
      $Die_Count = intval($Die_Count); 
      if( $Die_Count == 0 ) $Die_Count = 1; 
      $total = 0; 

      if( $Method ) 
      { 
         $footer = $footer . "("; 
      } 

      // Loop Limit to prevent 500000d500000 sort of dice due to max. execution time limit 
      if($Die_Count <= 200 && $Die_Type <= 100) 
      { 
         for( $i = 0; $i < $Die_Count; $i++ ) 
         { 
            if( $Die_Type == 100 ) 
            { 
               $value1 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10) * 10; 
               $value2 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10); 
               $dieexp = ($value1 + $value2) + 1; //Add 1 to get 1 to 100 instead of 0 to 99 
               $exploding = 1; 
               if( $Method == 5 ) 
               { 
                   While( $dieexp == ($exploding * 100) ) 
                   { 
                       $value1 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10) * 10; 
                       $value2 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10); 
                       $dieexp2 = ($value1 + $value2) + 1; 
                       $dieexp = $dieexp + $dieexp2; 
                       $exploding++; 
                        
                   } 
               } 
               $total = $total + $dieexp; 
               if( $exploding > 1 ) 
               { 
                   $footer = ($i != $Die_Count - 1) ? $footer . $dieexp . ' (100 + ' . ($dieexp - 100) . ' exploding<b></b>), ' : $footer .  $dieexp . ' (100 + ' . ($dieexp - 100) . ' exploding<b></b>), '; 
               } 
               else 
               { 
                   $footer = ($i != $Die_Count - 1) ? $footer . $dieexp . '<b></b>, ' : $footer .  $dieexp . '<b></b>'; 
               } 
            } 
            else 
            { 
               $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1; 
               $dieexp = $value; 
               $exploding = 1; 
               //Check for exploding method 
               if( $Method == 5 ) 
               { 
                   //Check to see if max roll was done and roll again if so 
                   While( $dieexp == ($exploding * $Die_Type) ) 
                   { 
                       $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1; 
                       $dieexp2 = $value; 
                       $dieexp = $dieexp + $dieexp2; 
                       $exploding++; 
                        
                   } 
               } 
               $total = $total + $dieexp; 
               if( $exploding > 1 ) 
               { 
                   //Append dice roll + exploding count to display 
                   $footer = ($i != $Die_Count - 1) ? $footer . $dieexp . ' (' . $Die_Type . ' + ' . ($dieexp - $Die_Type) . ' exploding<b></b>), ' : $footer .  $dieexp . ' (' . $Die_Type . ' + ' . ($dieexp - $Die_Type) . ' exploding<b></b>), '; 
               } 
               else 
               { 
                   $footer = ($i != $Die_Count - 1) ? $footer . $dieexp . '<b></b>, ' : $footer .  $dieexp . '<b></b>'; 
               } 
            } 
         } 
      } // Loop limit 
      else 
      { 
         $total = 0; 
         $Modifier = 0; 
         $footer = 'Too many dice and/or too many sides'; 
      } 

      switch( $Method ) 
      { 
      case 1: 
         $footer =  $footer . '<b></b>) + ' . $Modifier . ' '; 
         $total = $total + $Modifier; 
         break; 
      case 2: 
         $footer =  $footer . '<b></b>) - ' . $Modifier . ' '; 
         $total = $total - $Modifier; 
         break; 
      case 3: 
         $footer =  $footer . '<b></b>) * ' . $Modifier . ' '; 
         $total = $total * $Modifier; 
         break; 
      case 4: 
         $footer =  $footer . '<b></b>) / ' . $Modifier . ' '; 
         $total = $total / $Modifier; 
         break; 
      case 5: 
         $footer =  $footer . '<b></b>) '; 
         break; 
      } 
      // I do b - /b on purpose...  kills out some smilies that crop up. 
      if( ($Die_Count > 1) || ($Method != 0) ) 
      { 
         $footer=  $footer . ' (<b>Total =</b> ' . $total . '<b></b>)<BR>'; 
      } 
      else 
      { 
         $footer =  $footer . '<BR>'; 
      } 
      $footer = $footer. ""; 
      $results = $results . $header . $footer; 
   } 
   // Restore MT randomness 
   mt_srand($Future_Seed); 
   $results = $headerroll . $results;  //appends dice roll information to original roll info 
   return $results; 
} 

// -------------------------------- 
// END DICE MOD CODE 
// --------------------------------

Re: [RC1] Dice MOD

Posted: Mon Jan 14, 2008 3:00 am
by coppro
I'm rewriting this MOD now that 3.0.0 is out. I've improved the code to better integrate with the existing systems, and to mean less overall edits.

The new code will also feature full expressions. I plan on allowing the following:

1d3 :: roll a d3.
1e10 :: roll a d10. If you get the maximum value, roll another one and add it.
5d10:7 :: roll 5d10s and show the number greater than 7.

The problem with adding things like explosions before was that the engine wasn't a full expression parser. I'm changing it to be one. It also may break some advanced uses of existing script, but that's okay, because this was never actually released.

Re: [RC1] Dice MOD

Posted: Mon Jan 14, 2008 3:13 am
by Madhaus
Well, I will be more than happy to wait to put up my new forum until that dice mod is done, then. It's the most integral part of my gaming forum, so I'm looking forward to seeing what you have. Thank you.

Re: [RC1] Dice MOD

Posted: Mon Jan 14, 2008 4:35 pm
by anodyzed
coppro wrote:I'm rewriting this MOD now that 3.0.0 is out. I've improved the code to better integrate with the existing systems, and to mean less overall edits.
SOUNDS GREAT! I also will be waiting patiently for your release of this mod before I move my board to the new v3

Thank you!

John
http://www.whidbeygamers.net

Re: [RC1] Dice MOD

Posted: Mon Jan 14, 2008 5:21 pm
by CancelloCornorosso
Dice mod is basically the only mod I need for my forum, so it's great to know you are working to improve it, Coppro. Thank you!

I hope you'll give a look at the way the dice bbcode button is implemented (id code and all) because I installed the mod twice and both times I struggled a bit, and I noticed a couple of other comments about the same point in the thread.

keep up the good work

Re: [RC1] Dice MOD

Posted: Tue Jan 15, 2008 2:34 am
by coppro
CancelloCornorosso wrote:I hope you'll give a look at the way the dice bbcode button is implemented (id code and all) because I installed the mod twice and both times I struggled a bit, and I noticed a couple of other comments about the same point in the thread.
I recently found out that there's a limit on the number of BBCodes that can be added by the system, so anything outside of that is fair game. Any thoughts on what the ID should be? I'm thinking 314159, but if anyone has something nerdier, feel free to tell me!

Re: [RC1] Dice MOD

Posted: Thu Jan 17, 2008 8:36 am
by myboy
An update this mod is sound great. Don't forget to review the PM's part. Some codes don't exist.

Good work and success.

Sorry my bad english.

Re: [RC1] Dice MOD

Posted: Mon Jan 21, 2008 2:02 pm
by pmdweb
Hello,

I have problems to unzip the dice.zip file. is return a error saying its corrupted, so i cannot intal. in other place i can see the .php file, but, how is knowed(<= this word exist?), it's impossible to download.


if u can post another place to get this mod.
i use the phpbb3.0.0 this mod is functional in this version?


Edit:
( Ok, i find a "release" at page 7, it is the dice.zip, with the fixes of preview pages?)

thanks for your atenttion. ^^

Re: [RC1] Dice MOD

Posted: Mon Jan 21, 2008 4:25 pm
by coppro
I just wanted to ask if anyone has any experience writing expression parsers. I don't, personally, and in all likelihood, there's someone reading this who can do way better than I can at writing one, and since I lost a fair bit of my rewrite due to a crash (not too much; I can rerewrite it), I was wondering if anyone here would be good at that kind of stuff, or at least be able to tell me the best approach to take - should I use REs? How do I handle parentheses? That kind of information would be useful.

Thanks to anyone who can offer advice/help!

Re: [RC1] Dice MOD

Posted: Mon Jan 21, 2008 9:02 pm
by i101
Great mod. Thats what I need for my Pen&Paper RPG Group ... Does the mod work for anyone here with Version 3.0.0?

Re: [RC1] Dice MOD

Posted: Mon Jan 21, 2008 11:28 pm
by Madhaus
I'm sorry, Coppro, I have no experience with php, except for modifying absolutely the most basic code. If I speak to anyone who might be able to help you, I'll get them to contact you.

Re: [RC1] Dice MOD

Posted: Tue Jan 22, 2008 11:18 pm
by i101
Hoi, cant implement following changes ... The editor simply cant find the partial find ... Neither for the 1st and 2nd qoute. I am using a "fresh" 3.0.0 version of phpbb and besides those two problems I found everything else ...

Open: incudes/ucp/ucp_pm_viewmessage.php
Find
Tip: This may be a partial find and not the whole line.

Code:Select All
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
Add after
Tip: Add these lines on a new blank line after the preceding line(s) to find.

Code:Select All
if (!class_exists('dice'))
{
include($phpbb_root_path . 'includes/dice.' . $phpEx);
}
$dice = new dice();
Find
Tip: This may be a partial find and not the whole line.

Code:Select All
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
Add after
Tip: Add these lines on a new blank line after the preceding line(s) to find.

Code:Select All
if (has_dice($row['bbcode_bitfield']))
{
$dice->dice('privmsg', $id);
$dice->parse($message);
}
Furthermore I dont understand the following part (Sorry guys, but english is not my native language and unfortunately I am not a PHP Halfgod ...
Create a new BBCode from the admistration panel. The contents and name are completely irrelevant.
I am thankfull for any advice ...

Re: [RC1] Dice MOD

Posted: Thu Jan 24, 2008 2:49 am
by coppro
I would recommend waiting until I come out with the new one, as it will be better, and quite possibly not be backwards-compatible (apologies, but I know that if you want to upgrade, you'll need a special script. It could be done, but it wouldn't be done until some time after I finish this (If you were to manually click the edit button and then save the post, that will update them too.)

The biggest changes that could affect previous versions are the changing of the DICE_BBCODE_ID constant to 4242, the change of the % modifier to $ (% is now modulo), and the addition of precedence (so "2d3d5" will roll 2d3 5-sided dice, and "2d(3d5)" will roll 2 3d5-sided dice) to line up with every other mathematical expression system.

I'm going to use Bison to generate the parser, then manually convert the code to PHP.

Re: [RC1] Dice MOD

Posted: Thu Jan 24, 2008 11:47 am
by golgoth
Any ETA for the new version?

Re: [RC1] Dice MOD

Posted: Thu Jan 24, 2008 12:06 pm
by elazard
well that mod looks great i just wanted to know if it s possible that the roll bbcode do always same i mean i just want to roll 2 dices with 6 faces each and not allow user to do other roll. Is it possible?
sorry if the question has already been answered but as you should see my english sucks so i may not have understood everything^^