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

[Help] Ars Magica Dice Roller

Hi Mentors I'm looking for some help with a diceroller, initially I thought that what I wanted was simple, but I'm apperently not yet comfortable about the API yet. What I'm looking for is a AM5 Dice roller that can perform the following rolls.: Simple Die roll Quality Die roll Stress Die roll As far as I understands, one needs to make something at listens for the chat API, and does some calculations upon the data, and some loops. The Syntax for rolling could be something like (Stress Roll) "/aroll <type> <Modifier> <ease factor>"" <type> would be "S" for stress, "Q" for Quality", "N" for normal (if needed) <modifier> would be a value between 1 and 20, <ease factor> would be a no optional value, but if it was used, it should be included in the evaluation The difference between the 3 rolls are as follows: Simple die Simple die is just that, 1d10 + modifiers, so it's fairly simple to make (just use the /roll 1d10) Quality die Quality die roll is a bit more complex, it's essentially a "1d10 + modfiers" but.: if the dice is 4 it it should result in "Roll Result is 4 = 4 (Success)" if the dice is 1 it should roll again, and multiply the next by x2, (1, 5 = 10) "Roll Result is 1,5 + 3 (modifer) = 13 (Success)" if the dice is another 1, it should multiply the roll by x4. (ie 1,1, 5, = 20) and it should say "Roll Result is 1,1,5 + 3 (modifer) = 23 (Exceptional Success)" Stress die Stress die roll adds one more rule on the dice roll it still is essentially "1d10 + modfiers" but.: if the dice is 4 it it should result in "Roll Result is 4 = 4 (Success)" if the dice is 1 it should roll again, and multiply the next by x2, (1, 5 = 10) "Roll Result is 1,5 + 3 (modifer) = 13 (Success)" if the dice is another 1, it should multiply the roll by x4. (ie 1,1, 5, = 20) and it should say "Roll Result is 1,1,5 + 3 (modifer) = 23 (Exceptional Success)" if the dice rolls a 0, it should say "Roll result is a Botch" So with the above syntax, .: /aroll Q 5 13 it would generate a result like this (Botch, roll 0) would be "Roll Result is (10+5) 15 vs 13 (Success)" (Failure, roll 3) would be "Roll Result is (3+5) 8 vs 13 (Failure)" (Success, roll 9) would be "Roll Result is (9+5) 14 vs 13 (Success)" (Exceptional Success, roll 1,6) "Roll Result is (2x6 = 12+5) 17 vs 13 (Exceptional Success)" /aroll S 5 13 it would generate a result like this (Botch, roll 0) would be "Roll Result a (Botch), roll Botch Dice" (Failure, roll 3) would be "Roll Result is (3+5) 8 vs 13 (Failure)" (Success, roll 9) would be "Roll Result is (9+5) 14 vs 13 (Success)" (Exceptional Success, roll 1,6) "Roll Result is (2x6 = 12+5) 17 vs 13 (Exceptional Success)" I don't think the complexity of this is insane, I guess I'll eventually get to have to learn the API fully, but if anyone could point me in the right direction, or perhaps have a great idea on how to do this I'll embrace any help I can get. Best Regards L
After trying to remember some of the basics of Javascript I have come up with this, which works in a webpage, but getting it to work with roll20 isn't all there yet. I'm aware that it's not the best and most beautiful code in the world :) But I'm learning as we go - I've been trying figure out how to put it into the API, by looking at what others have done, but I've not been able to crack the code yet . as I said I'm still learning :D. I added the Botch Dices inside the botch detection, to make it roll the botch dices automaticall, Eventually i might make that a seperate roll I changed the syntax above a bit as well. to be something along the lines of !ars <easefactor> <modifier> <dicetype> <Botchdice> There is very little "validation" on data, and that ofcourse is really bad, but it will get there eventually. Anyway, my questions would be, how would I be able to make these functions work in the API, any pointers would be much appriciated :) function rollsdie() { roll = Math.floor((Math.random()*10)+1); return roll; } function pot2(result) { if (result > 0) {result = result * 2;} else {result = 1;} return result; } function botchChech(result) { if (result == 1) {result = "BOTCH";} else {result = "Good";} return result; } function resultCheck(diceRoll, easeFactor, isFormularic) { if (isFormularic == 1) { if (diceRoll < (easeFactor-10)) { result = "Action Failed"; } else if ((diceRoll <= easeFactor) && (diceRoll >= (easeFactor-10))) { // 14 <= 23 AND 14 >= 13 result = "Action Success, but gain +1 fatique"; } else { result = "Action Success"; } } else { if ( diceRoll <= easeFactor) { result = "Action Failed"; } else { result = "Action Success"; } } return result; } function rollstress(easeFactor, bonusModifier, stressDie, botchDice ){ var strDicesRolled = 0; var strResultText = ""; var intSuccess = 0; var dRoll = rollsdie(); var result1 = 0; var bDiceRoll = ""; var bDice = 0; if (stressDie == "S") { if ((dRoll == 10) && (intSuccess == 0)) { // if it's the first roll and it's a 10 it is a potential Botch strResultText = "Potential Botch, let's see what the dices say:"; for(i = 0;i < botchDice; i++) { bDice = rollsdie(); bDiceRoll = bDiceRoll + " " + botchChech(bDice) + ","; } strDicesRolled = 0; strResultText = strResultText + " " + bDiceRoll + ""; } } while(dRoll == 1) { //Rolled a 1, multiply the number intSuccess++; dRoll = rollsdie(); strDicesRolled = strDicesRolled + " " + dRoll; strResultText = ""; } // result1 = (dRoll * pot2(intSuccess)) + bonusModifier; strDicesRolled = strDicesRolled; if (strResultText.length == 0) {strResultText = resultCheck(result1, easeFactor, 1);} return "Result (" + result1 + ") vs (" + easeFactor +") Result: " + strResultText +", ([" + dRoll + "] " + strDicesRolled + " + " + bonusModifier +")"; }
1405612966

