Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Add damage dice every other level

I am looking to add spiritual weapon to my spell list and want the damage to scale along with casting level.  I used search but was unable to find what I am looking for.  Anyone got any idea how to write the API for damage dice to add an additional die every other level after the 2nd level? Thanks,
1597548845

Edited 1597548862
Damage formula: 1d8 + @{selected|spellcasting_modifier} + [[((?{Cast as Level|2} - 2) * 0.49)d8]] Replace spellcasting_modifier to the attribute the character uses as his spellcasting ability modifier.
1597558571
GiGs
Pro
Sheet Author
API Scripter
That's a clever way of handling rounding issues, Juan. The roll20 formulas for doing this involve the floor function and keep-highest, but aren't really any more elegant: 1d8 + @{selected|spellcasting_modifier} + [[{floor(?{Cast as Level|2}/2)-1,0}kh1]]d8
Both formulas threw the same error when tried.  Here is the line of code with GiGs' solution: DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] for [[1d8 + @{selected|spellcasting_modifier} + [[{floor(?{Cast as Level|2}/2)-1,0}kh1]]d8]] Force Damage}}`; BTW how do you break a line of code with this?  In VBA I would simply add and space followed by an underscore.  Code that goes off screen makes me twitch. I get this error when tried as shown: Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your script's code and click the "Save Script" button. We will then attempt to start running the scripts again.  More info...  If this script was installed from the Script Library, you might find help in the Community API Forum. For reference, the error message generated was:  SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "?" found. undefined ideas?
1597609663
GiGs
Pro
Sheet Author
API Scripter
I didnt realise you are putting this in a script. Does the script error if you comment out that line? The error could be coming from somewhere else in the script. You should comment out the sendChat line that sends the roll to chat, and instead log it, then copy the log and paste it here so we can see what isnt working. Unrelated: if you want to break the string over multiple lines, + is a concatenator in JS, so you can do: DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] ` +     `for [[1d8 + @{selected|spellcasting_modifier} + [[{floor(?{Cast as Level|2}/2)-1,0}kh1]]d8]] Force Damage}}`;
1597627928
timmaugh
Pro
API Scripter
You can also break a string with a simple backslash without closing your string. It works for simple strings, I know, and I*think* it works for template literals, too. let a = 'This is a string\     that breaks a line.';
Thanks for the info on line breaking.  I will learn this stuff.  Probably should go do a few videos, but i learn better when i have something I am trying to accomplish.   Now how do you comment here?  VBA is single quote. The script worked fine before I began adding spiritual hammer.  When I get a chance (and learn commenting out) I will do as suggested with the log.
1597668582

Edited 1597668660
timmaugh
Pro
API Scripter
You can do double slashes to comment: const thisIsCode = (awesomeness) => {    // this is commented out so I can tell you about the greatest, most special script in the history of scriptitude     // this function accepts nothing but awesomeness, and outputs only greatness and sunshine     let greatness, sunshine;     return { Greatness: greatness, Sunshine: sunshine }; }; You can also use the formation, /* */, to comment multiple lines (commenting everything between)... but since there are regex implementations that might utilize your ending closure, it's not always feasible. This will work: const thisIsCode = (awesomeness) => {     /* this function accepts nothing but awesomeness, and outputs only greatness and sunshine unfortunately, greatness and sunshine are unavailable while we work out the bugs     let greatness, sunshine;     return { Greatness: greatness, Sunshine: sunshine }; */ log(`Greatness is currently offline. Sunshine, too.`);     return; }; If, on the other hand, Greatness actually returned the following regex, not all of what you would be looking to comment out would be commented out, and you'd get an error: const thisIsCode = (awesomeness) => {     /* this function accepts nothing but awesomeness, and outputs only greatness and sunshine unfortunately, greatness and sunshine are unavailable while we work out the bugs     let greatness, sunshine;     return { Greatness: /great.*/g, Sunshine: sunshine };            // will cause an error because your commenting will end at the */ */ log(`Greatness is currently offline. Sunshine, too.`);     return; };
ok first thing is first.  This code is a modified version of Nick Olivo's Customspellbook code and all the code for functions Magic Missile and Scorching Ray (as well as the custom spell book) are his.  Any changes to accommodate Cure wounds, inflict wounds, healing word and now Spiritual Hammer are mine. When I run: on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!customPrayers") == 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 "curewoundsdl": CureWoundsDL(spellLevel,tokenName); break; case "healingworddl": HealingWordDL(spellLevel,tokenName); break; case "inflictwounds": InflictWounds(spellLevel,tokenName); break; case "spiritualweapon": SpiritualWeapon(spellLevel,tokenName); break; } sendChat("API",`!modbattr --charid ${charID} --lvl${spellLevel}_slots_expended|-1`); } }); function CureWoundsDL(spellLevel,tokenName){ var HealOutput=""; HealOutput+=`{{Healing=[[${spellLevel}d8+@{${tokenName}|Wisdom_mod}+(2+${spellLevel})]]}}`; var outputMessage = `&{template:default} {{name=Cure Wounds - Disciple of Life}} ${HealOutput}`; sendChat("API",outputMessage); } function HealingWordDL(spellLevel,tokenName){ var HealOutput=""; HealOutput+=`{{Healing=[[${spellLevel}d4+@{${tokenName}|Wisdom_mod}+2+${spellLevel}]]}}`; var outputMessage = `&{template:default} {{name=Healing Word - Disciple of Life}} ${HealOutput}`; sendChat("API",outputMessage); } function InflictWounds(spellLevel,tokenName){ var DmgOutput = ""; DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] for [[(2+${spellLevel})d10]] Necrotic Damage}}`; var outputMessage = `&{template:default} {{name=Inflict Wounds}} ${DmgOutput}`; sendChat("API",outputMessage); } function SpiritualWeapon(spellLevel,tokenName){ var DmgOutput = ""; /* DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] ` + `for [[1d8 + @{selected|spellcasting_modifier}]] + [[{floor(?{Cast as Level|2}/2)-1,0}kh1]]d8 Force Damage}}`;*/ DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] ` + `for [[1d8 + @{selected|spellcasting_modifier}]] + [[1d8]] Force Damage}}`; var outputMessage = `&{template:default} {{name=Spiritual Weapon}} ${DmgOutput}`; sendChat("API",outputMessage); log(outputMessage); } I get the following in the log: "ERROR: Unable to find character selected in chat command." "Error at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:637:11) at String.replace (<anonymous>) at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:549:29) at sendChat (/home/node/d20-api-server/api.js:1815:16) at SpiritualWeapon (apiscript.js:25161:5) at apiscript.js:25126:17 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1661:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560" "&{template:default} {{name=Spiritual Weapon}} {{Attack [[1d20+@{Sam Pippin|spell_attack_bonus} ]] for [[1d8 + @{selected|spellcasting_modifier}]] + [[1d8]] Force Damage}}" When the Spiritual Hammer function is changed to this: function SpiritualWeapon(spellLevel,tokenName){ var DmgOutput = ""; DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] ` + `for [[1d8 + @{selected|spellcasting_modifier}]] + [[{floor(?{Cast as Level|2}/2)-1,0}kh1]]d8 Force Damage}}`; /* DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] ` + `for [[1d8 + @{selected|spellcasting_modifier}]] + [[1d8]] Force Damage}}`;*/ var outputMessage = `&{template:default} {{name=Spiritual Weapon}} ${DmgOutput}`; sendChat("API",outputMessage); log(outputMessage); I get the following output: "ERROR: Unable to find character selected in chat command." "Error at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:637:11) at String.replace (<anonymous>) at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:549:29) at sendChat (/home/node/d20-api-server/api.js:1815:16) at SpiritualWeapon (apiscript.js:25161:5) at apiscript.js:25126:17 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1661:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560" SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "?" found. undefined Also the following shows up in a red box above the output log: Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your script's code and click the "Save Script" button. We will then attempt to start running the scripts again.  More info...  If this script was installed from the Script Library, you might find help in the Community API Forum. For reference, the error message generated was:  SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "?" found. undefined
I believe this is due to the current API limitation that doesn't allow you to both get the ID of both the selected and the target ID in the same code.
Juan C. said: I believe this is due to the current API limitation that doesn't allow you to both get the ID of both the selected and the target ID in the same code. Changing the code so that both pulls referenced  @{${tokenName} results in the same error occurring. 
1597691010
David M.
Pro
API Scripter
Adding the spell level query to the sendChat is causing problems because of the "?" character. See this thread for some details: <a href="https://app.roll20.net/forum/post/2154264/roll-queries-with-roll-template-in-sendchat-api" rel="nofollow">https://app.roll20.net/forum/post/2154264/roll-queries-with-roll-template-in-sendchat-api</a> I'm wondering if the first error is because the character name Sam Pippin has a space in it. Does it work for a character with no spaces in the name? If so, I think maybe adding quotes to the name might work?&nbsp;
1597697507
GiGs
Pro
Sheet Author
API Scripter
David M. said: Adding the spell level query to the sendChat is causing problems because of the "?" character. See this thread for some details: <a href="https://app.roll20.net/forum/post/2154264/roll-queries-with-roll-template-in-sendchat-api" rel="nofollow">https://app.roll20.net/forum/post/2154264/roll-queries-with-roll-template-in-sendchat-api</a> I'm wondering if the first error is because the character name Sam Pippin has a space in it. Does it work for a character with no spaces in the name? If so, I think maybe adding quotes to the name might work?&nbsp; It looks like the script is sending a roll to chat, which includes a query. Queries do not work when sent from the API. It's not just the ? causing a problem, its that queries themselves cannot work when in a roll sent from the API. Queries require a player, and sendChat commands do not belong to a player. If you want to use a query with API output, you must put the query in the initial command, and then extract it within the script. So youd do something like !customPrayers spiritualWeapon ?{level|0} then in the script, get the level argument, calculate its effects and output it with the sendChat.
GiGs said: It looks like the script is sending a roll to chat, which includes a query. Queries do not work when sent from the API. It's not just the ? causing a problem, its that queries themselves cannot work when in a roll sent from the API. Queries require a player, and sendChat commands do not belong to a player. If you want to use a query with API output, you must put the query in the initial command, and then extract it within the script. So youd do something like !customPrayers spiritualWeapon ?{level|0} then in the script, get the level argument, calculate its effects and output it with the sendChat. I use this from the token action bar in game to call the script !customSpellbook MelfAcidArrow ?{What level Sleep|2|3|4|5|6|7|8|9} obviously this one is for Melf's but I use the same setup for spiritual Hammer.
1597700849
David M.
Pro
API Scripter
GiGs said: Queries do not work when sent from the API. It's not just the ? causing a problem, its that queries themselves cannot work when in a roll sent from the API. Hmm, in the thread I linked it looked like they got sendChat queries to work in certain instances with some wizardry from TheAaron. Maybe I'm misinterpreting the results of that thread.
1597701338
GiGs
Pro
Sheet Author
API Scripter
David M. said: GiGs said: Queries do not work when sent from the API. It's not just the ? causing a problem, its that queries themselves cannot work when in a roll sent from the API. Hmm, in the thread I linked it looked like they got sendChat queries to work in certain instances with some wizardry from TheAaron. Maybe I'm misinterpreting the results of that thread. Notice in the thread, the query Aaron is referring to his here: a href=!aura tint&gt;"+state.auraTint+"&lt;/a&gt;" + "&lt;a href=!aura perc ?{Percent?|90}&gt;"+state.auraPerc+"&lt;/a&gt;" This is another script command: !aura perc ?{Percent?|90} Queries work like this, because its not being sent to chat - its being sent to the API to trigger another script. The example from this &nbsp;thread, is in a roll being sent to chat. queries won't work there.&nbsp;
1597701783
David M.
Pro
API Scripter
Got it, thanks GiGs!