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?