Last active
December 25, 2015 00:19
-
-
Save bripod/6887201 to your computer and use it in GitHub Desktop.
Mighty Deeds of Arms command for roll20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mighty Deeds of Arms for Dungeon Crawl Classics in roll20.net | |
// This script creates a command which will compute the Mighty Deed Die roll for a | |
// warrior's attack, and then use that value as a modifier for the attack and damage | |
// rolls, and output the computed roll to chat. | |
// The script assumes that 1) any character performing a mighty deed has an attribute called | |
// "DeedDie" whose max value is used to determine which die to roll for the mighty deed | |
// (i.e., 3 = 1d3, 4 = 1d4), and 2) ability modifiers are stored on the character sheets. | |
// I use STR, AGL, etc., but the script doesn't care what the attributes are called (although | |
// if they have commas in their names that will cause issues) | |
// The command format is as follows: | |
// !mightyDeed character_Name|action_die|damage_die|attack,mods|damage,mods | |
// - character_name: The full name of the character (not the token) performing the mighty deed | |
// - action_die: the roll expression to use for the base attack roll, i.e. 1d20 | |
// - damage_die: the roll expression to use for the base damage roll, i.e. 1d8 | |
// - attack,mods: comma-separated lists of character attribute values to add to the attack roll. Use "None" for no mods. | |
// - damage,mods: comma-separated lists of character attribute values to add to the attack roll. Use "None" for no mods. | |
// Example character abilities using the command: | |
// /emas attacks with his lucky weapon, a longsword. | |
// !mightyDeed Johnny Meatshield|1d20|1d8|STR,LCK|STR | |
// /emas attacks with his longbow, at medium range. | |
// !mightyDeed Johnny Meatshield|1d20-2|1d6|AGL|None | |
function mightyDeed(mightyCharacterName, mightyActionDie, mightyDeedDie, mightyDamageDie, mightyAttackArray, mightyDamageArray) { | |
var deedDieMax = mightyDeedDie.get("max"); | |
var deedResult = randomInteger(deedDieMax); | |
if (deedResult >= 3) { | |
sendChat("Mighty Deed", deedResult + ": Succeeds if hits!") | |
} else { | |
sendChat("Mighty Deed", deedResult + ": Fails!") | |
}; | |
var attackChatString = "[[" + mightyActionDie; | |
if (mightyAttackArray[0] != "None") { | |
for (var i = 0; i < mightyAttackArray.length; i++) { | |
attackChatString = attackChatString.concat(" + @{", mightyCharacterName, "|", mightyAttackArray[i], "}"); | |
}; | |
}; | |
attackChatString = attackChatString.concat(" + " + deedResult + "]] vs. AC, for [[" + mightyDamageDie); | |
if (mightyDamageArray[0] != "None") { | |
for (var i = 0; i < mightyDamageArray.length; i++) { | |
attackChatString = attackChatString.concat(" + @{", mightyCharacterName, "|", mightyDamageArray[i], "}"); | |
}; | |
}; | |
attackChatString = attackChatString.concat(" + " + deedResult + "]] points of damage!"); | |
log(attackChatString); | |
sendChat(mightyCharacterName,attackChatString); | |
}; | |
on("chat:message", function(msg) { | |
if (msg.type == "api" && msg.content.indexOf("!mightyDeed") !== -1) { | |
var mightyParameters = msg.content.split("!mightyDeed ")[1]; | |
var mightyCharacterName = mightyParameters.split("|")[0]; | |
var mightyActionDie = mightyParameters.split("|")[1]; | |
var mightyDamageDie = mightyParameters.split("|")[2]; | |
var mightyAttack = mightyParameters.split("|")[3]; | |
var mightyAttackArray = mightyAttack.split(","); | |
var mightyDamage = mightyParameters.split("|")[4]; | |
var mightyDamageArray = mightyDamage.split(","); | |
var mightyCharacterId = findObjs({_type: "character", name: mightyCharacterName})[0].get("_id"); | |
var mightyDeedDieId = findObjs({_type: "attribute", name: "DeedDie", _characterid: mightyCharacterId})[0].get("_id"); | |
var mightyDeedDie = getObj("attribute", mightyDeedDieId); | |
mightyDeed(mightyCharacterName, mightyActionDie, mightyDeedDie, mightyDamageDie, mightyAttackArray, mightyDamageArray); | |
}; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I messed around with it to make fewer arguments passed, and have it pull info off the token that is currently selected. Having issues with the final sendChat() command though. Keep getting unexpected number error.
// Mighty Deeds of Arms for Dungeon Crawl Classics in roll20.net
// This script creates a command which will compute the Mighty Deed Die roll for a
// warrior's attack, and then use that value as a modifier for the attack and damage
// rolls, and output the computed roll to chat.
// The script assumes that 1) any character performing a mighty deed has an attribute called
// "DeedDie" whose value is used to determine which die to roll for the mighty deed
// (i.e., d3, d4), 2) ability modifiers are stored on the character sheets.
// and 3) character uses an attribute called "ActionDie" to determine the attack roll.
// I use STR, AGL, etc., but the script doesn't care what the attributes are called (although
// if they have commas in their names that will cause issues)
// The command format is as follows:
// !mightyDeed damage_die|attack,mods|damage,mods
// - character_name: The full name of the character (not the token) performing the mighty deed
// - action_die: the roll expression to use for the base attack roll, i.e. 1d20
// - damage_die: the roll expression to use for the base damage roll, i.e. 1d8
// - attack,mods: comma-separated lists of character attribute values to add to the attack roll. Use "None" for no mods.
// - damage,mods: comma-separated lists of character attribute values to add to the attack roll. Use "None" for no mods.
// Example character abilities using the command:
// /emas attacks with his lucky weapon, a longsword.
// !mightyDeed 1d8|STR,LCK|STR
// /emas attacks with his longbow, at medium range.
// !mightyDeed 1d6|AGL|None
function mightyDeed(obj, actionDieAttrib, deedAttrib, mightyDamageDie, mightyAttackArray, mightyDamageArray) {
var attackChatString = "[[" + actionDieValue;
if (mightyAttackArray[0] != "None") {
for (var i = 0; i < mightyAttackArray.length; i++) {
attackChatString = attackChatString.concat(" + @{", mightyCharacterName, "|", mightyAttackArray[i], "}");
};
};
attackChatString = attackChatString.concat(" +", deedResult, "]] vs. AC, for [[", mightyDamageDie);
if (mightyDamageArray[0] != "None") {
for (var i = 0; i < mightyDamageArray.length; i++) {
attackChatString = attackChatString.concat(" + @{", mightyCharacterName, "|", mightyDamageArray[i], "}");
};
};
attackChatString = attackChatString.concat(" +", deedResult, "]] points of damage!");
log(attackChatString);
sendChat(mightyCharacterName,attackChatString);
};
on("chat:message", function(msg) {
});