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...