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] Ammo - Automated ammunition management in a character attribute.

1406218910

Edited 1455064268
The Aaron
Roll20 Production Team
API Scripter
Update v0.11 -- Minor update to add formal support for inline rolls. Provides an interface to add/remove ammunition from a character's attribute. Includes full bounds checking and verification that players own the character they are adjusting. Two commands: !ammo &lt;character_id/token_id&gt; &lt;attribute_name&gt; &lt;delta&gt; -- changes the attribute by the specified delta, bounds checked. !get-represents [token_id] -- prints the character_id for the provided or selected token(s). !ammo -- by itself whispers the help: Output is posted to chat for players, and whispered to the GM: Bounds checking is not enforced for the GM, before and after values are whispered to allow manual correction if desired: Players can only change attributes on characters they can control: (GM is notified if they try to adjust characters they don't control.) Additional command for looking up character id from a token or token id (because I hate @{selected|token_id} in macros for specific characters): Git:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Am" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Am</a>... Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so, go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.
Wow, Aaron comes through again!!! I tried to do this a few weeks ago, but yeah, this clearly goes well above and beyond yet again. Anyway to add a recover function? Essentially it will check how many have been shot, and then try to recover arrows at a 50% recovering rate or something? Then it will update the maximum and current = current + found arrows? So after combat/shooting arrows, you could go " !Recover Selectedtoken attributename " ?
1406227744
The Aaron
Roll20 Production Team
API Scripter
I could definitely add that. My GM would love that feature, as he's a stickler on the 50% recovery bit. =D Probably not necessary to update the maximum, I was thinking of that as being the size of the quiver, clip, exploding goblin pin, etc..
1406227898

Edited 1406227989
The Aaron
Roll20 Production Team
API Scripter
Might make sense to pre-calculate if a bit of ammunition is lost and report on the recoverable amount, with the option to just lose them completely (if say, you're shooting off of an airship), and report it after each operation: Bob uses 1 ammo and has 15 remaining. There are 2 recoverable. Also, it might be important to setup individual loss/recover policies for each attribute or character:attribute. Daggers have a 100% recovery rate, generally, where as howitzer shells have a 0% recovery rate.
Right, is it too much to ask for? lol I don't enforce a quiver size. Silly place to draw the line???? Maximum would have to be updated unless you use another attribute to track the amount fired though, right?
1406228468
The Aaron
Roll20 Production Team
API Scripter
I didn't mention it, but if no maximum is specified, it assumes a maximum of 10000 (just for simplicity). Probably I'd end up storing recoverable ammo in the state or creating a separate attribute (&lt;attribute_name&gt;_recoverable) to store it in. Seems reasonably straight forward. I'll add it to the list.
I do wish I could update the max when I click recover though, I don't mind recover being a popup box.
1406243197
The Aaron
Roll20 Production Team
API Scripter
Sounds like a config option. =D Shouldn't be a problem.
Got it working, just passing in -1 for now, I was trying to get ?{AmmoUsed} with it . Just need the retrieve button to update the max and I'll be good to go.
I have found this to be EXTREMELY useful. Might it be possible to have it say what attribute you're modifying instead of just ammo? (I'm clueless as to how these things work!) I'm using it for one of my gunslinger players to track bullets/charges of powder in powder horn and grit with his deeds and it would be nice to be able to see which one is which.... Though I suppose it is pretty obvious that he has 54 bullets and not 54 points of grit.... You've done your country a great service Aaron!
1406385038
The Aaron
Roll20 Production Team
API Scripter
Ha! Yeah, Jarret and I were talking about that last night. Based on responses, I've got big plans for this script and adding the name is certainly one of them. I'll get an update out today.
1406390549

