Last active
August 7, 2020 00:47
-
-
Save nolivo/e1d32eebfc53dddcd8d7126441ce0b5a to your computer and use it in GitHub Desktop.
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
on("chat:message", function(msg) | |
{ | |
if (msg.type == "api" && msg.content.indexOf("!customSpellbook") == 0){ | |
var args = msg.content.split(/\s+/); | |
var spellName = args[1].toLowerCase(); | |
var spellLevel = Number(args[2]); | |
var tokenid = msg.selected[0]._id; | |
var token = getObj("graphic",tokenid); | |
var charID = token.get("represents"); | |
var tokenName = token.get("name"); | |
switch(spellName){ | |
case "magicmissile": | |
magicMissile(spellLevel); | |
break; | |
case "scorchingray": | |
scorchingRay(spellLevel,tokenName); | |
break; | |
} | |
sendChat("API",`!modbattr --charid ${charID} --lvl${spellLevel}_slots_expended|-1`); | |
} | |
}); | |
function magicMissile(spellLevel){ | |
var numberOfDarts = spellLevel + 2; | |
var dartOutput = ""; | |
for(counter=1;counter<=numberOfDarts;counter++){ | |
dartOutput+=`{{Dart ${counter} = [[1d4+1]]}}`; | |
} | |
var outputMessage = `&{template:default} {{name=Magic Missile}} ${dartOutput}`; | |
sendChat("API",outputMessage); | |
} | |
function scorchingRay(spellLevel,tokenName){ | |
var numberOfRays = 3 + (spellLevel-2); | |
var rayOutput = ""; | |
if(spellLevel<2){ | |
sendChat("CustomSpellbook","Scorching Ray requires at least a level 2 spell slot"); | |
return; | |
} | |
for (counter=1;counter<=numberOfRays;counter++){ | |
rayOutput+=`{{Ray ${counter} Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]]=[[2d6]] Fire Damage}}`; | |
} | |
var outputMessage = `&{template:default} {{name=Scorching Ray}} ${rayOutput}`; | |
sendChat("API",outputMessage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment