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

Dark Heresy 2nd Edition help

1480532853

Edited 1480532914
John D.
Sheet Author
API Scripter
I'm setting up API for a friend Dark Heresy 2nd game using the degree of success API  here and  here . I'm added both of them to The Script Editor and no error pop up. But somehow when I using the !roll40k command the result just always show up like I used the !skill40k command instead. If I disable the skill40k script the !roll40k script work as normal. Can anyone help check out what is wrong with the scripts?
1480534653

Edited 1480537961
Jakob
Sheet Author
API Scripter
Short answer: the two scripts are both too greedy with the namespace and do not properly encapsulate their functions. Hence the rollResult function is defined twice (in different ways) by two scripts, and the latter definition takes over. It would probably be pretty easy to rewrite things so that everything has its own namespace... or, simpler but less, elegant, rename one of the functions (quick and dirty...). Also, one has to wonder why the script author writes a function called trimString instead of just using string.prototype.trim()... Ok, dirty rewrite of roll40k: /**  * 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 = '';     var output3 = '';     var autoRoll;     var degOfSuc;     //Check for an automatic result      switch (roll) {     case 1:         autoRoll = 1;         break;     case 100:         autoRoll = 100;         break;     default:         autoRoll = 0;     }          //Form output message based on result     if(roll <= modTarget) {         if(autoRoll === 100){             output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span> ';         }         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 {         if(autoRoll === 1) {             output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span> ';         }         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     var output = output1 + '<br><br>' + output2 + output3;     return output;  } /** Interpret the chat commands. **/ on('chat:message', function(msg) {     var cmdName;     var msgTxt;     cmdName = '!roll40k ';     msgTxt = msg.content;     if(msg.type == 'api' && msgTxt.indexOf(cmdName) !== -1) {         var paramList = msgTxt.slice(cmdName.length);         if(paramList.indexOf(',') == -1) {             sendChat(msg.who, '/w ' + msg.who + ' must specify three comma-separated parameters for !roll40k command.');         }         else {             var paramArray = paramList.split(',');             var curToken = trimString(paramArray[0]);             var attribute = trimString(paramArray[1]);             var modifier = trimString(paramArray[2]);             var result = rollResultForRoll40k(curToken, attribute, modifier);             sendChat(msg.who, result);             }     } });      /** Trims a string **/ var trimString = function(src) {     return src.replace(/^\s+|\s+$/g, ''); } Dirty rewrite of skill40k: /**  * 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 = '';     var output2 = '';     var output3 = '';     var autoRoll;     var degOfSuc;          //Create output which includes skill level wording      switch (skillBonus) {     case 0:         output1 = token + ' knows a bit of this skill (0) granting a modified target of <B>' + modTarget + '</B>. They rolled a <B>' + roll + '</B>. ';         break;     case 10:         output1 = token + ' is trained in this skill (+10) granting a modified target of <B>' + modTarget + '</B>. They rolled a <B>' + roll + '</B>. ';         break;     case 20:         output1 = token + ' is experianced with this skill (+20) granting a modified target of <B>' + modTarget + '</B>. They rolled a <B>' + roll + '</B>. ';         break;     case 30:         output1 = token + ' is a veteran of this skill (+30) granting a modified target of <B>' + modTarget + '</B>. They rolled a <B>' + roll + '</B>. ';         break;     default:         output1 = token + ' is untrained in this skill (-20) granting a modified target of <B>' + modTarget + '</B>. They rolled a <B>' + roll + '</B>. ';     }     //Check for an automatic result      switch (roll) {     case 1:         autoRoll = 1;         break;     case 100:         autoRoll = 100;         break;     default:         autoRoll = 0;     }          //Form output message based on result     if(roll <= modTarget) {         if(autoRoll === 100){             output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span> ';         }         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 {         if(autoRoll === 1) {             output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span> ';         }         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     var output = output1 + '<br><br>' + output2 + output3;     return output;  } /** Interpret the chat commands. **/ on('chat:message', function(msg) {     var cmdName;     var msgTxt;     cmdName = '!skill40k ';     msgTxt = msg.content;     if(msg.type == 'api' && msgTxt.indexOf(cmdName) !== -1) {         var paramList = msgTxt.slice(cmdName.length);         if(paramList.indexOf(',') == -1) {             sendChat(msg.who, '/w ' + msg.who + ' must specify seven comma-separated parameters for !skill40k command.');         }         else {             var paramArray = paramList.split(',');             var curToken = trimString(paramArray[0]);             var attribute = trimString(paramArray[1]);             var skillBonus1 = trimString(paramArray[2]);             var skillBonus2 = trimString(paramArray[3]);             var skillBonus3 = trimString(paramArray[4]);             var skillBonus4 = trimString(paramArray[5]);             var modifier = trimString(paramArray[6]);             var result = rollResultForSkill40k(curToken, attribute, skillBonus1, skillBonus2, skillBonus3, skillBonus4, modifier);             sendChat(msg.who, result);             }     } });      /** Trims a string **/ var trimString = function(src) {     return src.replace(/^\s+|\s+$/g, ''); } These will work unless I made a typo, but I'm not proud of it...
1480560564
John D.
Sheet Author
API Scripter
Uh... namespace, encapsulate? Ah yes, yes, so that is where I overlooked! (To be honest I have no idea what you're talking about, but hey it's working now! Praise the Emperor!) Thanks alot man! You're the best!
1480667632
John D.
Sheet Author
API Scripter
Uhm, I don't want to take advantage of you (I will anyway) but a new problem came up with the script, Somehow when I use both !roll40k and !skill40k command and roll a 100, it does not said "rolled a 100 and automatically fails by 1 degree" in both cases. May I ask you to look into this too?
1480669698
Jakob
Sheet Author
API Scripter
I don't fully understand what the script does, nor do I know the Dark heresy rules, but it will only display this message if 1) you rolled a 100, and 2) 100 <= attribute + modifier. Similarly, it will only display the message for roll result of 1 if 1) you rolled a 1, and 2) 1 > attribute+modifier. It seems these two are somehow switched around? If I understand correctly, if you roll a 100 or 1, you shouldn't care at all what attribute or modifier is and ONLY display the message "rolled a 100/1 and automatically fails/succeeds by 1", does that match the rules?
1480670055

Edited 1480670067
John D.
Sheet Author
API Scripter
Whoa thanks for relpy so fast. And yes that;s how rule work, if you roll 100 or the attribute + modifier is less than 1 (negative) it's an auto fail, if you roll 1 or the attribute + modifier is more than 100 (you can't roll over it, hence can't fail) it's an auto success. The rule is that you roll 1d100 and try to get it lower than the attribute + modifier
1480671985

Edited 1480672256
Jakob
Sheet Author
API Scripter
Yes, that script has its issues then, the conditions for 100 and 1 almost never trigger. Moreover, it crashes when you use less than the required number of arguments :O. Ok, try this. Caution, it's untested. /**  * 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); } } }); And this. /**  * 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); } } });
1480672382
John D.
Sheet Author
API Scripter
Well I'm more than happy to be your test subject. I'm gonna try that on a duplicate then.
1480674269
John D.
Sheet Author
API Scripter
It seem to be working now. Again thanks you very much for your help. If you ever want to try Dark Heresy 2nd edition contact me, I can hook you up. (^_-)≡★
1480679456
Jakob
Sheet Author
API Scripter
You're welcome, it was a simple enough fix. I'll keep that offer in mind :).