Edited 1406393666
The Aaron
Roll20 Production Team
API Scripter
Ok. So here's the feature request list: Add a Recover command retrieves the ammo that has been used: !ammo recover &lt;character/token id&gt; &lt;attribute_name&gt; Policy for amount to recover (0% for bullets, 50% for arrows, 100% for daggers, etc) !ammo recovery-policy &lt;character/token id&gt; &lt;attribute_name&gt; &lt;percentage&gt; Defaults to not being set (uses the attribute recovery policy) Sets the recovery policy for a specific character's attribute of the specified name !ammo recovery-policy &lt;attribute_name&gt; &lt;percentage&gt; Defaults to not being set (uses the overall policy below) Sets the recovery policy to use for attributes of a specific name !ammo recovery-policy &lt;percentage&gt; Defaults to 100% Sets the overall recovery policy that is applied by default Show name of the attribute !ammo name &lt;character/token id&gt; &lt;attribute_name&gt; "What to call it" Sets what is displayed for a specific character's attribute of a specific name Default to not being set (uses attribute specific name) !ammo name &lt;attribute_name&gt; "what to call it" Sets what is displayed for all attributes of a specific name Defaults to not being set (uses overall name below) !ammo name "what to call it" Sets what is displayed overall for any attributes Defaults to the name of the attribute Option for updating the maximum number !ammo recovery-updates-maximum Does this need attribute and character/attribute specific versions like policy does? Option for displaying the available ammo !ammo check &lt;character/token id&gt; &lt;attribute_name&gt; Shows the available ammo... =D
I am soo looking forward to this, with your expansions I'll be able to use this one script and some clever macros to update hitpoints, ammo, grit, ki, spells per day and all kinds of goodies. Thank-you in advance.
1406428042
The Aaron
Roll20 Production Team
API Scripter
Very cool. If you need something else I didn't list, just let me know, I'm happy to try and add about anything, or write another script if it's not thematically appropriate for this one. :)
I'm running into massive bugs right now with it not updating, I don't know if I got your latest or not, I tried to click on the gist and copied it, is this stuff in yet?
Just seems I messed up a token, I've tried deleting the attribute holding the value, but it doesn't seem to fix the bug. I'm not sure I can save it for that character sheet. I killed a character in my game from using it! lol
1406438429
The Aaron
Roll20 Production Team
API Scripter
No, that's my feature list. I hope to add it in the morning. Sorry for the confusion, I was just trying to make a list of everything people were asking for so I'd have a punch list to work from. Just so I'm clear, you aren't having any issues with the 0.1 features listed in the original post, right?
1406438480
The Aaron
Roll20 Production Team
API Scripter
Say what?!?
I created a duplicate version, then modified it to rename it as retrieve, and have that working to reset the ammo to the ammount that you retrieved (sets both current and max). Seems good now. However I am having an issue with the carry again, sigh. {"_id":"-JSsshUsej-m9bFGztML","_pageid":"-JH7cY5wBbQTCUzaH-Sg","left":3115,"top":5845,"width":70,"height":70,"rotation":0,"layer":"objects","isdrawing":false,"flipv":false,"fliph":false,"imgsrc":"<a href="https://s3.amazonaws.com/files.d20.io/images/6671/thumb.png?13363453504&quot;,&quot;name&quot;:&quot;vTorch&quot;,&quot;gmnotes&quot;:&quot;&quot;,&quot;controlledby&quot;:&quot;all&quot;,&quot;bar1_value&quot;:&quot;&quot;,&quot;bar1_max&quot;:&quot;&quot;,&quot;bar1_link&quot;:&quot;&quot;,&quot;bar2_value&quot;:&quot;&quot;,&quot;bar2_max&quot;:&quot;&quot;,&quot;bar2_link&quot;:&quot;&quot;,&quot;bar3_value&quot;:&quot;&quot;,&quot;bar3_max&quot;:&quot;&quot;,&quot;bar3_link&quot;:&quot;&quot;,&quot;represents&quot;:&quot;-JSKT-qu1dFg2rUhTkXY&quot;,&quot;aura1_radius&quot;:&quot;&quot;,&quot;aura1_color&quot;:&quot;#FFFF99&quot;,&quot;aura1_square&quot;:false,&quot;aura2_radius&quot;:&quot;&quot;,&quot;aura2_color&quot;:&quot;#59E594&quot;,&quot;aura2_square&quot;:false,&quot;tint_color&quot;:&quot;transparent&quot;,&quot;statusmarkers&quot;:&quot;&quot;,&quot;showname&quot;:true,&quot;showplayers_name&quot;:true,&quot;showplayers_bar1&quot;:false,&quot;showplayers_bar2&quot;:false,&quot;showplayers_bar3&quot;:false,&quot;showplayers_aura1&quot;:false,&quot;showplayers_aura2&quot;:false,&quot;playersedit_name&quot;:true,&quot;playersedit_bar1&quot;:true,&quot;playersedit_bar2&quot;:true,&quot;playersedit_bar3&quot;:true,&quot;playersedit_aura1&quot;:true,&quot;playersedit_aura2&quot;:true,&quot;light_radius&quot;:&quot;40&quot;,&quot;light_dimradius&quot;:&quot;20&quot;,&quot;light_otherplayers&quot;:true,&quot;light_hassight&quot;:false,&quot;light_angle&quot;:&quot;&quot;,&quot;light_losangle&quot;:&quot;&quot;,&quot;sides&quot;:&quot;&quot;,&quot;currentSide&quot;:0,&quot;lastmove&quot;:&quot;3115,5775&quot;,&quot;_type&quot;:&quot;graphic&quot;,&quot;_subtype&quot;:&quot;token&quot;,&quot;_cardid" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/6671/thumb.png?13363453504","name":"vTorch","gmnotes":"","controlledby":"all","bar1_value":"","bar1_max":"","bar1_link":"","bar2_value":"","bar2_max":"","bar2_link":"","bar3_value":"","bar3_max":"","bar3_link":"","represents":"-JSKT-qu1dFg2rUhTkXY","aura1_radius":"","aura1_color":"#FFFF99","aura1_square":false,"aura2_radius":"","aura2_color":"#59E594","aura2_square":false,"tint_color":"transparent","statusmarkers":"","showname":true,"showplayers_name":true,"showplayers_bar1":false,"showplayers_bar2":false,"showplayers_bar3":false,"showplayers_aura1":false,"showplayers_aura2":false,"playersedit_name":true,"playersedit_bar1":true,"playersedit_bar2":true,"playersedit_bar3":true,"playersedit_aura1":true,"playersedit_aura2":true,"light_radius":"40","light_dimradius":"20","light_otherplayers":true,"light_hassight":false,"light_angle":"","light_losangle":"","sides":"","currentSide":0,"lastmove":"3115,5775","_type":"graphic","_subtype":"token","_cardid</a>":""}
dang script is hard to work with sometimes, I should probably switch it over to selected token from token name, another silly issue on my part.
1406514907
The Aaron
Roll20 Production Team
API Scripter
I was hoping to work on this script all weekend, but everything else apparently was happening. =/ Maybe in the morning.
Well my next group doesn't run until Sunday, so no need to rush. :) But as always, thank you!
1406640042
The Aaron
Roll20 Production Team
API Scripter
Yeah, hoping to have time to work on this and other scripts this weekend. :)
Love this script. Was wondering how to deal with the headache on the pathfinder sheet, of having a powercard macro for abilities etc that calculated uses remaining but did not update the field. I know my players would see the 6 max, 5 remaining part of the macro and think to themselves "great it's updated already" then conveniently not notice the next time when it once again said 6 max, 5 remaining :)
1407186654
The Aaron
Roll20 Production Team
API Scripter
Cool! I've got a bunch of plans for this script. Let me know if there are any other features it should have.
It's pretty good. I also made an updater one to go with it. It adds the ammo you find (arrows) to the currentl, and resets the max and the current to that value. Together they make a good one 2 punch.
hmmm not sure what happened between this morning and this evening. I had the script calculating and modifying the repeating_class-abilities_0_used field and now when i try and run the exact same macro it tells me attribute [] cannot be found :(
Yeah, I think the more people try to work with the repeating fields, the more issues you run into. I'm not sure what sheet you are using, but I have intentionally set "ammo" sections. (non-repeating)
pathfinder sheet, with my power cards macros thrown in. The items, class abilities, feats etc all have fields for max uses and currently used. The power card macro displays the max uses and displays uses remaining but it is only showing uses remaining with the formula @{used}-1, there is nothing to actually set the uses remaining without manual intervention. I had hoped to have this script do the actual changing of the attribute and it was doing this last night so I am not sure why it can't find the attribute today. I realise repeating sections are difficult but once a value has been given they should be visible. If i simply type in @{selected|repeating_class-abilities_0_used} i get the value so I know it is there.
1407239610
The Aaron
Roll20 Production Team
API Scripter
If you want to PM me a join link and GM me, I'll try and debug it for you.
nevermind, i got it working again. I tried retyping it all out for the 10th time and it worked, so must have consistently typo'd it or something :/
1407244556
The Aaron
Roll20 Production Team
API Scripter
There may be a bug in the API with repeated fields for character sheets. I feel like I've had similar inconsistent behavior from it in the past...
1407248545

Edited 1407250359
I won't touch using the API against repeated fields with a 10 foot pole. I run into enough other bugs with attributes there / not there, miss handled attribute scores etc. The can of worms that is repeated fields is just too dangerous to go near.
1407248786
The Aaron
Roll20 Production Team
API Scripter
When I get some free time (hahahaha) I'll have to see if I can duplicate the attributes issue and settle if it's transient or not. Maybe I should add logic to this script that checks for the attribute but creates it if it's not there already. hmm.... that actually wouldn't be too hard. What do you all think?
Oh, I do have a change request. Since I use this for all sorts of fields, not just ammo, for when it whispers the player have it whisper the ammo attribute name instead of "ammo" ? Creating it can be dangerous, maybe it should send an additional message to the user/DM to notify the attribute has been created???? I'm just worried that it would be using a phantom field that a character sheet for instance isn't attached to, and that can be hard to debug/figure out if the script is automatically creating a new one if you accidently tried for it to use an existing one that you use other macros for.
1407252450
The Aaron
Roll20 Production Team
API Scripter
Your first request is already noted above: <a href="https://app.roll20.net/forum/post/1034829/#post-10" rel="nofollow">https://app.roll20.net/forum/post/1034829/#post-10</a>... Probably having a message stating that the attribute was not found but can be created automatically, along with a command to do that would be a good idea.
I would like to humbly request that it be able to handle dice expressions. Like 3df or 1d4+1. As I plan on replacing a few macros that do specific things with this all in one, once it is up and running. :) Again, thank you for all your hard works.
1407972541
The Aaron
Roll20 Production Team
API Scripter
Sounds like a plan. I've been meaning to explore writing a general purpose parser for the dice expressions. :)
Good request. I was having to work around when I am doing things like 1d6+?{rechargemodifier} as a separate chat roll, then had !ammo take a ?{recharge#}. I didn't even think to just ask Aaron. I think we should start a new phrase, "What would Aaron do?"
1408014834

Edited 1409840109
The Aaron
Roll20 Production Team
API Scripter
Ha! Aaron would add: if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ m['$[['+k+']]']=v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } at line 111 for the moment, then he'd integrate the same code more thoroughly after GenCon.. =D You can add that code to any script before it starts parsing msg.content to allow simple dice expressions. Enjoy!
Will that just accept 1d6, etc? Or will it accept 1d6+5 for instance as well?
1408020805
The Aaron
Roll20 Production Team
API Scripter
Anything in [[ ]] with a numeric value.
1409599317

