[REQ] BBCode to forum

Posted on Saturday 3rd January 2009 at 10:47 PM
zerocool
zerocool's Avatar
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 2009 at 09:48 PM
zerocool
zerocool's Avatar
No one can take a look at my post?
Posted on Wednesday 7th January 2009 at 10:43 PM
ShadowMage
ShadowMage's Avatar
What do you want it exactly to do? Find a number? I'm talking about the regular [dice] [/dice] one Btw :P
failure i sense
Posted on Wednesday 7th January 2009 at 10:56 PM
zerocool
zerocool's Avatar
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 2009 at 10:59 PM
ShadowMage
ShadowMage's Avatar
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
failure i sense
Posted on Wednesday 7th January 2009 at 11:11 PM
zerocool
zerocool's Avatar
ok, thaks Shadow
Posted on Thursday 8th January 2009 at 01:20 AM
ShadowMage
ShadowMage's Avatar
Alright I got them both working now :)
PHP Code
  1. <?php
  2. function doDice($text){
  3. $search = "/^(.*?)[dice]s*(d+)s*ds*(d+)s*[/dice]/i";
  4. $search2 = "/^(.*?)[dice=(.*?)]s*(d+)s*ds*(d+)s*[/dice]/i";
  5. $text = str_replace("", "", $text);
  6.  
  7. $countText = strlen($text);
  8. $original = substr($text, 0, ($countText - 17));
  9. if(preg_match($search, $text, $things)) {
  10. return rolldice($things[2], $things[3], $things[1]);
  11. }elseif(preg_match($search2, $text, $things)){
  12. return rolldice($things[3], $things[4], $things[1], $things[2]);
  13. }
  14. }
  15. function rolldice($dice, $sides, $originalText = null, $motive = null)
  16. {
  17. $total = 0;
  18. $temp = '';
  19. for ($i=1; $i <= $dice; $i++)
  20. {
  21. $dv = rand(1, $sides);
  22. $total = $total + $dv;
  23. }
  24. $temp .= 'total: ' . $total;
  25. if($motive != null){
  26. return "$originalTextRolling $dice dice with $sides sides &lt;$motive&gt;...Total Value: $total";
  27. }else{
  28. return "$originalTextRolling $dice dice with $sides sides...Total Value: $total";
  29. }
  30.  
  31. }
  32. $test = doDice("This would be a regular post, and then the original text for the rolldice function [dice=My
  33.  
  34. Motive]1d1000[/dice]");
  35. print $test;
  36. ?>
failure i sense
Posted on Thursday 8th January 2009 at 03:25 PM
zerocool
zerocool's Avatar
ok thanx Shadow but in this code
PHP Code
  1. if($motive != null){
  2. return "$originalTextRolling $dice dice with $sides sides &lt;$motive&gt;...Total Value: $total";
  3. }else{
  4. return "$originalTextRolling $dice dice with $sides sides...Total Value: $total";
  5. }

you may change the $originalTextRolling to $originalText
Posted on Thursday 8th January 2009 at 04:05 PM
ShadowMage
ShadowMage's Avatar
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
failure i sense
Login or register to respond to this forum topic.