View Single Post
  #1  
Old 04-08-2006, 06:48 AM
OrangeFlea OrangeFlea is offline
 
Join Date: Aug 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Still waiting: DICE HACK

There have been requests made for this one, but no brave coder has taken up the call.

There is a dice hack available for 3.5 but it is far too limited. I, along with some other people, were hoping for a dice hack that could roll up to (perhaps beyond) a 20-sided die.

For example:

[DICE]2d20[/DICE] ------> Two 20-sided dice (e.g. first die = 16; second die = 12)

[DICE]4d6[/DICE] -------> Four 6-sided dice (e.g., first die = 2; second die = 1; third die = 6; fourth die = 4)

This would be an excellent tool for games and for contests (random drawings, etc.)

If conditions need to be made, I'm willing to hear them out (PM me). Come on, let's get this thing going --- there's a demand for it.



************************************************** *******



Here's the dice code portion of the functions_bbcodeparse file that was originally in my Vbulletin 3.0.3, now no longer working for 3.5.4. Someone should be able to convert this into 3.5.4 format


Code:
	// [DICE]
	$bbcodes['custom']['find']['[dice]'] = '#\[dice\](<br>|<br />|\r\n|\n|\r)??(.*)(<br>|<br />|\r\n|\n|\r)??\[/dice\]#esiU';
	$bbcodes['custom']['replace']['[dice]'] = "handle_bbcode_dice('\\2')";
	$bbcodes['custom']['recurse']['dice'][0] = array('handler' => 'handle_bbcode_dice');

// fastjack
function handle_bbcode_dice($msg){
global $_SERVER;

	$d = explode(" ",$msg);
	foreach($d as $e){
		$r .= "<b>Request</b>: $e<br>";
		$r .= "<b>Result</b>: ";
		$e = strtolower($e);
		$e = trim($e);
		$e = str_replace("(","",$e);
		$e = str_replace(")","",$e);
		$e = str_replace("[","",$e);
		$e = str_replace("]","",$e);
		$e = str_replace("/","",$e);
		$e = str_replace("*","",$e);
		$e = explode("d",$e);
		unset($add);
		if(strpos($e[1],'+') !== false ){
			list($e[1], $e[2]) = explode("+",$e[1]);
			$add = 1;
		}
		if(strpos($e[1],'-') !== false ){
			list($e[1], $e[2]) = explode("-",$e[1]);
			$add = 2;
		}
		$f = 0;
		unset($error);
		if($e[1] != 2 && $e[1] != 3 && $e[1] != 4 && $e[1] != 6 && $e[1] != 8 && $e[1] != 10 && $e[1] != 12 && $e[1] != 20 && $e[1] != 100 && $e[1] != 1000  ){
			$r .= "You may only roll a 2, 4, 6, 8, 10, 12, 20, 100, or 1000-sided die. Please roll again";
			$e[1] = 100;
			$error = 1;
		}
		if(($e[0] > 100 || strlen($e[0]) > 3) && $error != 1){
			$r .= "We just support 100 dices each time. ";
			$e[0] = 1;
			$error =1;
		}
		if($add && (!is_numeric($e[2]) || $e[2] > 1000)){
			$r .= "You can just add or subtract numbers smaller than 1000.";
			$e[2] = 1;
			$error =1;
		}
		unset($g);
		if($error !=1){
		while($f != $e[0]){
			$g[] = rand(1,$e[1]);
			$r .= $g[$f].". ";
			$f++;
		}
		$r .= "<b>Total</b>: ".array_sum($g);
		if($add == 1){
			$t = (array_sum($g) + $e[2]);
			$r .= "+ ".$e[2]." = $t";
		}
		if($add == 2){
			$t = array_sum($g) - $e[2];
			$r .= "- ".$e[2]." = $t";
		}

		}
		$r .="<br>";
		
	}

//	$msg = $m[0].strstr($msg,'[/dice]');
//	$msg = str_replace('[/dice]','',$msg);

	$result[] = $msg;
	$result[] = $r;
	if($_SERVER['SCRIPT_NAME'] == "/forum/newreply.php")
		$r = "You cant have dice Preview";
	if($_SERVER['SCRIPT_NAME'] == "/forum/newthread.php")
		$r = "You cant have dice preview";
	$return = '<br><div class="smallfont" style="margin-bottom:2px"><img src=dice.gif> Diceroll:</div>
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="alt2" style="border:1px inset">
<div style="font-style:italic">'.$r.'</div>
</td>
</tr>
</table><br>';
	return $return;
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01149 seconds
  • Memory Usage 1,783KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete