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

Have function recognize inline roll

1489777633

Edited 1489778290
I'm trying to alter a script written by Havoc  here . In general I want the target variable to be able to accept inline rolls so one could write something like !eclipseroll [[3*@{cog}]] 0 Test and have it work. I'm fairly new to javascript just a warning   I would paste copy of code below but I couldn't get it to look readable sorry.
Use this code instead. I put my changes in bold so that you can see them easier. I simply added another function that you can find  here  into the script and call it to calculate the inline rolls for you. // !eclipseroll TargetNumber HiddenType Title(SingleWord) // hidden 0 - public // hidden 1 - only GM // hidden 2 - private function EclipsePhaseDice(char, player, target, hidden, title) {     var addTitle = false;     if (title != null)     {         if (title != "")         {             addTitle = true;         }     }     var targetNumber = Number(target);     if (targetNumber > 98) targetNumber = 98;     if (targetNumber < 1) targetNumber = 1;     var text = "";     if (addTitle == true)     {         text = text + "<table border='1' style='width:100%'><tr><td align='center'><h3>" + title + " Roll</h3></tr></td><tr><td>";     }     else     {         text = text + "<table border='1' style='width:100%'><tr><td align='center'><h3>Roll</h3></tr></td><tr><td>";     }     text = text + "<b>Rolling for target:</b> " + target;    var rollOne = randomInteger(10) - 1; var rollTwo = randomInteger(10) - 1; var sum = (rollOne * 10) + rollTwo; var succ = false; var color = "red"; if (sum <= targetNumber) { succ = true; color = "green"; } var zeroText = ""; if (sum < 10) { zeroText = "0"; } var critical = false; if (rollOne == rollTwo) { critical = true; }     text = text + "<br><b>Rolled:</b> " + "<span style='color:" + color + "'>" + zeroText + sum + "</span>"; //00 or crit success if ((rollOne == 0 && rollTwo == 0) || (critical == true && succ == true)) { text = text + "<br><span style='color:green'><b>Critical Success!</b></span>"; } //99 or crit failure else if ((rollOne == 9 && rollTwo == 9) || (critical == true && succ == false)) { text = text + "<br><span style='color:red'><b>Critical Failure!</b></span>"; } var MoS = 0; if (sum > targetNumber) { MoS = sum - targetNumber; } else { MoS = targetNumber - sum; } if (succ == true) { text = text + "<br><b>MoS:</b> " + MoS; if (MoS >= 30) { text = text + "<br><span style='color:green'><b>Excellent Success!</b></span>"; } } else { text = text + "<br><b>MoF:</b> " + MoS; if (MoS >= 30) { text = text + "<br><span style='color:red'><b>Servere Failure!</b></span>"; } } if (critical == false) { var moxie = (rollTwo * 10) + rollOne; var addedMoxie = false; var moxieText = "<br><span style='color:green'>Moxie Usage</span>"; if (critical == true && succ == false) { if (addedMoxie == false) { text = text + moxieText; addedMoxie = true; } text = text + "<br>- Reject Critical on Failure"; } if (critical == false && succ == true) { if (addedMoxie == false) { text = text + moxieText; addedMoxie = true; } text = text + "<br>- Turn Success to Critical"; } if (critical == false) { if (moxie <= targetNumber) { if (addedMoxie == false) { text = text + moxieText; addedMoxie = true; } text = text + "<br>- Flip flop the roll! Result:"; var result = ""; var moxieMoS = targetNumber - moxie; if (moxieMoS >= 30) { result = "Excellent "; } var zeroMoxieText = ""; if (moxie < 10) { zeroMoxieText = "0"; } text = text + "<br>Roll: " + zeroMoxieText + moxie + " is a " + result + "Success. MoS: " + moxieMoS; } } }     text = text + "</td></tr></table>"        if (hidden==2)     {         var tempText = "/w " + whoSent + " "+text;         if (player==1) sendChat("player|"+char, tempText);         else sendChat("character|"+char, tempText);     }     if (hidden >= 1) text = "/w gm " + text;     if (player==1) sendChat("player|"+char, text);     else sendChat("character|"+char, text); }; /**  * Converts any inline rolls that are contained in a message sent by the chat log and returns the converted string.  */ function processInlinerolls(msg) { if (_.has(msg, 'inlinerolls')) { return _.chain(msg.inlinerolls) .reduce(function(previous, current, index) { previous['$[[' + index + ']]'] = current.results.total || 0; return previous; },{}) .reduce(function(previous, current, index) { return previous.replace(index, current); }, msg.content) .value(); } else { return msg.content; } } on("chat:message", function(msg) {     if ( msg.type != 'api' ) return; var contents = processInlinerolls(msg)     var cmd = contents.toLowerCase().split(' ');     if ( cmd[0] == "!eclipseroll" )  {         var inputName = msg.who;         var list = findObjs( { _type: "character", name: inputName         });         if (list.length == 0)         {             EclipsePhaseDice( msg.playerid, 1, cmd[1], cmd[2], cmd[3]);         }         else         {             EclipsePhaseDice( list[0].id, 0, cmd[1], cmd[2], cmd[3]);         }     } });
That work beautifully thank you. I knew I would have to incorporate that script somehow I look forward to parsing through yours to learn how I was supposed to
1489797087
Lithl
Pro
Sheet Author
API Scripter
You can see two versions of processInlinerolls (one also handles rollable tables)  on the wiki .