Icy Phoenix

     
 


Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post Help on Dice BBCode! 
 
Hi, neighbours and friends...

I'm trying to make a new bbcode for Role Playing Games and whatever a random number generation could be for.

I used to use it for making contests in my web.

I've made this:

open includes/bbcode.php
Find (for instances)
Code: [Download] [Hide]
  1.             'fade' => array(  
  2.                     'nested' => true,  
  3.                     'inurl' => true,  
  4.                     'allow_empty' => false,  
  5.                     ), 


Right after add
Code: [Download] [Hide]
  1.             'dice' => array(  
  2.                     'nested'    => false,  
  3.                     'inurl'        => false,  
  4.                     'allow_empty'    => false,  
  5.                     ), 


Find
Code: [Download] [Hide]
  1. // --- Disable Active Content Switch BEGIN --- 


Right before add
Code: [Download] [Hide]
  1.         // BBcode dice, by Roland at ka-tet-corp.com. Based upon MOD-dice by >achary Aerogos (tribalgenesis at hotmail.com)  
  2.         if($tag === 'dice')  
  3.         {  
  4.             $Die = $content;  
  5.             $Expressions = explode('d', $content);  
  6.             if( (isset($Expressions[0])) && (isset($Expressions[1])) )  
  7.             {  
  8.                 $dice_Rolls = $Expressions[0];  
  9.                 $MT_Seed = (double)microtime()*1000000;//intval($Expressions[1]);  
  10.             }  
  11.             $Die_Count = $Expressions[0];  
  12.             $Die_Type = $Expressions[1];  
  13.             // Make sure we restore the MT gen to a random state after we are done...  
  14.             $Future_Seed = mt_rand();  
  15.             mt_srand( $MT_Seed );  
  16.  
  17.             $Original_Roll_String = '(' . $content . ') <b><span style="color: #AA0000"> Fixed</span></b>';  
  18.             $Die_Rolls = explode(' ', trim($dice_Rolls));  
  19.             $header = '<b>Sort of roll</b>: ' . $Die_Count . ' dices of ' . $Die_Type . ' sides ' . $Original_Roll_String . '<br /><b>' . $Die_Type . '-Result: </b>';  
  20.             $footer = '';  
  21.             $Die_Count = intval($Die_Count);  
  22.             if( $Die_Count == 0 ) $Die_Count = 1;  
  23.             $total = 0;  
  24.               
  25.             // Loop Limit to prevent 500000d500000 sort of dices due to max. execution time limit  
  26.             if($Die_Count <= 200 && $Die_Type <= 100)  
  27.             {  
  28.                 for( $i = 0; $i < $Die_Count; $i++ )  
  29.                 {  
  30.                     if( $Die_Type == 100 )  
  31.                     {  
  32.                         $value1 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10) * 10;  
  33.                         $value2 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10);  
  34.                         $total = $total + ($value1 + $value2);  
  35.                         $footer = ($i != $Die_Count - 1) ? $footer . $value1 . '+' . $value2 . '(' .($value1 + $value2) . '), ' : $footer .  $value1 . '+' . $value2 . '(' . ($value1 + $value2) . ')';  
  36.                     }  
  37.                     else  
  38.                     {  
  39.                         $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1;  
  40.                         $total = $total + $value;  
  41.                         $footer = ($i != $Die_Count - 1) ? $footer . $value . ', ' : $footer . $value . '';  
  42.                     }  
  43.                 }  
  44.             } // Loop limit  
  45.             else  
  46.             {  
  47.                 $total = 0;  
  48.                 $footer = 'Too many dices and/or too many sides';  
  49.             }  
  50.                 // I do b - /b on purpose...  kills out some smilies that crop up.  
  51.             if( ($Die_Count > 1))  
  52.             {  
  53.                 $footer=  $footer . ' (<b>Total =</b> ' . $total . '<b></b>)<BR>';  
  54.             }  
  55.             else  
  56.             {  
  57.                 $footer =  $footer . '<BR>';  
  58.             }  
  59.             $footer = $footer. "";  
  60.             $results = $header . $footer;  
  61.  
  62.             // Restore MT randomness  
  63.             mt_srand($Future_Seed);  
  64.               
  65.             //list($usec,$sec)=explode(" ",microtime());  
  66.             mt_srand((double)microtime()*1000000);//$sec * $usec);  
  67.               
  68.             // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades  
  69.                 mt_rand();  
  70.  
  71.             return array(  
  72.                 'valid'  => true,  
  73.                 'html'  => $results  
  74.                 );  
  75.         } 


To use it, you write:
Code: [Download] [Hide]
  1. [dice]xdyy[/dice] 


x means number of dices to roll
yy means number of sides of each dice

i.e
Code: [Download] [Hide]
  1. [dice]2d10[/dice] 

To roll 2 dices of 10 sides.

But now comes the problem.

Because of this line:
Code: [Download] [Hide]
  1. $MT_Seed = (double)microtime()*1000000; 


Everytime the post is reloaded, the result changes.

I fixed it using precompiled posts, so the message is saved as is and the dices are not rolled every time the post is reloaded.

But I would like to know what should I do to avoid the precompiled posts.

I've tried this
Code: [Download] [Hide]
  1. $MT_Seed = $uid; 

to use a random number that won't change everytime the post is loaded, but, as $uid is null, I always get the same "Random" number. I mean, If I roll 100 times a dice like 1d10 in 100 different posts, I always get the same number... That's not too random, isn't it?

Any idea is welcome!

Thanks in advance!!
 




____________
Icy Phoenix Latest 2.0 (working pending)
Style: Aphrodite and MG_Themes
Site: Spanish Stephen King fan forum
Mods: Medal System Mod. BBAntispam 1.2. Several own BBcodes.
 
XusquiSend private messageVisit poster's website  
Back to topPage bottom
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
I think that the only way to do it is inserting the number in the DB when the post is submitted.

But then you have to modify the posting function...
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
That would be a solution, but I don't want to mess up with the DB... There must be another solution, as the original mod dosen't make any modification in the DB and works...

If any otherone is interested, I can send him/her the original BBCode to see if we find a solution...

Thnx, MG!!
 




____________
Icy Phoenix Latest 2.0 (working pending)
Style: Aphrodite and MG_Themes
Site: Spanish Stephen King fan forum
Mods: Medal System Mod. BBAntispam 1.2. Several own BBcodes.
 
XusquiSend private messageVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
Attach the mod here... maybe I'll try to do it sooner or later...
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help On Dice BBCode! 
 
Looks like there's a very similar post right here.....
h**p://***.icyphoenix.it/viewtopic.php?p=6422#p6422

Does anyone care for it?
Excluding me, of course, since I'm not a programmer.....

Ah, almost forgot: I'm zio_gilmor  
 



 
IntactoSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
Intacto wrote: [View Post]
Looks like there's a very similar post right here.....
http://www.icyphoenix.it/viewtopic.php?p=6422#p6422

Does anyone care for it?
Excluding me, of course, since I'm not a programmer.....

Ah, almost forgot: I'm zio_gilmor  

You are still keeping busy Raphael10 with this... plus I already told you something in the Italian support.

Please do not cross post the same request and be patient.
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help On Dice BBCode! 
 
I finally fix the bug that always give the same result at rolled dices and add an increment value that can be +, -, * or /. I remakes the layout too.