Edited 1409600384
Paul S.
Sheet Author
API Scripter
Hey there Aaron. I've taken your script and modified it slightly (very) to be a universal tracker (for spells, wands, ammo, etc...) You name it - if there is an attribute in a character journal with values - it can track it. Loved your original script but thought it could be so much better with added ability to track all things. Hope you like it. I created three macros for tracking spells, ammo, and wands. !tracker @{selected|token_id} ?{Name of Wand?} ?{Charges used?|1} etc... Requires a GM to know the name of the attribute field for all items he/she desires to track. Hopefully the below link works... <a href="https://github.com/happywanderer/Tracker-API/blob/" rel="nofollow">https://github.com/happywanderer/Tracker-API/blob/</a>...
1409602162
The Aaron
Roll20 Production Team
API Scripter
Cool! I'm looking forward to comparing! :)
1409839868

Edited 1409839977
The Aaron
Roll20 Production Team
API Scripter
@Paul - Ok, so you basically just renamed it and changed all the references to 'Ammo' to refer to Tracker and made the messages more generic? I think you have an error on line 37: sendChat('Tracker', (isGM(playerid) ? ' ' : '') It should probably be: sendChat('Tracker', (isGM(playerid) ? '/w gm ' : '') Also, since you removed the showHelp() function, you'll probably want to remove the call to it on line 119. Finally, you should change the first line to: // GITHUB: <a href="https://github.com/happywanderer/Tracker-API/blob/" rel="nofollow">https://github.com/happywanderer/Tracker-API/blob/</a>... Nice mod! I think people will find it handy. =D Cheers!
1409926455
Paul S.
Sheet Author
API Scripter
Yep - like I said VERY slight modification. Makes it universal.
1409926710
The Aaron
Roll20 Production Team
API Scripter
cool. =D If there are any features that are missing from making it universal, let me know and I can help you add them. =D
Would be good to see the features you listed earlier, the recovery policy and such.
1413574859
The Aaron
Roll20 Production Team
API Scripter
I'll try to work on those this weekend. I've done some of the work already.
1414246204

Edited 1414246236
@ roll 20 mods/admins, Just hire TheAaron onto the team already, it would make your lives easier lol
1414265961
The Aaron
Roll20 Production Team
API Scripter
=D Thanks for the kind words, Dustin!