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] Rest and Recovery

1589245909

Edited 1592167106
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Rest and Recovery Warlocks, and Archers, rejoice! This is a script to handle recovery of the Resource attributes on the D&amp;D 5th Edition by Roll20 sheet. To use this script, most non-class resources must include a code in their name, separated from the name by a plus sign. You can include standard dice expressions as well. "1d6" is used in all examples, but you can do 2d6+3, 3d20, etc. After it is finished, it will whisper to the person who used the command just which resources were affected and by how much. This script does not affect Hit Points, Hit Dice or any of the other things that a short or long rest does. The Companion script for the sheet handles those, and I don't want to overlap any functions. This only affects the Resource section. Here are examples of the commands given and the codes that are affected. All commands affect a selected token that represents a PC sheet. !r-short Used for Short Rest +SR &nbsp;This resource will return to its maximum value +SR1d6 &nbsp;This resource will add 1d6 to the resource up to its maximum value !r-long Used for Long Rest +LR&nbsp; This resource will return to its maximum value +LR1d6 &nbsp;This resource will add 1d6 to the resource up to its maximum value !r-charges used for restoring charges that are user-controlled, such as "at dawn" or "under a full moon". +1d6&nbsp; This resource will add 1d6 to the resource up to its maximum value !r-ammo no code is used here. The script looks for common ammo types, specifically: "Crossbow bolts", "Arrows", "Bullets", "Needles", and "Darts". It rolls 1d2 for each piece of ammo expended. If the result is a "2", the ammo is recovered, in accordance with the standard rules for D&amp;D 5e. The max and current values are adjusted to reflect the new total. !r-help This will display the basic help syntax in chat. !r-list This will list every resource that can be recovered without using a code. Almost everything from an official sourcebook is covered with the exception of ties such as Ravnica or Acquisitions, Inc. Special Cases Finally, the following special cases exist. Class Resources that have any of the following names are recognized and handled appropriately: These are recovered on a Short or Long Rest: Spell Slots, Warlock Spell Slots Channel Divinity Wild Shape Superiority Dice Ki Points, Ki These are recovered on a Long Rest. Rages Lay on Hands Sorcery Points Bardic Inspiration needs a +SR or +LR code, since the recovery rate changes at fifth level Examples: This barbarian will regain all of their rages on the command&nbsp; !r-long The archer will find 1-10 arrows on the command&nbsp; !r-ammo . That will become the new maximum. This high level warlock will regain all of their spells slots on the command&nbsp; !r-short This Wand of Fear will regain 1d6+1 charges to a maximum of 7 on the command&nbsp; !r-charges This boon will gain 1d6 charges on the command !r-short . Since it is already at maximum, it will not change. This script is now available in One Click install. Or directly from the Roll20 repo at&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/Rest-and-Recovery" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/Rest-and-Recovery</a> I'm sure that it will need some tweaking and patching. I ask patience, since I am not a particularly fast or skilled JavaScript coder. If anyone can think of common class features that I have overlooked, or variant ways to refer to them, please feel free to make suggestions. The same goes for common ammunition types. Remember that special cases can always be handled with an appropriate recovery code, though.
1589289106
Pantoufle
Pro
Sheet Author
Translator
Hey keith! That sounds really cool and quicker to set up rather than a setattr method!&nbsp; Do you handle translation? (Maybe through a setup menu?) Can you explain a bit more about how you handle ammunitions : in your exemple, 10/20... 10 is the number of arrows remaining or used? :)
1589292314
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
All of the "special" names are declared near the beginning of the script: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let shortRestList = ['Spell Slots', 'Warlock Spell Slots', 'Channel Divinity', 'Wild Shapes', 'Superiority Dice', 'Ki', 'Ki Points']; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let longRestList = ['Rages', 'Lay on Hands', 'Sorcery Points']; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let ammoList = ['Crossbow bolts', 'Arrows', 'Bullets', 'Sling Bullets', 'Needles', 'Darts']; ... so yeah, it should be pretty easy to localize without any programming knowledge. I haven't yet learned how to work with the state object, so no setup menu. The ammo algorithm is basically: Find number of spent pieces (max - current) Roll that many d2s, and then subtract that number (if you spent 10 arrows, then that's [[10d2-10]]) Add that result to the current amount and then set the max to equal the new current value. So if you started with a max of 20 arrows and shot 12 of them so that you currently had 8 remaining, the formula would be: (20-8)d2-(20-8) =&gt; 12d2-12 =&gt; ~6 (most likely result) Current = (6 + 8) = 14 Max = 14
Whoa, this is awesome! I already have my own jury-rigged long-rest and short-rest recovery macros happening (via ChatSetAttr) but eventually I'll probably want to move to this.&nbsp;
This is fantastic, keithcurtis . Looking forward to trying it out.
First I gotta say that I really like it ^^ But I ran into something that I wanted ot ask about. When I played with my group, the players couldn't use the retrieve ammo command. They would just get # followed by the macro I set up for it. Is this normal behaviour? I mean I could just use it instead of them, but thought it would be fun for them to retrieve their own shot ammo :)
1590191273
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That sounds like the macro may not being called correctly. Can you post the macro, plus whatever macro might call that macro, and describe where it is stored?
keithcurtis said: That sounds like the macro may not being called correctly. Can you post the macro, plus whatever macro might call that macro, and describe where it is stored? Sorry for replying so late but here is the macro. :) And here is the macro that calls the macro: &amp;{template:default} {{name=Player Menu}} {{ Movement=[Moving](!&amp;#13;#Move)}} {{ Actions=[Initiative](!&amp;#13;#Initiative) - [Short Rest](!&amp;#13;#Short-Rest) - [Long Rest](!&amp;#13;#Long-Rest) - [Retrieve Ammo](!&amp;#13;#Retrieve-Ammo)}} {{ Checks=[Ability](!&amp;#13;#Ability-Check) - [Skill](!&amp;#13;#Skill-Check) - [Saving](!&amp;#13;#Saving-Throws)}} {{ Money=[CashMaster](!&amp;#13;#CashMaster)}} Now seeing it again, I'm thinking it could also just be a call to the script instead of having it call a macro that calls the macro :P Hope this helps figuring out what happend (I did something wrong probably)
1590342587
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
The screen shot shows that the retrieve ammo macro is not visible to the players, i.e. it can be used only by you. Put "All Players" in the Visible to Players field and that should put you right. And yeah, those buttons are actually built with API calls in mind. Hence the rigmarole with the html replacements. Here are some useful posts for building macro systems and chat menus: Macro Character Sheet Chat Menu
Wow, I feel stupid for missing that xD Totally forgot doing that. Thanks for pointing that out. A macro character sheet sounds pretty handy, gonna look into that! Thanks again for helping and for the awesome scripts.&nbsp; &nbsp;
1590354716
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Glad it was a simple fix.
1591571171
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Update. I have gone through every official sourcebook (with the exception of some of the tie-in products like Ravnica or Acq. Inc) and added just about every ability I could find that recovers on a short or on a long rest. The script now includes a !r-list command that will give you the name of everything available. I have updated the code at the link in top post.
Hey, thanks for the cool script! I have a question: is there a reason that a token must be selected to call the help command (and the list as well)? And a second hint: you described in this post the commands as "!r-Help" but actually your script only supports "!r-help" atm. Maybe a .toLowerCase() at the if statement at the bottom of the script might improve usability :) Oh, and one other hint you might be interested in (if not ignore it :) ) - if you use while(...) {...} instead of do {...} while(...) you don't need those if-statements in the loops
1591698360

Edited 1591704309
Oh and I just discovered another bug: your script whispers the messages to only the part of the name after the first space. So I have a Character called "Astaroth Malphas" and the whisper command sends it to "Malphas". Even worse, if a player has only one word, like for one player of mine called "Meriel", I don't see any whispering in the chat at all. Edit: I think I found the solution to this: if whispering, you need to enclose the name in ""
1591715502

Edited 1591715718
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'll put those in the next version. Thanks! Fortunately, I caught the capitalization before submitting to the repo. The need for the token being selected is just laziness on my part. I added the help rather late in the writing process and just decided to tack it onto the list of routines after testing for selection had already been done. This script is now available in One Click install.
I can't seen to find this script. One click install means the script library, correct? Is it called something not obvious? Where to I find it? Daddy wants.
Same, I can't seem to find it in the API section.
1592152823
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yes, I have contacted the devs about this. It is in the official Roll20 repo, but I forgot you have to make a special request for the One-Click. I have not yet heard back. I'm still hoping it will be available by next Tuesday's merge.
1592153425
GiGs
Pro
Sheet Author
API Scripter
I didnt know you had to make a special request. I assumed it would be automatic, like the character sheet repo. That's what its for, after all.
1592156157
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
There has been talk of that, but I do not think it is the case. It's very difficult to find the info on the new Help Center.
Is there a link for a manual install in the meantime?
1592166986

Edited 1592167116
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Good catch. I have added it back into the top post, but here is the direct link: <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/Rest-and-Recovery" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/Rest-and-Recovery</a>
1592342781
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It's going to be one more week for One-Click. I missed a hoop to jump through and forgot to validate the script.json. Live and learn.
1593790991
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Now that the bug that has been keeping One-Click scripts from installing properly has been fixed by the devs, this script is now finally and truly available for quick and easy installation and updating.
1593830668

Edited 1593834616
Okay just came across this and I'm loving it. I have my own Short rest macros already but this will streamline so much. You da best. Only question I have is, is there any way to track ammo that's not one of the basic types. For example, my rogue has arrows, bolts, and a set of walloping arrows she found a while back. Could I track the walloping arrows the same way I can track the regular ones? Edit: I suppose, since the walloping arrows lose their magical property once shot, that they would be recollected as regular arrows. Which presents more complications. So i get it if that's just a "keep track yourself" kinda thing.
1593840325
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I have some ideas for that. Now that One Click is finally working, I can look into giving that capability.
I'm already editing the script to include racial abilities like the orc's Relentless Rage, tiefling's Hellish Rebuke, etc., as well as Luck Points from the Lucky feat. Any chance you will be adding these changes to the script yourself? Long rest adds so far: 'Relentless Rage', 'Arcane Recovery', 'Hellish Rebuke',&nbsp; 'Healing Light,' Short rest adds: 'Breath Weapon,'
1596349070
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yeah, if you have anything you can think of that needs adding. I have some time this weekend.
I made a list of racial abilities from non-setting specific sources, but added Genasi. Some are just spell names, like a Drow gets Faerie Fire, and Darkness once per long rest. 'Fey Step', 'Hidden Step', 'Firbolg Magic', 'Stones Endurance', 'Saving Face', 'Grovel Cower and Beg', 'Hungry Jaws', 'Fury of the Small', 'Breath Weapon', 'Necrotic Shroud', 'Radiant Soul', 'Radiant Consumption', 'Healing Hands', 'Duergar Magic', 'Dancing Lights', 'Faerie Fire', 'Darkness', 'Blessing of the Raven Queen', 'Mingle with the Wind', 'Merge with Stone', 'Reach to the Blaze', 'Burning Hands', 'Githyanki Psionics', 'Jump', 'Misty Step', 'Githerazi Psionics', 'Shield', 'Detect Thoughts', 'Control Air and Water', 'Poison Spray', 'Animal Friendship', 'Hellish Rebuke', 'Relentless Endurance', 'Luck',
1596386448
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I had decided against using spell names in the resources section, since the spell section not only seemed the likelier place, but has a field for placing innate "1/day", and source "drow magic" notations. Still, these are not technically tracked in any meaningful way, and the script is not slowed to any realistic degree by their inclusion.
I didn't know it did that. I've been adding more of the class features, but I haven't been very picky. Thank you for this script that. It was really something missing from the OGL Companion. Do you have any advice on muting that message, or changing the message to a public "so-and-so took a rest" instead? I've messed around with it and I break it everytime.
1596413766

Edited 1596418034
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
For the message, changing line 20 to&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Rest and Recovery", header + messageText + footer); will make the message public. You can change&nbsp; message text &nbsp;to whatever you want it to be.&nbsp; You can delete the line entirely if you want no message. I have added the other options to the script and it should be in next week's pull.
1596418234
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I liked your idea of putting the character name in the report. The script now does that, so you can tell whom is recovering.: you can still edit the line as above to remove the whisper. After the update it will be: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Rest and Recovery", header + '&lt;b&gt;'+(getObj('character', characterID)).get('name') + '&lt;/b&gt;&lt;BR&gt;' + messageText + footer); If you want to try it ahead of time, you can pull code from here .
1596418603
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
The Devilish DM said: Okay just came across this and I'm loving it. I have my own Short rest macros already but this will streamline so much. You da best. Only question I have is, is there any way to track ammo that's not one of the basic types. For example, my rogue has arrows, bolts, and a set of walloping arrows she found a while back. Could I track the walloping arrows the same way I can track the regular ones? Edit: I suppose, since the walloping arrows lose their magical property once shot, that they would be recollected as regular arrows. Which presents more complications. So i get it if that's just a "keep track yourself" kinda thing. Actually, I wasn't thinking the first time you asked this. For anything you put in there to be treated as ammo, just change the name like so: walloping arrows+ammo and the script will recover it using the ammo rules upon issuing&nbsp; !r-ammo Of course, you will need to change the name of the ammo resource on the attack to match.
Thanks for your work! I pulled the new code and it looks much more complete, and the change in message is working out fine. Added the " took a rest" bit before the &lt;/b&gt; so it works seamless with the new name addition. Very cool.&nbsp; I've got !longrest and !r-long built into a macro with ChatSetAttr to clear any death saves (and !r-short with the same). Both in a drop-down token macro called Rest. It's nifty. I dabble with the API and way too complicated macros every few years before I get discouraged. My next step is a "are you sure you want to rest" query to discourage accidents. Then, onward to figuring out how to add rolling short rest dice along with the !r-short macro... I'll get there.
1596555182
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
There are two other "rest" scripts that came out within two weeks after this one*. I know at least one of them does hit dice. I think the only thing mine does that isn't duplicated by one or both of them is ammo recovery. You could take a look at them. I believe they are both in the One Click. *They're like busses that way, apparently.
1598446179

Edited 1598448510
How does&nbsp;!r-ammo track the ammo that has been expended? EDIT - Figured it out. Amazing script!
1598450235
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Thank you. Ammo recovery is about the only thing this script does that is not done by the other resting scripts. (And they each have things that this one doesn't do). :D