Find
Code: [Download] [Hide]
  1. # // BBcode dice, by Roland at ka-tet-corp.com. Based upon MOD-dice by >achary Aerogos (tribalgenesis at otmail.com)    
  2.         if($tag === 'dice')    
  3.         {    
  4.             $Die = $content;    
  5.             $Expressions = explode('d', $content);    
  6.             if( (isset($Expressions[0])) && (isset($Expressions[1])) )    
  7.             {    
  8.                 $dice_Rolls = $Expressions[0];    
  9.                 $MT_Seed = (double)microtime()*1000000;//intval($Expressions[1]);    
  10.             }    
  11.             $Die_Count = $Expressions[0];    
  12.             $Die_Type = $Expressions[1];    
  13.             // Make sure we restore the MT gen to a random state after we are done...    
  14.             $Future_Seed = mt_rand();    
  15.             mt_srand( $MT_Seed );    
  16.     
  17.             $Original_Roll_String = '(' . $content . ') <b><span style="color: #AA0000"> Fixed</span></b>';    
  18.             $Die_Rolls = explode(' ', trim($dice_Rolls));    
  19.             $header = '<b>Sort of roll</b>: ' . $Die_Count . ' dices of ' . $Die_Type . ' sides ' . $Original_Roll_String . '<br /><b>' . $Die_Type . '-Result: </b>';    
  20.             $footer = '';    
  21.             $Die_Count = intval($Die_Count);    
  22.             if( $Die_Count == 0 ) $Die_Count = 1;    
  23.             $total = 0;    
  24.                 
  25.             // Loop Limit to prevent 500000d500000 sort of dices due to max. execution time limit    
  26.             if($Die_Count <= 200 && $Die_Type <= 100)    
  27.             {    
  28.                 for( $i = 0; $i < $Die_Count; $i++ )    
  29.                 {    
  30.                     if( $Die_Type == 100 )    
  31.                     {    
  32.                         $value1 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10) * 10;    
  33.                         $value2 = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * 10);    
  34.                         $total = $total + ($value1 + $value2);    
  35.                         $footer = ($i != $Die_Count - 1) ? $footer . $value1 . '+' . $value2 . '(' .($value1 + $value2) . '), ' : $footer .  $value1 . '+' . $value2 . '(' . ($value1 + $value2) . ')';    
  36.                     }    
  37.                     else    
  38.                     {    
  39.                         $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1;    
  40.                         $total = $total + $value;    
  41.                         $footer = ($i != $Die_Count - 1) ? $footer . $value . ', ' : $footer . $value . '';    
  42.                     }    
  43.                 }    
  44.             } // Loop limit    
  45.             else    
  46.             {    
  47.                 $total = 0;    
  48.                 $footer = 'Too many dices and/or too many sides';    
  49.             }    
  50.                 // I do b - /b on purpose...  kills out some smilies that crop up.    
  51.             if( ($Die_Count > 1))    
  52.             {    
  53.                 $footer=  $footer . ' (<b>Total =</b> ' . $total . '<b></b>)<BR>';    
  54.             }    
  55.             else    
  56.             {    
  57.                 $footer =  $footer . '<BR>';    
  58.             }    
  59.             $footer = $footer. "";    
  60.             $results = $header . $footer;    
  61.     
  62.             // Restore MT randomness    
  63.             mt_srand($Future_Seed);    
  64.                 
  65.             //list($usec,$sec)=explode(" ",microtime());    
  66.             mt_srand((double)microtime()*1000000);//$sec * $usec);    
  67.                 
  68.             // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades    
  69.                 mt_rand();    
  70.     
  71.             return array(    
  72.                 'valid'  => true,    
  73.                 'html'  => $results    
  74.                 );    
  75.         } 


Replace
Code: [Download] [Hide]
  1. // BBcode dice, by Roland at ka-tet-corp.com. Based upon MOD-dice by >achary Aerogos (tribalgenesis at hotmail.com)fixed by Yuri Menzl Celaschi    
  2.         if($tag === 'dice')    
  3.         {    
  4.             $Die = $content;    
  5.             $Expressions = explode('d', $content);    
  6.             if( (isset($Expressions[0])) && (isset($Expressions[1])) )  
  7.            {  
  8.               $Dice_Rolls = $Expressions[0];  
  9.               $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//  
  10.               $Fixed = $Expressions[2];  
  11.            }  
  12.           else  
  13.            {  
  14.               return;  
  15.            }  
  16.             $Die_Count = $Expressions[0];    
  17.             $Die_Type = $Expressions[1];  
  18.           
  19.             /*// Make sure we restore the MT gen to a random state after we are done...    
  20.             $Future_Seed = mt_rand();    
  21.             mt_srand( $MT_Seed );  */  
  22.           
  23.             $Original_Roll_String = '<b>(' . $content . ')</b>';  
  24.             $Die_Rolls = explode(' ', trim($Dice_Rolls));  
  25.  
  26.         $Die_Count = substr($Die,0,strpos($Die,'d'));  
  27.       $Die_Type = substr($Die,strpos($Die,'d')+1);  
  28.       if( strpos($Die_Type, '+') )  
  29.       {  
  30.          $Method = 1;  
  31.          $Modifier = substr($Die_Type,strpos($Die_Type,'+')+1);  
  32.          $Die_Type = substr($Die_Type,0,strpos($Die_Type,'+'));  
  33.       }  
  34.       else if( strpos($Die_Type, '-') )  
  35.       {  
  36.          $Method = 2;  
  37.          $Modifier = substr($Die_Type,strpos($Die_Type,'-')+1);  
  38.          $Die_Type = substr($Die_Type,0,strpos($Die_Type,'-'));  
  39.       }  
  40.       else if( strpos($Die_Type, '*') )  
  41.       {  
  42.          $Method = 3;  
  43.          $Modifier = substr($Die_Type,strpos($Die_Type,'*')+1);  
  44.          $Die_Type = substr($Die_Type,0,strpos($Die_Type,'*'));  
  45.       }  
  46.       else if( strpos($Die_Type, 'x') )  
  47.       {  
  48.          $Method = 3;  
  49.          $Modifier = substr($Die_Type,strpos($Die_Type,'x')+1);  
  50.          $Die_Type = substr($Die_Type,0,strpos($Die_Type,'x'));  
  51.       }  
  52.       else if( strpos($Die_Type, '/') )  
  53.       {  
  54.          $Method = 4;  
  55.          $Modifier = substr($Die_Type,strpos($Die_Type,'/')+1);  
  56.          $Die_Type = substr($Die_Type,0,strpos($Die_Type,'/'));  
  57.       }  
  58.       else  
  59.       {  
  60.          $Method = 0;  
  61.          $Modifier = 0;  
  62.       }  
  63.  
  64.             $header = '<div align=center><b>Dice rolled</b><br>You rolled ' . $Die_Count . ' dices of ' . $Die_Type . ' sides ' . $Original_Roll_String . '<br /><b>Partial Result: </b>';    
  65.             $footer = '';    
  66.             $Die_Count = intval($Die_Count);    
  67.             if( $Die_Count == 0 ) $Die_Count = 1;    
  68.             $total = 0;           
  69.                 
  70.             // Loop Limit to prevent 500000d500000 sort of dice due to max. execution time limit  
  71.       if($Die_Count <= 200 && $Die_Type <= 100)  
  72.       {  
  73.          for( $i = 0; $i < $Die_Count; $i++ )  
  74.          {  
  75.             if( $Die_Type == 100 )  
  76.             {  
  77.                $value1 = mt_rand(1,9) * 10;  
  78.                $value2 = mt_rand(1,10);  
  79.                $total = $total + ($value1 + $value2);  
  80.                $footer = ($i != $Die_Count - 1) ? $footer . $total . '<b></b> + ' : $footer .  ($value1 + $value2) . '<b></b><br>';  
  81.             }  
  82.             else  
  83.             {  
  84.                $value = mt_rand(1,$Die_Type);  
  85.                $total = $total + $value;  
  86.                $footer = ($i != $Die_Count - 1) ? $footer . $value . ' + ' : $footer . $value . '';  
  87.             }  
  88.          }  
  89.       } // Loop limit  
  90.       else  
  91.       {  
  92.          $total = 0;  
  93.          $Modifier = 0;  
  94.          $footer = 'Too many dice and/or too many sides';  
  95.       }  
  96.  
  97.       switch( $Method )  
  98.       {  
  99.       case 1:  
  100.          $footer =  $footer . '<span style="color: #00AA00"> + ' . $Modifier . '</span><br>';  
  101.          $total = $total + $Modifier;  
  102.          break;  
  103.       case 2:  
  104.          $footer =  $footer . '<span style="color: #AA0000"> - ' . $Modifier . '</span><br>';  
  105.          $total = $total - $Modifier;  
  106.          break;  
  107.       case 3:  
  108.          $footer =  $footer . '<span style="color: #00AA00"> * ' . $Modifier . '</span><br>';  
  109.          $total = $total * $Modifier;  
  110.          break;  
  111.       case 4:  
  112.          $footer =  $footer . '<span style="color: #AA0000"> / ' . $Modifier . '</span><br>';  
  113.          $total = $total / $Modifier;  
  114.          break;  
  115.       }  
  116.       // I do b - /b on purpose...  kills out some smilies that crop up.  
  117.       if( ($Die_Count > 1) || ($Method != 0) )  
  118.       {  
  119.          $footer=  $footer . ' <b>Total =</b> ' . $total . '<b></b><BR>-*-*-';  
  120.       }  
  121.       else  
  122.       {  
  123.          $footer =  $footer . '<BR>-*-*-';  
  124.       }  
  125.       $footer = $footer. "";  
  126.       $results = $results . $header . $footer . '</div>';  
  127.  
  128.     // Restore MT randomness  
  129.        mt_srand($Future_Seed);  
  130.  
  131.                 
  132.             //list($usec,$sec)=explode(" ",microtime());    
  133.             mt_srand((double)microtime()*1000000);//$sec * $usec);    
  134.                 
  135.             // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades    
  136.                 mt_rand();  
  137.     
  138.             return array(    
  139.                 'valid'  => true,    
  140.                 'html'  => $results    
  141.                 );    
  142.         } 


Result of code [dice]2d6+3[/code]

Dice Rolled
You rolled 2 dices of 6 sides (2d6+3)
Partial Result: 6 + 4 + 3
Total: 13


Hope it's help
 



 
Yuri MenzlSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
Thanks for that.

I've implemented a random number generator in latest RC version, but the value it is not stored in the DB... I will hopefully do it in the future...

You can test it on this site.

This will generate a random number between 1 and 100.
Code: [Download] [Hide] [Select]
[random=100][/random]


23
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help On Dice BBCode! 
 
Yuri Menzl wrote: [View Post]
I finally fix the bug that always give the same result at rolled dices and add an increment value that can be +, -, * or /. I remakes the layout too.

WOW! This is a GREAT JOB!!  

I just ask you a big help... Would you be so kind by packing it all in a file with some instructions so that I can try to implement the MOD in my site?

I realize I'm asking a lot but it would help me a lot!

 
 



 
IntactoSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help On Dice BBCode! 
 
Done by myself!!
I repeat: A GREAT JOB!!! THANKS AGAIN!!!  
 



 
IntactoSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help On Dice BBCode! 
 
Hey guys!
I'm making a rpg forum with IP plataform and I need the dice bbcode... But, every time the topic page is reloaded the dice results change.
Somebody can help me with this?
Thanks for the help and sorry about the bad english... I'm brazilian.
 



 
altamirSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Help on Dice BBCode! 
 
What version of IcyPhoenix are you using?
 




____________
TheSteffen
Often SEARCH is the quickest way to get support.
IcyPhoenix German Support
 
TheSteffenSend private message  
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events