Edited 1405613063
The Aaron
Roll20 Production Team
API Scripter
Hi Lukas, sorry I missed your post 3 days ago, I would have tried to help you sooner! What you are missing is tying into the event system for Roll20. I took your code and put it into the event system: var AM5 = AM5 || (function() { 'use strict'; var pot2 = function(result) { if (result > 0) { result = result * 2; } else { result = 1; } return result; }, botchChech = function(result) { if (result === 1) { result = "BOTCH"; } else { result = "Good"; } return result; }, resultCheck = function(diceRoll, easeFactor, isFormularic) { var result; if (isFormularic === 1) { if (diceRoll < (easeFactor-10)) { result = "Action Failed"; } else if ((diceRoll <= easeFactor) && (diceRoll >= (easeFactor-10))) { // 14 <= 23 AND 14 >= 13 result = "Action Success, but gain +1 fatique"; } else { result = "Action Success"; } } else { if ( diceRoll <= easeFactor) { result = "Action Failed"; } else { result = "Action Success"; } } return result; }, rollstress = function(easeFactor, bonusModifier, stressDie, botchDice ) { var strDicesRolled = 0, strResultText = "", intSuccess = 0, dRoll = randomInteger(10), result1 = 0, bDiceRoll = "", bDice = 0, i; if (stressDie === "S") { if ((dRoll === 10) && (intSuccess === 0)) { // if it's the first roll and it's a 10 it is a potential Botch strResultText = "Potential Botch, let's see what the dices say:"; for(i = 0;i < botchDice; i++) { bDice = randomInteger(10); bDiceRoll = bDiceRoll + " " + botchChech(bDice) + ","; } strDicesRolled = 0; strResultText = strResultText + " " + bDiceRoll ; } } while(dRoll === 1) { //Rolled a 1, multiply the number intSuccess++; dRoll = randomInteger(10); strDicesRolled = strDicesRolled + " " + dRoll; strResultText = ""; } // result1 = (dRoll * pot2(intSuccess)) + bonusModifier; if (strResultText.length === 0) {strResultText = resultCheck(result1, easeFactor, 1);} return "Result (" + result1 + ") vs (" + easeFactor +") Result: " + strResultText +", ([" + dRoll + "] " + strDicesRolled + " + " + bonusModifier +")"; }, HandleInput = function(msg) { var args, easefactor, modifier, dicetype, botchdice,result; if (msg.type !== "api") { return; } args = msg.content.split(" "); switch(args[0]) { case '!ars': easefactor = parseInt(args[1],10) || 0; modifier = parseInt(args[2],10) || 0; dicetype = args[3] || 'N'; botchdice = parseInt(args[4],10) || 0; result = rollstress(easefactor,modifier,dicetype,botchdice); sendChat('AM5',result); break; } }, RegisterEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: RegisterEventHandlers }; }()); on("ready",function(){ 'use strict'; AM5.RegisterEventHandlers(); }); Here's what it looks like when it runs: I also ran it through JSLint and cleaned up most of it's complaints, and wrapped it in a single object in the global scope named AM5. The specific parts you were missing: 1: This is registering a function to listen to messages from the chat window: on('chat:message', HandleInput); You can see the HandleInput() function I added to look at the messages and respond only to API messages (begin with ! ) and only the ! ars message. 2: Output to the player is handed by calling sendChat(): sendChat('AM5',result); I'm just dumping your results to the chat. If you don't want it to say AM5 in the message, you can just put '' instead. Also, Roll20 provides the function randomInteger( num ) which gives you a random number between 1 and num which is uniformly distributed randomly. Hope that helps! P.S.: If you're looking for Javascript info, I highly recommend Javascript: The Good Parts by Douglas Crockford. Cheers!
Thanks a lot Aaron. !! This just looks awesome, thanks for the help and pointers. I'll certainly give it a good look. Best Regards Lukas