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] Dark Heresy 2nd Edition API

1486527772
John D.
Sheet Author
API Scripter
So I'm trying to make a custom DH2 sheet for my game using this API for degree of success /** * This script rolls a d100 and computes and outputs the success results based * on Dark Heresy Second Edition RPG criteria. * * The following commands is used: * !roll40k [tokenName], [attributeValue], [ModifierValue] **/ //Rolls a d100 and calculates the success or fail results to the chat window. var rollResultForRoll40k = function (token, attribute, modifier) { var roll = randomInteger(100); var modTarget = parseInt(attribute) + parseInt(modifier); var output1 = token + ' has a modified target of <B>' + modTarget + '</B> and rolled a <B>' + roll + '</B>. '; var output2, degOfSuc; //Form output message based on result if (roll === 1) { output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span>'; } else if (roll === 100) { output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span>'; } else if (roll <= modTarget) { degOfSuc = (Math.floor(modTarget / 10) - Math.floor(roll / 10)) + 1; output2 = '<span style="color:green">' + token + ' succeeds by <B>' + degOfSuc + ' degree(s)</B>.</span>'; } else { degOfSuc = (Math.floor(roll / 10) - Math.floor(modTarget / 10)) + 1; output2 = '<span style="color:red">' + token + ' fails by <B>' + degOfSuc + ' degree(s)</B></span>.'; } //Return output return output1 + '<br><br>' + output2; }; /** Interpret the chat commands. **/ on('chat:message', function (msg) { 'use strict'; var cmdName = '!roll40k '; if (msg.type === 'api' && msg.content.indexOf(cmdName) !== -1) { var paramArray = msg.content.slice(cmdName.length).split(','); if (paramArray.length !== 3) { sendChat(msg.who, '/w ' + msg.who + ' You must specify three comma-separated ' + 'parameters for the !roll40k command.'); } else { var result = rollResultForRoll40k(paramArray[0].trim(), paramArray[1].trim(), paramArray[2].trim()); sendChat(msg.who, result); } } }); Normally it work just fine, but I also wanted to implement the new drop down list for combat circumstances that just got updated for the character sheet. So I tried a command like this: !roll40k @{character_name}, @{BallisticSkill}, (?{Aim | Half aim (+10),+10| No aim (+0),+0 | Full aim (+20),+20} + ?{Range | Point Blank (+30),+30 | Short Range (+10),+10 | Standard range (+0),+0 | Long Range (-10),-10 | Extreme Range (-30),-30} + ?{Rate of Fire/Attack Type|Standard (+10),+10 | Semi auto (+0),+0 | Full Auto (-10),-10 | Called Shot (-20),-20 | Suppressing Fire (-20),-20} + ?{Modifier|0}) Aaaand it doesn't work, only the first value ?{Aim | Half aim (+10),+10| No aim (+0),+0 | Full aim (+20),+20} got calculate by the API. I think it's because API command doesn't do calculation like macro? Anyone can help me out on this?
1486528322
The Aaron
Pro
API Scripter
So, that api only expects 3 parameters.  The 3rd parameter is expected to be an integer and gets passed to parseInt() to turn it into one.  This will discard anything but the first valid number in the string. Here's a modified version of the script: /** * This script rolls a d100 and computes and outputs the success results based * on Dark Heresy Second Edition RPG criteria. * * The following commands is used: * !roll40k [tokenName], [attributeValue], [ModifierValue] **/ //Rolls a d100 and calculates the success or fail results to the chat window. var Roll40k = Roll40k || (function(){     var rollResultForRoll40k = function (token, attribute, modifier) {         var roll = randomInteger(100);         var modTarget = parseInt(attribute) + parseInt(modifier);         var output1 = token + ' has a modified target of <B>' + modTarget + '</B> and rolled a <B>' + roll + '</B>. ';         var output2, degOfSuc;         //Form output message based on result         if (roll === 1) {             output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span>';         }         else if (roll === 100) {             output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span>';         }         else if (roll <= modTarget) {             degOfSuc = (Math.floor(modTarget / 10) - Math.floor(roll / 10)) + 1;             output2 = '<span style="color:green">' + token + ' succeeds by <B>' + degOfSuc + ' degree(s)</B>.</span>';         }         else {             degOfSuc = (Math.floor(roll / 10) - Math.floor(modTarget / 10)) + 1;             output2 = '<span style="color:red">' + token + ' fails by <B>' + degOfSuc + ' degree(s)</B></span>.';         }         //Return output         return output1 + '<br><br>' + output2;     },     processInlinerolls = function(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;         }     };     /** Interpret the chat commands. **/     on('chat:message', function (msg) {         'use strict';         var cmdName = '!roll40k ';         if (msg.type === 'api' && msg.content.indexOf(cmdName) !== -1) {             let content = processInlinerolls(msg);             var paramArray = content.slice(cmdName.length).split(',');             if (paramArray.length !== 3) {                 sendChat(msg.who, '/w ' + msg.who + ' You must specify three comma-separated ' +                 'parameters for the !roll40k command.');             }             else {                 var result = rollResultForRoll40k(paramArray[0].trim(),                 paramArray[1].trim(), paramArray[2].trim());                 sendChat(msg.who, result);             }         }     }); }()) You should be able to call it like this and have it work now: !roll40k @{character_name}, @{BallisticSkill}, [[(?{Aim | Half aim (+10),+10| No aim (+0),+0 | Full aim (+20),+20} + ?{Range | Point Blank (+30),+30 | Short Range (+10),+10 | Standard range (+0),+0 | Long Range (-10),-10 | Extreme Range (-30),-30} + ?{Rate of Fire/Attack Type|Standard (+10),+10 | Semi auto (+0),+0 | Full Auto (-10),-10 | Called Shot (-20),-20 | Suppressing Fire (-20),-20} + ?{Modifier|0})]] (I put the third parameter in an inline roll so it will get evaluated to a number first, the change to the script allows it to accept inline rolls)
1486538650
John D.
Sheet Author
API Scripter
Yep, it worked perfectly well now. Thank you.
1486561016
The Aaron
Pro
API Scripter
No worries.  Happy Rolling!
This script is pretty great. Started rolling into my own sheet. Noticed it doesn't handle negative target numbers well. Not a big deal, but thought I'd mention it. 
1486668046

Edited 1486668117
Lithl
Pro
Sheet Author
API Scripter
Messiahcide said: This script is pretty great. Started rolling into my own sheet. Noticed it doesn't handle negative target numbers well. Not a big deal, but thought I'd mention it.  If you're playing Dark Heresy and you have a negative target number, you should probably be running for your life instead of shooting something. I mean, you'll die anyway, but at least you'll get shot in the back and make the guy that killed you feel slightly  bad about it. Maybe.
Well, let me explain. I sort of derped. I went to apply this to the skills list, and untrained rolls have a -20 penalty. When utilized without checking off known (+20), it results in a NaN result. XD
1486668984
John D.
Sheet Author
API Scripter
Brian said:   If you're playing Dark Heresy and you have a negative target number, you should probably be running for your life instead of shooting something. I mean, you'll die anyway, but at least you'll get shot in the back and make the guy that killed you feel slightly  bad about it. Maybe. *click* *BLAM* If you will not serve in combat, then you will serve on the firing line!
1486669246

Edited 1486669267
John D.
Sheet Author
API Scripter
Messiahcide said: Well, let me explain. I sort of derped. I went to apply this to the skills list, and untrained rolls have a -20 penalty. When utilized without checking off known (+20), it results in a NaN result. XD Worry not, The Emperor provides, here's a seperate script I used for Skill check /**  * This script rolls a d100 and computes and outputs the success results based  * on Dark Heresy Second Edition RPG criteria. It is intended to be used for skill  * checks.  *  * The following commands is used:  * !skill40k [tokenName], [attributeValue], [skillBonus1], [skillBonus2], [skillBonus3], [skillBonus4], [ModifierValue]  *  * It is expected that the following bonus are inlcuded based on the skill level of the character:  * skillBonus1 = 20 or 0, if known or untrained  * skillBonus2 = 10 or 0, if trained or less than trained  * skillBonus3 = 10 or 0, if experianced or less than experianced  * skillBonus4 = 10 or 0, if veteran or less than veteran  *  * Example:  * /em @{character_name} makes a known Acrobatics skill check!  * !skill40k @{character_name},@{Agility},20,0,0,0,?{Total Modifiers|0}  **/ //Rolls a d100 and calculates the success or fail results to the chat window. var rollResultForSkill40k = function (token, attribute, skillBn1, skillBn2, skillBn3, skillBn4, modifier) { var roll = randomInteger(100); var skillBonus = parseInt(skillBn1) + parseInt(skillBn2) + parseInt(skillBn3) + parseInt(skillBn4) - 20; var modTarget = parseInt(attribute) + skillBonus + parseInt(modifier); var output1 = token, output2, degOfSuc; //Create output which includes skill level wording switch (skillBonus) { case 0: output1 += ' knows a bit of this skill (0)'; break; case 10: output1 += ' is trained in this skill (+10)'; break; case 20: output1 += ' is experienced with this skill (+20)'; break; case 30: output1 += ' is a veteran of this skill (+30)'; break; default: output1 += ' is untrained in this skill (-20)'; } output1 += ' granting a modified target of <B>' + modTarget + '</B>. They ' + 'rolled a <B>' + roll + '</B>.'; //Form output message based on result if (roll === 1) { output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span>'; } else if (roll === 100) { output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span>'; } else if (roll <= modTarget) { degOfSuc = (Math.floor(modTarget / 10) - Math.floor(roll / 10)) + 1; output2 = '<span style="color:green">' + token + ' succeeds by <B>' + degOfSuc + ' degree(s)</B>.</span>'; } else { degOfSuc = (Math.floor(roll / 10) - Math.floor(modTarget / 10)) + 1; output2 = '<span style="color:red">' + token + ' fails by <B>' + degOfSuc + ' degree(s)</B></span>.'; } //Return output return output1 + '<br><br>' + output2; }; /** Interpret the chat commands. **/ on('chat:message', function (msg) { 'use strict'; var cmdName = '!skill40k '; if (msg.type === 'api' && msg.content.indexOf(cmdName) !== -1) { var paramArray = msg.content.slice(cmdName.length).split(','); if (paramArray.length !== 7) { sendChat(msg.who, '/w ' + msg.who + ' must specify seven comma-separated ' + 'parameters for the !skill40k command.'); } else { var result = rollResultForSkill40k(paramArray[0].trim(), paramArray[1].trim(), paramArray[2].trim(), paramArray[3].trim(), paramArray[4].trim(), paramArray[5].trim(), paramArray[6].trim()); sendChat(msg.who, result); } } });
1486669326

Edited 1486669339
Messiahcide
Sheet Author
Truly blessed am I to receive the Emperor's blessings!  Thanks Jack D =D
1486670055

Edited 1486670604
Messiahcide
Sheet Author
quick question for clarification - if im reading this correctly, I have to change the attributions under each skill to match the SkillBonus format, changing attr_Command1 for example to attr_CommandBonus1 ? Disregard! I derped again. XD
1486670649
John D.
Sheet Author
API Scripter
Here is the HTML layout I made using the 2017 sheet by Michael R. You can just use it. It worked on my games I changed "/em" to Bold & Italicize Text because I like to show my NPC' name in the rolls, but you could just switch it back. for Command it'd be something like this !skill40k @{character_name}, @{CommandCharacteristic}, @{Command1}, @{Command2}, @{Command3}, @{Command4}, ?{Target Modifier|0}
Thanks a bunch Jack D. I figured it out. Trying to implement this into the html while my son is blaring unholy canticles to the dark gods (children's games on tablets) was an unwise move on my part. I figured it out just before you posted. lol
1486671101

Edited 1486671266
John D.
Sheet Author
API Scripter
Glad to be able to help. Happy purging.