Logo

Goto Bottom


Latest Shouts In The Shoutbox -- View The Shoutbox · Rules   


  Add ReplyMake New TopicStart Poll

» Dice Rolling System
yavona
 Posted: Jul 11 2018, 03:37 PM
Quote Post


Newbie
 *

Group: Members
Posts: 1
Member No.: 85
Joined: 11-July 18









hi. im from a pokemon rp on zetaboards and we use this dice system: http://support.zathyus.com/topic/5079712/1/ as a form of orchestrating our pokemon battles. we are moving to jcink and we're wondering how to convert said feature to jcink. we use rolls such as [/roll]1d2[/roll] [/roll]1d10[/roll] and [/roll]2d6[/roll], so if you're able to help us recode it to fit jcink standards, it'd be appreciated

dice roll: http://support.zathyus.com/topic/5079712/1/

our current forum: http://s15.zetaboards.com/Pokemon_Roleplay/index/
forum we're moving to: https://thepokemonroleplay.jcink.net/index.php?
PM
^
Cory
 Posted: Jul 12 2018, 12:18 AM
Quote Post


Administrator
 *  *  *  *  *  *

Group: Admin
Posts: 393
Member No.: 1
Joined: 4-June 18









Try this:

CODE
<script>
/* Dice Rolling Script (v3.1)
by Reid of ZNR (resources.zetaboards.com)
Feel free to edit/redistribute */

(function () {
   var dr = {
       roll_dice: function (sides, times) {
           var result = [], result_num = 0, result_holder;
           while (times--) {
               result_holder = Math.ceil(Math.random() * sides);
               result_num += result_holder;
               result[result.length] = result_holder;
           }
           return [result_num, result];
       },

       regex: /\[result\](\d+&amp;[d:\d,|]+&amp;[d\d+]+)\[\/result\]/gi,
       old_regex: /\[result=([d\d+]+)\](\d+)\[\/result\]/gi,

       // Intended to be used as an event handler
       update_post: function (event_handler) {
           // Malformed post checker
           var somebody_set_up_the_bomb = false,
               t = $('textarea[name=Post]')[0];

           if (dr.regex.test(t.value) && !$('#admin-link').length) {
               $("<p id='cheat'>Please do not attempt to cheat.</p>").hide().insertBefore(t).fadeIn();
               return false;
           } else if (!dr.regex.test(t.value) && $('#cheat').length) {
               $('#cheat').fadeOut(function () {
                   $(this).remove();
               });
           }

           $('#malformed').remove();

           t.value = t.value.replace(/\[roll\](.+?)\[\/roll\]/gi, function (total, to_roll) {
               var tr = to_roll.toLowerCase().replace(/ /g, "").split('+'),
                   result = [], result_num = 0, result_holder, i, k, c, excess_holder;

               if (/[^d+\d]|([+d])\1/.test(to_roll)) {
                   $('#malformed').remove();
                   $("<p id='malformed' style='display: none'>You appear to have a malformed roll. Please correct it and try again.</p>").insertBefore(t).fadeIn();
                   somebody_set_up_the_bomb = true;
                   event_handler.preventDefault ? event_handler.preventDefault() : event_handler.returnValue = false;
                   return total;
               }

               for (i = 0, k = tr.length; i < k; i++) {
                   if (tr[i].indexOf('d') === -1) continue;

                   c = tr[i].split('d');

                   excess_holder = tr[i + 1] && tr[i + 1].indexOf('d') === -1 ? +tr[i + 1] : 0;

                   result_holder = dr.roll_dice(+c[1], +(c[0] || 1));
                   result_num += result_holder[0] + excess_holder;
                   result[result.length] = [result_holder[1].join(':'), tr[i], excess_holder, result_holder[0] + excess_holder].join();
               }

               return "[result]" + result_num + "&" + result.join("|") + "&" + to_roll + "[/result]";
           });


           // Malformed roll check
           if (somebody_set_up_the_bomb) {
               t.value = t.value.replace(dr.regex, "[roll]$1[/roll]");
           }
       },

       insert_roll: function () {
           $('textarea[name=Post]').val(function (i, v) {
               return v + '[roll]' + prompt("Type the roll you which to use\n(Format: [num]d[sides]+[extra(opt.)])") + '[/roll]';
           });
       },

       // Used as an event handler
       // 'this' is the span result clicked
       roll_display: function () {
           var information = $(this).next().html().split('%'),
               dice_used = information[1].split('|'),
               i, k, tmp, each_die, excess,
               formatted = ["Original dice used: " + information[0] + "\n\nDissected rolls:"];

           for (i = 0, k = dice_used.length; i < k; i++) {
               tmp = dice_used[i].split(',');
               each_die = tmp[0].split(':');
               excess = tmp[2] !== '0' ? " (+" + tmp[2] + ")" : "";
               formatted[formatted.length] = tmp[1] + excess + (each_die.length > 1 ? "  => " + each_die.join(' + ') + excess : "") + "  => " + tmp[3];
           }

           formatted[formatted.length] = ["\nResult: " + information[2]];
           alert(formatted.join("\n"));
       }
   };

   if (location.href.indexOf('act=Post') !== -1) {
       $('form:has(textarea[name=Post])').submit(dr.update_post);
       $("<input type='button' id='d_roll' value='ROLL' />").insertAfter('#bbcode-buttons input:last').click(dr.insert_roll);
   } else if (/showtopic/.test(location.href)) {
       $('div.postcolor').each(function () {
           if (dr.regex.test(this.innerHTML)) {
               this.innerHTML = this.innerHTML.replace(dr.regex, function (t, result) {
                   // t[0] should be the result in number format
                   // t[1] should be the dice used to roll and their results, separated by |
                   // t[2] should be the entire dice used
                   var t = result.split(/&(?:amp;)?/);
                   return "<span style='cursor: pointer; border-bottom: 1px dotted gray' title='Dice used to roll: " + t[2] + "; click for details' class='roll_results'>" + t[0] + "</span><span style='display: none'>" + t[2] + "%" + t[1] + "%" + t[0] + "</span>";
               });

               // Remove edit button unless admin
               if (!$('#admin-link').length) {
                   $(this).parents('tr').prev().find('a[href*=Post&CODE=08]').remove();
               }
           }

           // Support old result format (yuck)
           if (dr.old_regex.test(this.innerHTML)) {
               this.innerHTML = this.innerHTML.replace(dr.old_regex, "<a href='javascript:;' class='old_roll_results'>$2</a><div style='display:none'>$1</div>");
               if (!$('#admin-link').length) {
                   $(this).parents('tr').prev().find('a[href*=Post&CODE=08]').remove();
               }
           }
       });

       // Bind the results function
       $('span.roll_results').click(dr.roll_display);
       $('a.old_roll_results').click(function () {
           alert("Rolled with: " + $(this).next().text());
       });
       $('form:has(textarea[name=Post])').submit(dr.update_post);
   }
}());
</script>
PM
^
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Add ReplyMake New TopicStart Poll


 


 


Goto Top