DiscussWorldIssues - Socio-Economic Religion and Political Uncensored Debate

DiscussWorldIssues - Socio-Economic Religion and Political Uncensored Debate (http://www.discussworldissues.com/forums/)
-   General Discussion (http://www.discussworldissues.com/forums/general-discussion/)
-   -   A look into Crad's flawed plugin! (http://www.discussworldissues.com/forums/general-discussion/141088-look-into-crads-flawed-plugin.html)

AdSuiteAdobe 07-22-2011 11:26 PM

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 = 'http://www.discussworldissues.com/fo.../dice/dice.png 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'  );


Fiipolera 07-22-2011 11:28 PM

I'd like to see a finished product, could be fun.

Fouttysotlalf 07-22-2011 11:39 PM

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"

AgindyMinnife 07-22-2011 11:42 PM

"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.

wmirkru 07-23-2011 12:01 AM

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)

Britfunclubs 07-23-2011 12:20 AM

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.

http://www.discussworldissues.com/fo.../icon-info.png 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 :)

dXI9XFOA 07-23-2011 10:01 AM

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

JohnfAclambrJA 07-23-2011 05:00 PM

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.

JulietOreira 07-23-2011 07:32 PM

Quote:

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

santorio 07-23-2011 08:13 PM

So this is what you've been doing!

Ocqljudq 07-23-2011 08:40 PM

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.

gkihueonhjh 07-24-2011 04:02 AM

[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?


All times are GMT +1. The time now is 05:01 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2