Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Mistborn RPG Dice Roller Script

I'm trying to make a dice roller specific to the Mistborn Adventure Game system, but I am a newbie to the Roll20 scripts. Here is what it needs to do: Roll a number of d6s (anywhere between 2 and 10 dice) determined by the player Every six that is rolled is a "nudge" The highest rolled pair is the result of the roll So if a player rolls five dice and rolls 1, 3, 3, 5, 6, then the roll has a result of 3 with one nudge. A roll of 1, 1, 1, 4, 4 has a result of 4 and no nudges. I have already written my code in JavaScript, but I have no idea if it could be modified to be incorporated into the Roll20 API. Here is my code: //dice roller function var diceRoller = function(numberOfDice){      //declaring variables   var results1 = 0;   var results2 = 0;   var results3 = 0;   var results4 = 0;   var results5 = 0;   var results6 = 0;   var result = 0;   var loop = (1*numberOfDice)+1;      //roll each die individually until all dice are rolled   for (i=1; i<loop; i++){     var roll = Math.ceil(6*Math.random());          //add each die result to the number of occurrences of that result     if (roll == 1) {       results1 += 1;     }     else if (roll == 2) {       results2 += 1;     }     else if (roll == 3) {       results3 += 1;     }     else if (roll == 4) {       results4 += 1;     }     else if (roll == 5) {       results5 += 1;     }     else {       results6 += 1;     }//end of if/else statements         }//end of 'for' loop      //highest number <6 with at least 2 occurrences is the result   if (results5 > 1) {       result = 5;     }     else if (results4 > 1) {       result = 4;     }     else if (results3 > 1) {       result = 3;     }     else if (results2 > 1) {       result = 2;     }     else if (results1 > 1) {       result = 1;     }     else {       result = 0;     };      //user is told the result and how many nudges(6s) they got   var response = "You got a result of " + result + " and " + results6 + " nudges!"   return response; }; //end of dice Roller function //DOM variables var numberOfDice=document.getElementById("numberOfDice"); var rollResult=document.getElementById("rollResult"); //function activated when button is clicked var rollDice = function() {   var dice = numberOfDice.value;   answer = diceRoller(dice);   rollResult.innerHTML = answer; }; I know I can't use IDs in my script, but other than that, I don't see how this could be translated to the native script. Any ideas?
1485101039

Edited 1497524580
The Aaron
Pro
API Scripter
You definitely can! &nbsp;Here's your code minimally fit into a script that responds to the command !mb &lt;num&gt; on('ready', function(){ &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; //dice roller function &nbsp; &nbsp; var diceRoller = function(numberOfDice){ &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //declaring variables &nbsp; &nbsp; &nbsp; var results1 = 0; &nbsp; &nbsp; &nbsp; var results2 = 0; &nbsp; &nbsp; &nbsp; var results3 = 0; &nbsp; &nbsp; &nbsp; var results4 = 0; &nbsp; &nbsp; &nbsp; var results5 = 0; &nbsp; &nbsp; &nbsp; var results6 = 0; &nbsp; &nbsp; &nbsp; var result = 0; &nbsp; &nbsp; &nbsp; var loop = (1*numberOfDice)+1; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //roll each die individually until all dice are rolled &nbsp; &nbsp; &nbsp; for (i=1; i&lt;loop; i++){ &nbsp; &nbsp; &nbsp; &nbsp; var roll = randomInteger(6); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //add each die result to the number of occurrences of that result &nbsp; &nbsp; &nbsp; &nbsp; if (roll == 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results1 += 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (roll == 2) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results2 += 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (roll == 3) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results3 += 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (roll == 4) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results4 += 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (roll == 5) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results5 += 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results6 += 1; &nbsp; &nbsp; &nbsp; &nbsp; }//end of if/else statements&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }//end of 'for' loop &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //highest number &lt;6 with at least 2 occurrences is the result &nbsp; &nbsp; &nbsp; if (results5 &gt; 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 5; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (results4 &gt; 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 4; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (results3 &gt; 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 3; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (results2 &gt; 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 2; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else if (results1 &gt; 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 0; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //user is told the result and how many nudges(6s) they got &nbsp; &nbsp; &nbsp; var response = "You got a result of " + result + " and " + results6 + " nudges!"; &nbsp; &nbsp; &nbsp; return response; &nbsp; &nbsp; }; //end of dice Roller function &nbsp; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; if('api' === msg.type && msg.content.match(/^!mb\b/) &nbsp;){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let args=msg.content.split(/\s+/); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(args.length&gt;1){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let numRolls = parseInt(args[1],10) || 1, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answer &nbsp; = diceRoller(numRolls); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Mistborn Dice',answer); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); }); I didn't test this (cuz I'm supposed to be prepping for my game in 3 hours (eep!)), but it should work fine and you should be able to build from there. This is what a call to it would look like: !mb 5 And it will print the result to the chat. To learn more about the API, start reading here: &nbsp; <a href="https://wiki.roll20.net/API:Use_Guide" rel="nofollow">https://wiki.roll20.net/API:Use_Guide</a> Post back with any questions! Cheers!