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

[Script] 5eShapedSpellBook

1442693969

Edited 1443871274
Lucian
Pro
API Scripter
Updates 0.4 2015-10-03: Re-enabled&nbsp; spell_data_hash checking - see below for more details, you need to change how you install the script Added experimental extension mechanism for the brave. (Requires October 2nd 2015 version of 5e-shaped character sheet - but see below) 0.3.1 2015-09-25: &nbsp; &nbsp;Disabled spell_data_hash checking - shouldn't be enabled yet, sorry! (Requires September 20th 2015 version of 5e-shaped character sheet) 0.3 2015-09-24: Introduced more robust system for tracking changes to 5e-shaped character sheet. Fixed some minor issues around values drawn from selects (attack stats, save stats etc) (Requires September 20th 2015 version of 5e-shaped character sheet) 0.2.2 2015-09-22: Fixed bug with attack spell rendering. &nbsp; Fixed bug with higher level damage dice calculation being broken by bad interpolation &nbsp;&nbsp;(Requires September 20th 2015 version of 5e-shaped character sheet) 0.2.1 2015-09-21: Added one missing attribute (Requires&nbsp; September 20th 2015 version of 5e-shaped character sheet) 0.2 &nbsp; &nbsp;2015-09-21: Added long rest handling 0.1 &nbsp; &nbsp;2015-09-20: Initial version IMPORTANT NOTE: This script requires special installation, please read the instructions carefully! So I finally got fed up with not being able to do anything useful with the spells on the 5e-shaped sheet without always having to navigate into the sheet itself, thanks to the evils of repeating sections. I've made a spellbook script that reads all of your spells from the character sheet and then spits out buttons for them in the chat window. The buttons are enabled/disabled depending on whether you have the spells prepared + have appropriate slots to cast them. When you click on the buttons it will prompt you for a spell level to cast at if this is appropriate (either because the spell has higher-level effects and you have available slots to cast at higher level, or because you only have higher-level slots left), and will also prompt you for a target, if appropriate to the spell. When you click one of the spell buttons it casts pretty much as it would do from the character sheet.&nbsp;Additionally, it will decrement your spell slots (warlock ones first, normal ones afterwards) appropriately. It's currently at beta quality level, and doesn't have proper documentation so I haven't put in a pull request to Roll20, but if you're interested you can check it out here:&nbsp; Github Link Installation You need to install the files&nbsp; 5eShapedSpellbook.js&nbsp; and&nbsp; LHU.js&nbsp; into your campaign. In addition, you must grab the file&nbsp; spellDefaults.js from the repository for the 5e shaped character sheets. You must use the file from exactly the same version of the sheet's repository as the HTML and CSS files that you have installed for your campaign. The recommended approach it to install spellDefaults.js &nbsp;whenever you install the HTML and CSS files for the 5e shaped sheet. The spellDefaults.js &nbsp;file contains important information that is auto-generated from the shaped sheet that allows the spellbook script to work correctly. The spellbook script will check that you are using the right version and will issue an error message if there is a mismatch between the spellDefaults.js &nbsp;file and the HTML/CSS of the character sheet that you are using. Commands: !5esb --show &nbsp;shows the spellbook for the selected token !5esb --cast &lt;Spell name&gt; [--ritual] [--level &lt;lvl&gt;] --character &lt;character_id&gt; [--targetAC @{target|AC}] [--targetName &lt;name&gt;] Casts a spell. Will only work if you have appropriate slots to cast the requested spell at the requested level. The targetAC parameter is designed to parse the results of requesting AC using the @{target|AC} syntax, any other value won't work here. !5esb --long-rest &nbsp;restore spell slots as for a long rest for the selected token It should go without saying that this is designed to work with the 5eShaped sheet only (the latest version from GitHub, not the default one on Roll20), and you probably also want the spell importer that goes with the sheet to get the best value out of it: <a href="https://github.com/mlenser/roll20-character-sheets" rel="nofollow">https://github.com/mlenser/roll20-character-sheets</a>... <a href="https://github.com/mlenser/roll20/blob/master/scri" rel="nofollow">https://github.com/mlenser/roll20/blob/master/scri</a>... Future ideas: put in short rest mechanics for slot recovery for warlocks + arcane recovery for others Document it Support daily/at will spell powers from various class features / MM Innate Spellcasting feature Provide some sort of extension mechanism to allow API scripts to be triggered from spells (e.g. Mage Armor actually switches on your Mage Armor) Lucian
1442773343
Lucian
Pro
API Scripter
Small update: Improved the rendering (now grouped into levels) Added spell slot display.&nbsp; You also get hover text that indicates what slots are available to cast a spell. Warlock spell slots now work properly (damn calculated fields!) Displays both ritual and non ritual buttons for a spell where appropriate Cheers, Lucian
1442774224
Kryx
Pro
Sheet Author
API Scripter
Looks great. I'm curious how you work around all the issues of accessing an input in a repeating section (it's null until something edits it).
1442777210
Lucian
Pro
API Scripter
Kryx said: Looks great. I'm curious how you work around all the issues of accessing an input in a repeating section (it's null until something edits it). It's really dirty. I mean really &nbsp;dirty. :-) I took all of your hidden inputs that hold expansions for the toggles + default values, and I converted them into JSON which I then pasted into the script. I build a spell object by cloning the JSON of the default values, then I overwrite/supplement them with all attributes I can find starting with "repeating_spellbook", and then I run cycles of interpolating from the map of toggle expansions until no more replacements are made. Then I fill in anything that's missing from the character attributes. It's not pretty, but it kind of works. The biggest limitation is that a bunch of the inline roll expressions that work for you when run from the sheet don't work properly when run through sendChat. I've cludged and fudged my way round some of them, but there are some that have me stumped - there's a thread on the bugs forum about some of them. The one saving grace is that the copy-pasta of the bits from your script could almost certainly be automated, so I could dynamically produce an updated version when you update the sheet. In fact, if we were getting really fancy, I could give you a gulp fragment to include in your build. When you release it would generate a .js file which I could reference from my script. It's a terrible solution, but it's all I could think of doing. I tried an experimental session with a friend who has never used a VTT before the other day. His computer is fairly old and slow, and having to open the character sheet every time he wanted to cast a spell was the one thing that really turned him off, so I figured I should find some solution for the time being. Hopefully Riley will listen to our pleas soon and fix the repeating sections thing so this all goes away. Lucian
1442777800
Lucian
Pro
API Scripter
... and to give you an example of how downright nasty it ended up getting, I gave up on trying to get your AC expression to resolve through sendChat and resorted to replacing "floor" and "abs" with "Math.floor" and "Math.abs" and called eval() on it. If that's not evil, I don't know what is...
1442779982
Kryx
Pro
Sheet Author
API Scripter
Lucian H. said: It's really dirty. I mean really &nbsp;dirty. :-) I took all of your hidden inputs that hold expansions for the toggles + default values, and I converted them into JSON which I then pasted into the script. I build a spell object by cloning the JSON of the default values, then I overwrite/supplement them with all attributes I can find starting with "repeating_spellbook", and then I run cycles of interpolating from the map of toggle expansions until no more replacements are made. I can't read any more. shudder
1442780641
Lucian
Pro
API Scripter
Kryx said: I can't read any more. shudder Hahaha. Perhaps if we send Riley the code, the horror of it will make him cave in and fix the repeating sections things? ;-)
1442781188
vÍnce
Pro
Sheet Author
Lucian H. said: Kryx said: I can't read any more. shudder Hahaha. Perhaps if we send Riley the code, the horror of it will make him cave in and fix the repeating sections things? ;-) We need some fixes/upgrades for repeating items in a BIG way. &nbsp;It would help sheet authors tremendously!
Your links don't lead to this fabled script? :o
You have a stop/period on the end of your address :&lt; Also nothing seems to happen when I use !sb --show&nbsp;
1442781900
Kryx
Pro
Sheet Author
API Scripter
Also, FYI, you've linked to the wrong 5e sheet on my github. :P
1442782005

Edited 1442782230
Lucian
Pro
API Scripter
All round epic fail. Sorry guys, just fixing the links now. [Done]. This is what happens when you stay up too late staring at javascript and broken roll queries :-/
Haha its fine, its an awesome script! Considering the very few number of "Attack Roll" spells outside of Cantrips which can be very easily turned into buttons anyways. Its really good :)!!
1442790907

Edited 1442791439
Interesting script. Would it be possible to make it work with spell points instead of slots? I also keep getting the following error out of it. evalmachine.&lt;anonymous&gt;:18222 var targetParam = spellNeedsTarget(spell) ? " --targetAC " + LHU.ch('@') + ^ TypeError: Object #&lt;Object&gt; has no method 'ch' at getSpellButtonText (evalmachine.&lt;anonymous&gt;:18222:74) at evalmachine.&lt;anonymous&gt;:18197:35 at Array.reduce (native) at Function._.reduce._.foldl._.inject (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:113:28) at _.(anonymous function) [as reduce] (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:1073:39) at evalmachine.&lt;anonymous&gt;:18132:18 at evalmachine.&lt;anonymous&gt;:18399:13 at evalmachine.&lt;anonymous&gt;:18412:21 at evalmachine.&lt;anonymous&gt;:18365:21 at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:81:22)
1442792639
Lucian
Pro
API Scripter
Brother Sharp said: Interesting script. Would it be possible to make it work with spell points instead of slots? In principle I see no reason why not. In many ways it's a whole lot easier than slots because you only have to keep track of one resource pool rather than 9. The only tricky thing would be the rule that says you can only cast one spell of each of 6-9th levels / long rest. We'd need to use class resources with a agreed names to keep track of that. It's probably going to be a week or so before I do much more on this, though, because I have to move house now and my fiancee probably won't be impressed if I make her do all the packing :-) I also keep getting the following error out of it. evalmachine.&lt;anonymous&gt;:18222 var targetParam = spellNeedsTarget(spell) ? " --targetAC " + LHU.ch('@') + ^ TypeError: Object #&lt;Object&gt; has no method 'ch' at getSpellButtonText (evalmachine.&lt;anonymous&gt;:18222:74) at evalmachine.&lt;anonymous&gt;:18197:35 at Array.reduce (native) at Function._.reduce._.foldl._.inject (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:113:28) at _.(anonymous function) [as reduce] (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:1073:39) at evalmachine.&lt;anonymous&gt;:18132:18 at evalmachine.&lt;anonymous&gt;:18399:13 at evalmachine.&lt;anonymous&gt;:18412:21 at evalmachine.&lt;anonymous&gt;:18365:21 at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:81:22) Hmmm. Sounds like possibly you have a mismatched version of the LHU utilities script perhaps. I have just pushed a new version of both files, do you want to try updating both files and see if it works now? Cheers, Lucian
Thanks Lucian! Some more things I found while testing is that, this does not seem to take into account the bonuses from casting stats and higher level queries. The following is copy pasted from the API output; "Error: No attribute or sheet field found for character_id -JxoOGOVO3dNi4w6EasO named spell_var_higher_lvl_query" "Error: No attribute or sheet field found for character_id -JxoOGOVO3dNi4w6EasO named healbonus" "ERROR: Unable to find character spell_var_higher_lvl_query in chat command." and so on. They work properly when cast from the character sheet without using the API.
1442824755
Lucian
Pro
API Scripter
Hi, Aha, yes, thanks to the truly awful way that I had to implement this script, there may be some pieces missing that I need to copy over from the character sheet. As mentioned above, I'm hoping to automate this process so it's less error prone. I'll add the ones in that appear to be missing from your message above. Will post an update here when it's done. If you have more problems with the spell casting, one thing that would be really useful is if you can post the command that was used to cast the spell (push up arrow in the chat window to get this) along with the API logs. Makes it easier for me to reproduce the issue reliably. Cheers, Lucian
1442853297

