LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 07-22-2011, 11:26 PM   #1
AdSuiteAdobe

Join Date
Oct 2005
Posts
351
Senior Member
Default A look into Crad's flawed plugin!
Spent about an hour rigging this up for Whatah. As it turns out, we can't even use it because we need the random numbers to remain constant for all users. Planning on revising it with a much trickier method

Figured someone might be interested in this.

Critique away!

[dice=5]20[/dice]

Output:
[dice=5]20[/dice]


Hook Location: bbcode_parse_start

Code:
Code
if (!function_exists('handle_dicetag')) {      srand((double) microtime() * 1000000);       function handle_dicetag(&$parser, $param, $option = '')      {          $numSides = 6;          $numDice = 1;           $htmlOut = ' rolls a ';           $paramVal = intVal($param, 10);          $optionVal = intval($option, 10);           if ($paramVal > 0 and $paramVal  0 and $optionVal  1)              $htmlOut .= ' on ' . $numDice . ' d' . $numSides . 's';          else              $htmlOut .= ' on a d' . $numSides;           $htmlOut .= '
';           return $htmlOut;      }  }  $this->tag_list['no_option']['dice'] = array(          'callback' => 'handle_external',          'strip_empty' => false,          'stop_parse' => false,          'disable_smilies' => true,          'disable_wordwrap' => true,          'strip_space_after' => 1,          'external_callback' => 'handle_dicetag'  );   $this->tag_list['option']['dice'] = array(          'callback' => 'handle_external',          'strip_empty' => false,          'stop_parse' => false,          'disable_smilies' => false,          'disable_wordwrap' => true,          'strip_space_after' => 1,          'external_callback' => 'handle_dicetag'  );

AdSuiteAdobe is offline


Old 07-22-2011, 11:28 PM   #2
Fiipolera

Join Date
Oct 2005
Posts
429
Senior Member
Default
I'd like to see a finished product, could be fun.
Fiipolera is offline


Old 07-22-2011, 11:39 PM   #3
Fouttysotlalf

Join Date
Oct 2005
Posts
549
Senior Member
Default
yea as i understand it the numbers change when the page is parced so they do not stay the same forever. right now i see the numbers "2, 9, 17, 17, 4"
Fouttysotlalf is offline


Old 07-22-2011, 11:42 PM   #4
AgindyMinnife

Join Date
Oct 2005
Posts
392
Senior Member
Default
"8, 8, 11, 20, 12" here. But that will change as soon as I post.

Therein lies the problem; we need to either store the results or preferably just store a seed for the random number on a per-tag basis.
AgindyMinnife is offline


Old 07-23-2011, 12:01 AM   #5
wmirkru

Join Date
Oct 2005
Posts
528
Senior Member
Default
Looks nice and simple (as far as I can tell, I'm not exactly fluent in BBcode. Mabye I should pick up something to learn), though I wonder why you don't like it reading 1 d20s :P (or whatever your $numSides var is set to lol)
wmirkru is offline


Old 07-23-2011, 12:20 AM   #6
Britfunclubs

Join Date
Oct 2005
Posts
361
Senior Member
Default
Hm? The only restrictions I put for the inputs are:

#dice: between 1 and 12.
#sides: between 1 and 256.

Also, it's PHP. BBCode is just the name of the identifiers used by the parser to determine what effects to apply.

Info Crad actually despises PHP. It's a messy language with weak (non-explicit) typing; and therein lies the road to madness.

EDIT:

Oh! That's just a bit of formatting.

If you only have 1 di, it prints out "a d20" instead of "1 d20's". I figured Jedah would murder me if I didn't do that
Britfunclubs is offline


Old 07-23-2011, 10:01 AM   #7
dXI9XFOA

Join Date
Oct 2005
Posts
562
Senior Member
Default
So if it's now 4; 16; 1; 17; 2

It will change as soon as I post?

---------- Post added at 09:01 AM ---------- Previous post was at 08:55 AM ----------

Code: [code]$paramVal = intVal($param, 10); $optionVal = intval($option, 10); if ($paramVal > 0 and $paramVal 0 and $optionVal
dXI9XFOA is offline


Old 07-23-2011, 05:00 PM   #8
JohnfAclambrJA

Join Date
Oct 2005
Posts
457
Senior Member
Default
The first two lines are because I don't trust weak typing. I'm explicitly telling it to convert the string values, read in as a base-10 number, to an integer.

The rest is me just making sure players don't do anything ludicrous, like display -6 d203949032 dice.
JohnfAclambrJA is offline


Old 07-23-2011, 07:32 PM   #9
JulietOreira

Join Date
Oct 2005
Posts
584
Senior Member
Default
The first two lines are because I don't trust weak typing. I'm explicitly telling it to convert the string values, read in as a base-10 number, to an integer.

The rest is me just making sure players don't do anything ludicrous, like display -6 d203949032 dice.
ahhhh

making sure people don't bug your function hehe
JulietOreira is offline


Old 07-23-2011, 08:13 PM   #10
santorio

Join Date
Oct 2005
Posts
470
Senior Member
Default
So this is what you've been doing!
santorio is offline


Old 07-23-2011, 08:40 PM   #11
Ocqljudq

Join Date
Oct 2005
Posts
348
Senior Member
Default
Format is being changed slightly

[dice]20|20|6|6|20[/dice]

Would roll 5 dice: 2 d20's, 2 d6's, and another d20. The reason for this is I'm reserving the option value of the bbcode for a generated random number seed, to ensure that the number remains constant.

For example:

You post: [dice]20[/dice]

On submitting, the post is parsed for any instances of "[dice"; if they don't immediately follow by "=" and a number, the tag will be modifed to use the current server-time in milliseconds as a random number seed.

So it becomes: [dice=12098503123304]20[/dice]

If you're not familiar with random numbers, a seed is a value passed to a pseudo-random number generator that it uses to create random numbers. Two identical seeds will generate the same random numbers.

This will also allow you to grab various sets of values by simply reproducing the tag.
Ocqljudq is offline


Old 07-24-2011, 04:02 AM   #12
gkihueonhjh

Join Date
Oct 2005
Posts
407
Senior Member
Default
[dice]20|20|20|12|4[/dice]

[dice]20|20|20|12|4[/dice]

---------- Post added at 09:02 PM ---------- Previous post was at 09:01 PM ----------

so atm it is only rolling 1 die, not multiple?
gkihueonhjh is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 05:22 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity