Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2016, 06:20 PM
kerrghann's Avatar
kerrghann kerrghann is offline
 
Join Date: Jul 2012
Location: Hawaii
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Javascript dice roller in bbcode

I'm attempting to make a javascript based dice roller inside of a bbcode.

Issue is that I'd like it to be [roll]{param1}d{param2}[/roll] and I'm pretty sure that isn't possible.

Am I barking up the wrong tree trying to do it this way? And if so, does anyone have advice on a better way to do this?
Reply With Quote
  #2  
Old 05-26-2016, 06:32 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you looked at:

Dice Roller [BBCode] ?
Reply With Quote
  #3  
Old 05-26-2016, 07:26 PM
kerrghann's Avatar
kerrghann kerrghann is offline
 
Join Date: Jul 2012
Location: Hawaii
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did. Oddly enough I can't even get it to install on 4.2.3

That it doesn't even make the database changes in threads and posts like it's suppose to, it just kind of stops after you upload it.
Reply With Quote
  #4  
Old 05-26-2016, 09:18 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What kind of behavior are you looking for exactly? Are you looking for something static (the dice are "rolled" and the values stored in the database upon submitting the post), and remains fixed thereafter, or something that rolls the dice each time the page is loaded, with different results, or even something that can be clicked (an unlimited number of times) once the page is loaded?
Reply With Quote
  #5  
Old 05-26-2016, 10:19 PM
kerrghann's Avatar
kerrghann kerrghann is offline
 
Join Date: Jul 2012
Location: Hawaii
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm looking for something static, for sure.
Reply With Quote
  #6  
Old 05-26-2016, 11:05 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kerrghann View Post
I'm looking for something static, for sure.
In order for it to be static, you could use PHP, and parse the post either on preview or submitting the post (whichever happens first) to change pre-defined text into the dice roll before the post is saved to the db. You could choose to have the parsing only take place when the post is submitted, and skip the preview, allowing the tags or whatever code you define to be a dice roll remain until the post is actually submitted. My choice would be to parse the post in both places.

I do something similar in a couple of my products.

Let me know the parameters you want (number of dice, number of faces on each die, etc.) and I will see what I can come up with.
Reply With Quote
  #7  
Old 05-27-2016, 12:02 AM
kerrghann's Avatar
kerrghann kerrghann is offline
 
Join Date: Jul 2012
Location: Hawaii
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd really appreciate it. I was thinking of allowing something like xdy+z where x is the number of dice being thrown, y is the number of sides on the dice, and z is the modifier being applied to the dice. So if a member where to use [roll]3d10+2[/roll] it would roll three ten sided dice and add 2 to whatever the total was.

I'd appreciate any help I can get, but I really don't want to make you go out of your way: I do appreciate it though.
Reply With Quote
  #8  
Old 05-27-2016, 12:10 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kerrghann View Post
I'd really appreciate it. I was thinking of allowing something like xdy+z where x is the number of dice being thrown, y is the number of sides on the dice, and z is the modifier being applied to the dice. So if a member where to use [roll]3d10+2[/roll] it would roll three ten sided dice and add 2 to whatever the total was.

I'd appreciate any help I can get, but I really don't want to make you go out of your way: I do appreciate it though.
So, you would only need to display the sum of the faces and the modifier? To use you example, suppose a user posted [roll]3d10+2[/roll] and one die was 4, the second 7 and the third 2, then 15 would be displayed? Or would you want to see the number of faces, the individual dice, the modifier and the sum all neatly displayed in a box or tabular format?
Reply With Quote
  #9  
Old 05-27-2016, 12:18 AM
kerrghann's Avatar
kerrghann kerrghann is offline
 
Join Date: Jul 2012
Location: Hawaii
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, having them all in a nice box as 4,7,2 (+2) = 15 would be nice, having any number show up would be ideal. To be honest, I'd take whatever you feel would be best in this situation.
Reply With Quote
  #10  
Old 05-28-2016, 01:46 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, create a plugin hooked at "newpost_process" with the "Plugin PHP Code":

PHP Code:
$text $post['message'];
preg_match_all('/\[roll\](.*?)\[\/roll\]/i'$text$match);

foreach (
$match[0] AS $roll)
{
    
$row1 '';
    
$row2 '';
    
$rolltext strtolower(preg_replace('/\[roll\](.*?)\[\/roll\]/''$1'$roll));
    
$rt_parse explode('d'$rolltext);
    
$dice intval($rt_parse[0]);
    
preg_match('~[^0-9]~i'$rt_parse[1], $signposPREG_OFFSET_CAPTURE);
    
$sign substr($rt_parse[1], $signpos[0][1], 1);
    
$fm_parse explode($sign$rt_parse[1]);
    
$faces intval($fm_parse[0]);

    if (
$sign == '+')
    {
        
$mod intval($fm_parse[1]);
    }
    elseif (
$sign == '-')
    {
        
$mod = -intval($fm_parse[1]);
    }

    
$dsum 0;

    for (
$m 0$m $dice$m++)
    {
        
$d mt_rand(1$faces);
        
$dsum += $d;
        
$dnum $m 1;
        
$row1 .= '[TD] Die ' $dnum ' [/TD]';
        
$row2 .= '[TD]' $d '[/TD]';
    }

    
$dsum += $mod;
    
$row1 '[TR]' $row1 '[TD]Modifier[/TD][TD]Sum[/TD][/TR]';
    
$row2 '[TR]' $row2 '[TD]' $mod '[/TD][TD]' $dsum '[/TD][/TR]';
    
$replace '[TABLE="class: grid"]' $row1 $row2 '[/TABLE]';
    
$text str_replace($roll$replace$text);
}

$post['message'] = $text
Reply With Quote
Благодарность от:
kerrghann
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:50 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06715 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete