|
Page 1 of 1
|
Xusqui
Joined: August 2006
Posts: 211
Location: C?rdoba
|
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)
- 'fade' => array(
- 'nested' => true,
- 'inurl' => true,
- 'allow_empty' => false,
- ),
Right after add
- 'dice' => array(
- 'nested' => false,
- 'inurl' => false,
- 'allow_empty' => false,
- ),
Find
- // --- Disable Active Content Switch BEGIN ---
Right before add
- // BBcode dice, by Roland at ka-tet-corp.com. Based upon MOD-dice by >achary Aerogos (tribalgenesis at hotmail.com)
- if($tag === 'dice')
- {
- $Die = $content;
- $Expressions = explode('d', $content);
- if( (isset($Expressions[0])) && (isset($Expressions[1])) )
- {
- $dice_Rolls = $Expressions[0];
- $MT_Seed = (double)microtime()*1000000;//intval($Expressions[1]);
- }
- $Die_Count = $Expressions[0];
- $Die_Type = $Expressions[1];
- // 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 = '(' . $content . ') <b><span style="color: #AA0000"> Fixed</span></b>';
- $Die_Rolls = explode(' ', trim($dice_Rolls));
- $header = '<b>Sort of roll</b>: ' . $Die_Count . ' dices of ' . $Die_Type . ' sides ' . $Original_Roll_String . '<br /><b>' . $Die_Type . '-Result: </b>';
- $footer = '';
- $Die_Count = intval($Die_Count);
- if( $Die_Count == 0 ) $Die_Count = 1;
- $total = 0;
-
- // Loop Limit to prevent 500000d500000 sort of dices 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);
- $total = $total + ($value1 + $value2);
- $footer = ($i != $Die_Count - 1) ? $footer . $value1 . '+' . $value2 . '(' .($value1 + $value2) . '), ' : $footer . $value1 . '+' . $value2 . '(' . ($value1 + $value2) . ')';
- }
- else
- {
- $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1;
- $total = $total + $value;
- $footer = ($i != $Die_Count - 1) ? $footer . $value . ', ' : $footer . $value . '';
- }
- }
- } // Loop limit
- else
- {
- $total = 0;
- $footer = 'Too many dices and/or too many sides';
- }
- // I do b - /b on purpose... kills out some smilies that crop up.
- if( ($Die_Count > 1))
- {
- $footer= $footer . ' (<b>Total =</b> ' . $total . '<b></b>)<BR>';
- }
- else
- {
- $footer = $footer . '<BR>';
- }
- $footer = $footer. "";
- $results = $header . $footer;
-
- // Restore MT randomness
- mt_srand($Future_Seed);
-
- //list($usec,$sec)=explode(" ",microtime());
- mt_srand((double)microtime()*1000000);//$sec * $usec);
-
- // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades
- mt_rand();
-
- return array(
- 'valid' => true,
- 'html' => $results
- );
- }
To use it, you write:
x means number of dices to roll
yy means number of sides of each dice
i.e
To roll 2 dices of 10 sides.
But now comes the problem.
Because of this line:
- $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
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.
|
#1 Mon 18 Dec, 2006 22:01 |
|
Sponsors
|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
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
|
#2 Sun 24 Dec, 2006 20:50 |
|
Xusqui
Joined: August 2006
Posts: 211
Location: C?rdoba
|
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.
|
#3 Tue 09 Jan, 2007 11:57 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
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
|
#4 Wed 10 Jan, 2007 00:47 |
|
Intacto
Joined: October 2007
Posts: 4
|
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
|
#5 Sat 27 Oct, 2007 18:34 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
Re: Help on Dice BBCode!
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
|
#6 Thu 01 Nov, 2007 22:05 |
|
Yuri Menzl
Joined: August 2007
Posts: 6
|
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
- # // BBcode dice, by Roland at ka-tet-corp.com. Based upon MOD-dice by >achary Aerogos (tribalgenesis at otmail.com)
- if($tag === 'dice')
- {
- $Die = $content;
- $Expressions = explode('d', $content);
- if( (isset($Expressions[0])) && (isset($Expressions[1])) )
- {
- $dice_Rolls = $Expressions[0];
- $MT_Seed = (double)microtime()*1000000;//intval($Expressions[1]);
- }
- $Die_Count = $Expressions[0];
- $Die_Type = $Expressions[1];
- // 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 = '(' . $content . ') <b><span style="color: #AA0000"> Fixed</span></b>';
- $Die_Rolls = explode(' ', trim($dice_Rolls));
- $header = '<b>Sort of roll</b>: ' . $Die_Count . ' dices of ' . $Die_Type . ' sides ' . $Original_Roll_String . '<br /><b>' . $Die_Type . '-Result: </b>';
- $footer = '';
- $Die_Count = intval($Die_Count);
- if( $Die_Count == 0 ) $Die_Count = 1;
- $total = 0;
-
- // Loop Limit to prevent 500000d500000 sort of dices 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);
- $total = $total + ($value1 + $value2);
- $footer = ($i != $Die_Count - 1) ? $footer . $value1 . '+' . $value2 . '(' .($value1 + $value2) . '), ' : $footer . $value1 . '+' . $value2 . '(' . ($value1 + $value2) . ')';
- }
- else
- {
- $value = (integer)(((double)mt_rand()/(double)mt_getrandmax()) * $Die_Type) + 1;
- $total = $total + $value;
- $footer = ($i != $Die_Count - 1) ? $footer . $value . ', ' : $footer . $value . '';
- }
- }
- } // Loop limit
- else
- {
- $total = 0;
- $footer = 'Too many dices and/or too many sides';
- }
- // I do b - /b on purpose... kills out some smilies that crop up.
- if( ($Die_Count > 1))
- {
- $footer= $footer . ' (<b>Total =</b> ' . $total . '<b></b>)<BR>';
- }
- else
- {
- $footer = $footer . '<BR>';
- }
- $footer = $footer. "";
- $results = $header . $footer;
-
- // Restore MT randomness
- mt_srand($Future_Seed);
-
- //list($usec,$sec)=explode(" ",microtime());
- mt_srand((double)microtime()*1000000);//$sec * $usec);
-
- // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades
- mt_rand();
-
- return array(
- 'valid' => true,
- 'html' => $results
- );
- }
Replace
- // 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
- if($tag === 'dice')
- {
- $Die = $content;
- $Expressions = explode('d', $content);
- 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;
- }
- $Die_Count = $Expressions[0];
- $Die_Type = $Expressions[1];
-
- /*// 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 = '<b>(' . $content . ')</b>';
- $Die_Rolls = explode(' ', trim($Dice_Rolls));
-
- $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
- {
- $Method = 0;
- $Modifier = 0;
- }
-
- $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>';
- $footer = '';
- $Die_Count = intval($Die_Count);
- if( $Die_Count == 0 ) $Die_Count = 1;
- $total = 0;
-
- // 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 = mt_rand(1,9) * 10;
- $value2 = mt_rand(1,10);
- $total = $total + ($value1 + $value2);
- $footer = ($i != $Die_Count - 1) ? $footer . $total . '<b></b> + ' : $footer . ($value1 + $value2) . '<b></b><br>';
- }
- else
- {
- $value = mt_rand(1,$Die_Type);
- $total = $total + $value;
- $footer = ($i != $Die_Count - 1) ? $footer . $value . ' + ' : $footer . $value . '';
- }
- }
- } // Loop limit
- else
- {
- $total = 0;
- $Modifier = 0;
- $footer = 'Too many dice and/or too many sides';
- }
-
- switch( $Method )
- {
- case 1:
- $footer = $footer . '<span style="color: #00AA00"> + ' . $Modifier . '</span><br>';
- $total = $total + $Modifier;
- break;
- case 2:
- $footer = $footer . '<span style="color: #AA0000"> - ' . $Modifier . '</span><br>';
- $total = $total - $Modifier;
- break;
- case 3:
- $footer = $footer . '<span style="color: #00AA00"> * ' . $Modifier . '</span><br>';
- $total = $total * $Modifier;
- break;
- case 4:
- $footer = $footer . '<span style="color: #AA0000"> / ' . $Modifier . '</span><br>';
- $total = $total / $Modifier;
- 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 . '</div>';
-
- // Restore MT randomness
- mt_srand($Future_Seed);
-
-
- //list($usec,$sec)=explode(" ",microtime());
- mt_srand((double)microtime()*1000000);//$sec * $usec);
-
- // Loop to fix randomness problem of results when multiple die rolls are made in a single post - Hades
- mt_rand();
-
- return array(
- 'valid' => true,
- 'html' => $results
- );
- }
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
|
#7 Tue 27 Nov, 2007 02:13 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
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.
84
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#8 Wed 28 Nov, 2007 10:42 |
|
Intacto
Joined: October 2007
Posts: 4
|
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!
|
#9 Sat 29 Dec, 2007 20:56 |
|
Intacto
Joined: October 2007
Posts: 4
|
Re: Help On Dice BBCode!
Done by myself!!
I repeat: A GREAT JOB!!! THANKS AGAIN!!!
|
#10 Wed 02 Jan, 2008 17:32 |
|
altamir
Joined: February 2012
Posts: 1
|
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.
|
#11 Fri 03 Feb, 2012 12:01 |
|
TheSteffen
Joined: August 2006
Posts: 1625
Location: Magdeburg
|
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
|
#12 Thu 09 Feb, 2012 12:08 |
|
|
Page 1 of 1
|
Was this topic useful?
Was this topic useful?
Link this topic |
URL |
|
BBCode |
|
HTML |
|
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
|
|
|
|