Edited 1442853704
Lucian
Pro
API Scripter
Brother Sharp said: Thanks Lucian! Some more things I found while testing is that, this does not seem to take into account the bonuses from casting stats and higher level queries. The following is copy pasted from the API output; "Error: No attribute or sheet field found for character_id -JxoOGOVO3dNi4w6EasO named spell_var_higher_lvl_query" "Error: No attribute or sheet field found for character_id -JxoOGOVO3dNi4w6EasO named healbonus" "ERROR: Unable to find character spell_var_higher_lvl_query in chat command." and so on. They work properly when cast from the character sheet without using the API. Hey again, So I've pushed a new version with one missing attribute added, but at least some of the problem stems from the fact that you aren't using the latest version of the 5e-shaped character sheet. Thanks to the downright horrible way that I was forced to implement this script, it is very &nbsp;dependent of having exactly &nbsp;the right version of the character sheet to work with. You need to update to the latest version direct from Mark's github repository linked in the original post. For anyone trying to sort out problems with this script, I can't stress enough how important it is to use the right version of the character sheet. To avoid confusion I will make explicit the version I'm expecting for each version of my script in the first post at the head of the thread. Cheers, Lucian
1442854056
Kryx
Pro
Sheet Author
API Scripter
Lucian H. said: To avoid confusion I will make explicit the version I'm expecting for each version of my script in the first post at the head of the thread. This is the best way to handle it, ya. Users can always get old versions of the sheet or script via github.
1442854275
Lucian
Pro
API Scripter
Kryx said: This is the best way to handle it, ya. Users can always get old versions of the sheet or script via github. Hey, It occurs to me that the other thing I could do is to actually warn the user explicitly if it finds the wrong version of the character sheet. Is there any chance you could put a hidden field at the root of the character sheet with a version/date in so that I can request the attribute and spit out a warning in the chat if it's not what I'm expecting? Cheers, Lucian
Awesome script man. Any chance someone want's to tackle this for the Pathfinder sheet next :P
1442879914
Lucian
Pro
API Scripter
Version 0.2.2 I have fixed one of the most annoying bugs - the broken roll display for attack-based spells. Anyone who has used the API to process complex roll strings with lots of inline rolls will have experienced frustration at the unpredictable behaviour. In particular, if you used nested inline rolls, things break a *lot*. So, after trying lots of nice, sensible approaches, like trying to establish what exactly the parser liked and didn't, I finally did what I do best, and went for the 'orrible ugly 'ack solution: removeNestedRolls = function(rollTemplate) { var nestLevel = 0; var re = /(?:\[\[|\]\])/g; return rollTemplate.replace(re, function(match) { if (match === '[[') { return (++nestLevel &gt; 1) ? "" : "[["; } else { return (--nestLevel &gt; 0) ? "" : "]]"; } }); } I'm off to have a long shower now to try and get rid of the dirty feeling :-( This version also fixes a bug whereby spells with higher level damage dice expressions weren't getting their proper damage. I had accidentally interpolated the text "Level &lt;higherLevel&gt;" rather than just "&lt;higherLevel&gt;" into the calculation, which was breaking things. Amazing that the API will happily sail past a random bit of text in the middle of a calculation silently, but falls over in a heap if you dare to include a space between the opening square brackets and the first expression. There's no parser in there, it's just Dice Goblins, I tell you. Cheers, Lucian
Well done sir! Well done! Another amazing script! +5 xp
1443117092
Lucian
Pro
API Scripter
Version 0.3 Recoded the way that I deal with sucking in default attributes from the 5e-shaped sheet. Rather than manually hard-coding these into the script I now have a build file that generates a separate .js that contains all the default values from the sheet. If&nbsp; Kryx is amenable to the idea this could potentially be incorporated into the build for his sheet so that a corresponding .js can be released along with each version of the sheet to ensure that new versions don't always break this script. From this point onwards you will need to install an additional .js to use this script, named spellDefaults.js.
Hi Lucian, Script looks great but I keep getting this error after installing: "Error: No attribute or sheet field found for character_id -JwUGHUbrHnOU45AVC3A named spell_data_hash" However, I am using the latest version of the Shaped 5e Sheet (Sept 20th version). Any idea what could be the matter? Thanks
1443175043
Lucian
Pro
API Scripter
Hi Ryan, Sorry, my bad, I enabled a feature that wasn't ready yet (supposed to ensure that the character sheet and script are compatible). I have pushed a new version to my GitHub with this disabled and it should work for you now. Lucian
1443872128
Lucian
Pro
API Scripter
Version 0.4 Kryx&nbsp;has now added &nbsp;some stuff to his repository that allows me to handle versioning more robustly. From this point on, you need to install two files from my repository (5eShapedSpellbook.js and LHU.js) and an additional one from his (spellDefaults.js) - links in the description in the original post. The script will automatically fail if the wrong versions are being used, and the spellDefaults.js is automatically generated from Kryx's character sheet build so it should always have the correct data. From this point onwards, I won't normally be specifying which versions of the character sheet are required, because this should be taken care of by the auto-generation mechanism. I have also committed the start of my extension system, that allows additional behaviour to be plugged in for specific spells. See the file 5eCustomSpellHandlers.js for an example of how I'm thinking about handling this - but use at your own risk because it's very early days yet!
Great stuff. Looking forward to watching this project grow!
1444141101
Cosmic
Sheet Author
I am not sure, is this just me, I added all scripts listed. I had a "unexpected token" error when saving the sandbox. I did the same with just saving&nbsp;5eShapedSpellbook.js and had the same error. Nice script. Hard work, but well worth it !&nbsp;
1444310403
Lucian
Pro
API Scripter
Alexander said: I am not sure, is this just me, I added all scripts listed. I had a "unexpected token" error when saving the sandbox. I did the same with just saving&nbsp;5eShapedSpellbook.js and had the same error. Nice script. Hard work, but well worth it !&nbsp; Hi Alexander, This is a recurring problem with all Roll20 scripts. Try this: Open your campaign in one tab Open the script editor page in another tab Position the cursor at the end of the last line of the script and hit enter Save the script Hopefully you will see all of your scripts reload successfully. It's a weird bug that has been around for some time now, it seems to happen more or less frequently at different times :-/ Lucian