Last active
July 13, 2017 21:33
-
-
Save SCPRedMage/2ce71237d9d3f7f3463d0dfd61cc0608 to your computer and use it in GitHub Desktop.
Create basic token actions for new Roll20 characters
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
function getCharacterObj(obj) { | |
"use strict"; | |
//send any object and returns the associated character object | |
//returns character object for attribute, token/graphic, and ability, and... character | |
var objType = obj._type, | |
att, characterObj, tok; | |
if ((objType !== "attribute") && (objType !== "graphic") && (objType !== "character")) { | |
sendChat("API"," cannot be associated with a character."); | |
return; | |
} | |
if ((objType === "attribute") || (objType === "ability")) { | |
att = getObj(objType, obj._id); | |
if (att.get("_characterid") !== "") { | |
characterObj = getObj("character", att.get("_characterid")); | |
} | |
} | |
if (objType === "graphic") { | |
tok = getObj("graphic", obj._id); | |
if (tok.get("represents") !== "") { | |
characterObj = getObj("character", tok.get("represents")); | |
} else { | |
sendChat("API"," Selected token does not represent a character."); | |
return; | |
} | |
} | |
if (objType === "character") { | |
characterObj = getObj("character", obj._id); | |
} | |
return characterObj; | |
} | |
on("ready", function() { | |
on('chat:message', function(msg) { | |
if (msg.type === "api" && msg.content.indexOf("!create-abilities") !== -1 ) | |
{ | |
selected = msg.selected; | |
_.each(selected, function(obj) { | |
var charObj = getCharacterObj(obj); | |
var charName = charObj.get("name"); | |
if (charObj) | |
{ | |
createObj("ability", { | |
name: "Init", | |
characterid: charObj.id, | |
action: "@{init-macro-text}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Fort", | |
characterid: charObj.id, | |
action: "%{"+charName+"|Fort-Save}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Ref", | |
characterid: charObj.id, | |
action: "%{"+charName+"|Ref-Save}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Will", | |
characterid: charObj.id, | |
action: "%{"+charName+"|Will-Save}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Abilities⁠", | |
characterid: charObj.id, | |
action: "@{ability_checks_macro}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Skills⁠", | |
characterid: charObj.id, | |
action: "%{"+charName+"|skills}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Spells", | |
characterid: charObj.id, | |
action: "@{spellclass-0-book}", | |
istokenaction: true | |
}); | |
createObj("ability", { | |
name: "Attacks⁠", | |
characterid: charObj.id, | |
action: "@{attacks-macro}", | |
istokenaction: true | |
}); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment