vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Dice Roller Hack [BBCode] (https://vborg.vbsupport.ru/showthread.php?t=113972)

Eq4bits 05-26-2006 01:03 PM

Quote:

Originally Posted by Zowners
I'm still wrestling with the database.

how was ZIKI's problem solved? I don't know where to alter the database and alter it with what.

Do you actually have access to the database? Via something like phpMyAdmin? Where you can 'see' the database and alllll the tables that make it up?

As previously stated on the FIRST page the changes are not being made to the database when you install/import this product. You'll have to ALTER the
***_thread & ***_post yourself. Do the following:
  • ALTER the ****_thread table by ADDING a field named 'dice' the field should be MEDIUM TEXT and set at NOT NULL;
  • ALTER the ****_post table by ADDING a field named 'dice', athe field should be MEDIUMTEXT and set at NOT NULL;
Since I don't know what you named your database table prefixes I inserted asterisks prior to the _thread & _post table names. The attached images are screenshots showing the ****_post table of a database and indicatingwith the 'dice' field already added (image1a.png) , and an image (image1.png) is showing the properties of the dice field... which can be edited, dropped altogether or whatever. If you need help adding a field to the database I suggest reading over the help file for phpmyAdmin.

Eq4bits 05-26-2006 01:18 PM

also, as Eiikenskjaldi stated above he ported this product from it's original (written by someone else) that was for ver 3.0 so that it could be used for ver. 3.5.x the xml file
to add a button as Emma2 suggested would require more than this simple xml file/product. There is a hack somewhere for adding additional bbcode buttons to the editor. This is just a simple and easy way to be able to roll dice by typing the bbcode for it, just like adding an img tag or url tag when typing a post, it's NOT really that hard to type [dice=1]100[/dice] is it? Having 20 buttons for different dice rolls on the WYSIWYG editor could get a bit crowded anyway, don't you think? IF you were ONLY using, for your board a SINGLE predetermined number of die with a predetermined number of faces (i.e. only able to roll x number of die that have z number of faces) yes a button would be the thing to go with, but that wasn't the purpose of this hack.. You can always put a request for someone to write a hack that does this in the request forum, or pay someone to do it. I don't have all the know how to.

Eq4bits 05-26-2006 01:49 PM

Quote:

Originally Posted by Zowners
Where was the database with this code? I assume it's not one of the dice hack databases because I couldn't find them. Found the other two but not the above code

Zowner,
That is in the actual xml file and has to be changed prior to importing.

wherever you saved the xml file on your computer, open it using notepad or wordpad.. some type of equivalent editor. Then use 'Find' to seach and located the code, then change it
EDIT: hit submit too soon :eeps:
Then save the file and reimport, be sure to check 'Yes' to overwrite for the import process.
EDIT: :eeps: i must need more coffee i totally read and replied wrong, have fixed my reply now tho
ignore the attached image it has nothing to do with the section of code Zowner was asking about.
Edit: I definiately need more coffee or another brain... the image attached DOES have everything to do with this
all that code change in the xml file was change the 'wording' above the pics of the dice in the post
'dices' was not correct you would use either 'die' or 'dice' and it bugged me seeing 'dices' made me want to grab a knife and an onion... :D

Eq4bits 05-26-2006 03:08 PM

Quote:

Originally Posted by soravok
How long do you think it will be before there is a solid/stable version of this dice roller I like it a lot just a few too many minor bugs with it for the time being.

I'm putting in a 'code' section below a copy of the XML file I use on my board (please note '***' that is in front of '_thread' and '_post' should be the PREFIX all the tables in your database have)... except for making the alterations to the table this hack works FINE.

The changes I (as Rukbat at the time) made were for customizing it for MY board/forum (using up to 9 dice with up to 100 faces), and also changing the 'Dice roll with x dices of ** faces: *** points' phrase to 'Dice roll with x dice of ** faces: *** points' because 'dices' is not the plural and it bugged me.

So now....
################### INSTALL INSTRUCTIONS ################
1. Access the database you use for your forum
  • open the ***_thread table
    • ADD a field - make the field name 'dice' set it's properties to: 'mediumtext' and 'not null'
  • open the ***_post table
    • ADD a field - make the field name 'dice' set it's properties to: 'mediumtext' and 'not null'
2. Upload the images to ./images/dice in your main forum directory, you will need to create the dice folder. (the ZIP file attached below is Blue Dice 1-100.. you will have to download the zip file, extract it and upload all the images in it to the dice folder you created)

4. Copy and paste the below code into notepad (or other xml editor), change the '***' prefix for the tables to the prefix YOUR database has for all it's tables, then SAVE it as: Eikin-DiceRoller-1_0.xml (in notepad 'save' box be sure to have the file type set to 'all files' NOT as TEXT/TXT and the encoding as ANSI):
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="dice" active="1">
 <title>Dice Roller</title>
 <description>Rolls dice in postbit</description>
 <version>1.0</version>
 <codes>
  <code version="1.0">
  <installcode>ALTER TABLE `***_thread` ADD `dice` MEDIUMTEXT NOT NULL ;
ALTER TABLE '***_post' ADD 'dice' MEDIUMTEXT NOT NULL ;</installcode>
  <uninstallcode />
  </code>
 </codes>
 <templates>
  <template name="dice" templatetype="template" date="1145915902" username="admin" version="3.5.4"><![CDATA[<img src="images/dice/$point.gif" width="76" height="80" />]]></template>
  <template name="postbit_dice" templatetype="template" date="1145915990" username="admin" version="3.5.4"><![CDATA[<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">
<tr>
  <td><smallfont><b>Dice roll with $dicesno dice of $dicesfaces faces: $dicepoints points</b></smallfont></td>
</tr>
<tr>
  <td style="BORDER: #000000 1px solid; FONT-SIZE: 11px; COLOR: #000000; BACKGROUND-COLOR: #D7D7D7;">
$dicedata
</td>
</tr>
</table><br/>]]></template>
 </templates>
 <plugins>
  <plugin active="1">
  <title>dice_process_data</title>
  <hookname>newpost_process</hookname>
  <phpcode><![CDATA[// Hack
                if (@eregi("\[dice",$post['message']))
                {
                        $diceresult = array();
                        preg_match_all("/\[dice=([1-9])\]([0-9]?[0-9]?[0-9])\[\/dice\]/",$post['message'],$diceresult);
 
                        $dices = $diceresult[1];
                        $faces = $diceresult[2];
                        $dicedetail = array();
                        $rollcount = count($dices);
 
                        $validdice = 0;
                        for ($i = 0; $i < $rollcount; $i++)
                        {
                                if ($faces[$i] >= 2 && $faces[$i] <= 100)
                                {
                                        $diceresult[0][$i] = str_replace("[","\[",$diceresult[0][$i]);
                                        $diceresult[0][$i] = str_replace("]","\]",$diceresult[0][$i]);
                                        $diceresult[0][$i] = str_replace("/","\/",$diceresult[0][$i]);                                               
                                        $post['message'] = preg_replace("/".$diceresult[0][$i]."/","[dice".($validdice)."]",$post['message'],1);
 
                                        $dicedetail[$validdice]['dices'] = $dices[$i];
                                        $dicedetail[$validdice]['faces'] = $faces[$i];
                                        $dicedetail[$validdice]['data'] = array();
                                        for ($j = 0; $j < $dices[$i]; $j++)
                                        {
                                                $dicedetail[$validdice]['data'][] = rand(1,$faces[$i]);       
                                        }
                                        $validdice++;
                                }
                        }
 
                        if (!empty($dicedetail))
                        {
                                  $dataman->set('dice',serialize($dicedetail));
                        }
                }
                // End Hack]]></phpcode>
  </plugin>
  <plugin active="1">
  <title>dice_postbit_convert</title>
  <hookname>postbit_display_complete</hookname>
  <phpcode><![CDATA[// Hack: dice
 if ($post['dice'])
        {
        $dicearray = unserialize($post['dice']);
  $totalroll = count($dicearray);
 
  for ($i = 0; $i < $totalroll; $i++)
                {
  $dicedata = "";               
                $dicepoints = 0;
                $dicesno = $dicearray[$i]['dices'];
                $dicesfaces = $dicearray[$i]['faces'];
 
                foreach ($dicearray[$i]['data'] as $point)
                {
                        eval('$dicedata .= "' . fetch_template("dice") . '";');
                        $dicepoints += $point;                 
                }
                eval('$dice = "' . fetch_template("postbit_dice") . '";');
                $post['message'] = preg_replace("/\[dice$i\]/i","$dice",$post['message']);
                }
        }]]></phpcode>
  </plugin>
  <plugin active="1">
  <title>dice_set_valid_fields</title>
  <hookname>postdata_start</hookname>
  <phpcode><![CDATA[$this->validfields['dice'] = array(TYPE_STR, REQ_NO);]]></phpcode>
  </plugin>
  <plugin active="1">
  <title>dice_set_valid_fields_new_thread</title>
  <hookname>threadfpdata_start</hookname>
  <phpcode><![CDATA[$this->validfields['dice'] = array(TYPE_STR, REQ_NO);]]></phpcode>
  </plugin>
 </plugins>
 <phrases>
 </phrases>
 <options>
 </options>
</product>

3. Go into ACP and upload the XML through the product manager. BE SURE TO CHECK-OFF 'YES' for OVERWRITE.

4. Go to a forum and test the formatting (described below).

################# FORMATTING INFORMATION ################
To roll a dice use the following tag,
[dice=X]Y[/dice]
X - The number of dice to roll (This cannot be larger than 9 currently, I'm not a coding whiz and not sure how to fix this but I AM looking into it.)
Y - The number of sides on the dice (This cannot be larger than 100 currently, mainly because I don't feel like making more dice, but if YOU do feel free, just find in the xml file (again using notepadchange the ) the following
Code:

if ($faces[$i] >= 2 && $faces[$i] <= 100)
and change the '100' to however many you need it/want it to be, provided you have dice images up to and including that number.

so [dice=1]6[/dice] Roll's 1, 6 sided dice.

NOTE: Currently you CANNOT make a dice roll in the first post of a new thread, only in reply posts. I'm not a coding-whiz so I don't know how to fix it, but I'll try looking into it in the next couple of days and post another reply here.

The hack isn't buggy except for the table altering, as long as you go in and make those changes to the 2 tables yourself via phpMyAdmin (or whatever) it works fine.

Eq4bits 05-26-2006 03:15 PM

Quote:

Originally Posted by Emmy2
nice hack!

Is is possible to create a bbcode within a bbcode? Example, if I want to create a bb code called "roll" (and an accompanying button for it), and I want it to automatically roll 5 dice with 1-6 options, how can I do that? Theoretically this is what I want:

my member would type (or hit the roll button and get this): [roll][/roll]

but the code would execute as: [roll][dice=5]6[/dice][/roll]


Anyway to do that? The reason is...my members are low tech and having them input all the variables is too complex. Just want a simple roll button that they can click and it's all set up for them. Can do?

I'll look into this when I have time, but I'm not guaranteeing anything, so you essentially want a button for the WYSISYG editor that has the word 'Roll' on it (that's an image thing) that will ALWAYS roll the same number of die with the same number of faces, correct?

cclaerhout 05-26-2006 03:16 PM

I think the sql problem shoud be fixed with this new product file.

I'm still thinking the idea suggested above would be great. If each time you want to play dice you have to type the code, members are going to be upset. I'm going to look if i can do it. Anyway we can ask Michelle, the hacker of e-steki Smilie Maker 1.7 to help us ;)


Edit : file removed because update on next page.

cclaerhout 05-26-2006 03:18 PM

Quote:

Originally Posted by Eq4bits
I'll look into this when I have time, but I'm not guaranteeing anything, so you essentially want a button for the WYSISYG editor that has the word 'Roll' on it (that's an image thing) that will ALWAYS roll the same number of die with the same number of faces, correct?

My idea would be to create a collaspe menu with several choice of dice. Each time you click on of the icon, the bbcode will be insert in the message.

BeaLzeBuB 05-26-2006 03:38 PM

it doesn't show the dices.I imported it and it doesn't show the dices there is only [dice=1]6[/dice]

Eq4bits 05-26-2006 03:58 PM

Quote:

Originally Posted by cclaerhout
My idea would be to create a collaspe menu with several choice of dice. Each time you click on of the icon, the bbcode will be insert in the message.

That's a bit more complicated than my limited knowledge allows for, perhaps one of the 'whizzy' coders here could assist... if any are reading this thread....

Eq4bits 05-26-2006 04:18 PM

Quote:

Originally Posted by cclaerhout
I think the sql problem shoud be fixed with this new product file.

I'm still thinking the idea suggested above would be great. If each time you want to play dice you have to type the code, members are going to be upset. I'm going to look if i can do it. Anyway we can ask Michelle, the hacker of e-steki Smilie Maker 1.7 to help us ;)

I haven't had any problems with my users getting upset, they are just thrilled that they can roll dice and haven't had a problem rolling them... i posted instruction on how to do the bbcode and so far no problems... i made a thread for them to 'practice' on, lol

That would be great if Michelle could help, bribe her maybe???? lol

Looking at the xml version you attached it 'looks' like the code for altering the two tables should work (I was just looking at that part of the code and fixing to try to fix it... thanks for saving me the trouble), anyone try it yet?
A note tho... the 'dices' word is still there instead of 'die' or 'dice' so that would need to be changed if anyone else is as anal about that as I am :D
Another note your's is only for up to 5 dices of 30 faces each.

So anyone needing up to 9 dice would need to change
Code:

preg_match_all("/\[dice=([1-5])\]([0-9]?[0-9])\[\/dice\]/",$post['message'],$diceresult);
TO
Code:

preg_match_all("/\[dice=([1-9])\]([0-9]?[0-9]?[0-9])\[\/dice\]/",$post['message'],$diceresult);
and anyone wanting/needing more than 30 faces would need to change the '30' in
Code:

if ($faces[$i] >= 2 && $faces[$i] <= 30)
to the number of faces they choose (as long as they have images of dice up to and including the number they choose)


All times are GMT. The time now is 05:11 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01444 seconds
  • Memory Usage 1,805KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete