Skip to content

Instantly share code, notes, and snippets.

@sturtus
Last active January 2, 2016 20:18
Show Gist options
  • Save sturtus/8355602 to your computer and use it in GitHub Desktop.
Save sturtus/8355602 to your computer and use it in GitHub Desktop.
Roll20 DCC Dice chain script
/*
function to change an attribute with a d20 value and move it up or down the
DCC dice chain by x number of dice.
REQUIRES MY PERSONAL ROLL20 LIBRARY SCRIPT TO BE IN ROLL20 CAMPAIGN
https://gist.github.com/sturtus/8352577
!diceChain attributeName|newValue
!diceChain ActionDie|+1
!diceChain ActionDie|-2
!diceChain DeedDie|-1
!diceChain WeaponDamage|-1
*/
function diceChain(characterObj,attributeObjArray,newValue) {
var diceChainArray = ["d3", "d4", "d5", "d6", "d7", "d8", "d10", "d12", "d14", "d16", "d20", "d24", "d30"];
var characterName = characterObj.get("name");
var attributeName = attributeObjArray[0].get("name");
var attributeValue = attributeObjArray[0].get("current");
var diePositionChange = removePlus(newValue);
diePositionChange = parseInt(diePositionChange.toString());
var newDiePosition = (diceChainArray.indexOf(attributeValue)) + diePositionChange;
var newDie = diceChainArray[newDiePosition];
attributeObjArray[0].set("current", newDie);
//output
sendChat("", "/desc " + characterName + " has changed " + attributeName + " from " + attributeValue + " to " + newDie + ".");
};
on("chat:message", function(msg) {
if (msg.type == "api" && msg.content.indexOf("!diceChain ") !== -1) {
//parse the input into two variables, attribute and newValue
var selected = msg.selected;
var Parameters = msg.content.split("!diceChain ")[1];
var attributeName = Parameters.split("|")[0];
var newValue = Parameters.split("|")[1];
if(!selected) {
sendChat("", "/desc Select token and try again.");
return; //quit if nothing selected
};
//loop through selected tokens
_.each(selected, function(obj) {
var characterObj = getCharacterObj(obj);
if (characterObj == false) return;
var attributeObjArray = getAttributeObjects(characterObj, attributeName);
if (attributeObjArray == false) return;
diceChain(characterObj,attributeObjArray,newValue);
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment