![]() |
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 .= ' |
I'd like to see a finished product, could be fun.
|
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"
|
"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. |
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)
|
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 :) |
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 |
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. |
Quote:
making sure people don't bug your function hehe |
So this is what you've been doing!
|
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. |
[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