Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 873
0 Users 11 Guests Online
Forum Index » PHP + MySQL » [REQ] BBCode to forum
Posted on Saturday 3rd January 2009 at 10:47 PM
zerocool
templates/default/images/noavatar.png's Avatar
Newbie
Hi people, I wanna add a custom BBCode to the chat, but i havn't idea how to do it.

The code is [dice]XdY[/dice]
the X was the number of rands and the Y the max number.
how i could do this?

and another code is [dice=Motive]XdY[/dice]
the X and Y is the same as the other code, but the Motive is a text.

it will shown in a box with the infos.

Thanx to all and sorry for my badly English :P
Posted on Wednesday 7th January 200 at 09:48 PM
zerocool
templates/default/images/noavatar.png's Avatar
Newbie
No one can take a look at my post?
Posted on Wednesday 7th January 200 at 10:43 PM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
What do you want it exactly to do? Find a number? I'm talking about the regular [dice] [/dice] one Btw :P
Posted on Wednesday 7th January 200 at 10:56 PM
zerocool
templates/default/images/noavatar.png's Avatar
Newbie
mm yes, but a rpg dice roller, with diferent dice sides, like 4 sided dice, 6, 8, 10, etc
then it will done a rand or somthing, and put the result in the database

and the second code, with the coment to show a little coment on the forum
like

Mod-Shadow rolled a 4 sided dice and get 3. I rolled for pass the door
Posted on Wednesday 7th January 200 at 10:59 PM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
Alright, I have made something like that but it's including the message in which I put before [dice] So I'll go try and make it only do the calculations then post it up on here ;D
Posted on Wednesday 7th January 200 at 11:11 PM
zerocool
templates/default/images/noavatar.png's Avatar
Newbie
ok, thaks Shadow
Posted on Thursday 8th January 2009 at 01:20 AM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
Alright I got them both working now :)
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
function doDice($text){
$search "/^(.*?)\[dice\]\s*(\d+)\s*d\s*(\d+)\s*\[\/dice\]/i";
$search2 "/^(.*?)\[dice=(.*?)\]\s*(\d+)\s*d\s*(\d+)\s*\[\/dice\]/i";
$text str_replace(""""$text);

$countText strlen($text);
$original substr($text0, ($countText 17));
if(
preg_match($search$text$things)) {
  return 
rolldice($things[2], $things[3], $things[1]);
}elseif(
preg_match($search2$text$things)){
  return 
rolldice($things[3], $things[4], $things[1], $things[2]);
}
}
function 
rolldice($dice$sides$originalText null$motive null)
{
   
$total 0;
   
$temp '';
   for (
$i=1$i <= $dice$i++)
   {
      
$dv rand(1$sides);
      
$total $total $dv;
   }
   
$temp .= 'total: ' $total;
if(
$motive != null){
   return 
"$originalTextRolling $dice dice with $sides sides &lt;$motive&gt;...Total Value: $total";
}else{
   return 
"$originalTextRolling $dice dice with $sides sides...Total Value: $total";
}

}
$test doDice("This would be a regular post, and then the original text for the rolldice function [dice=My 

Motive]1d1000[/dice]"
);
print 
$test;
?>
Posted on Thursday 8th January 2009 at 03:25 PM
zerocool
templates/default/images/noavatar.png's Avatar
Newbie
ok thanx Shadow but in this code
PHP Code
1
2
3
4
5
6
if($motive != null){
   return "$originalTextRolling $dice dice with $sides sides &lt;$motive&gt;...Total Value: $total";
}else{
   return "$originalTextRolling $dice dice with $sides sides...Total Value: $total";
}

you may change the $originalTextRolling to $originalText
Posted on Thursday 8th January 2009 at 04:05 PM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
Replace the $originalTexTRolling with $originalText<br />Rolling I made a type. ALso, anywhere where it has $temp remove it. also where I have $text = str_replace("","", $text); and $countText = strlen($text); and $original = substr($text, 0, stuff delete it. I forgot to clean up the code =P

This code could also be shortened a ton with single line if statements for the motive. ;D