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

[Help] Mana bar tracker

Hello there! I don't know how to program an API if it where to safe my life ... so I wondered whether there is somebody here to help me, because there is one thing and one thing only that I wanna add to the API and that is the following. I added a Spell Book to my sheet and it has a Cast button, that has the following Value (this is for the level 2 spells, which is why there is a 2 in all the attribute): "&{template:default} {{name= CASTING}} {{Spell Name= @{spell2name}}} {{Spell level= [[1]] (@{Class})}} {{Type= @{spell2type}}} {{Spec./Sign.= @{spell2spec}}} {{Success= [[d20]] vs TN[[@{spell2stat}@{spell2TNmod}]]}} {{Cost= [[@{spell2cost}@{spell2manamod}]] Mana}} {{Heals/Deals= @{spell2healdeal}}} {{Range= @{spell2range}}} {{Components= @{spell2comp} (@{spell2complist})}} {{Duration= @{spell2dur}}} {{CastingTime= [[@{spell2speed}]]}} {{AOE= @{spell2aoe}}} {{Save= @{spell2save}}} {{Effect= @{spell2eff}}} {{Limit= @{spell2limit}}}" Easy enough, right? It's a roll template ... Now I would really like this part {{Cost= [[@{spell2cost}@{spell2manamod}]] Mana}} to automatically deduct the Mana from the mana bar. The value connected to the bar is @{MP} on the sheet, but I dunno how to do it ... people are supposed to type in stuff list 2d4 into the spell cost field and stuff like -1 into the manamod field, so [[@{spell2cost}@{spell2manamod}]] would end up being [[2d4-1]] ... I tried to abuse the ammo tracker for that, but it won't work (probably because I have no idea on how  to make it work, so if there is a way, please let me know). Help, please? xoxo, Shin
1462738280
The Aaron
Pro
API Scripter
So, the amount you'll be changing by is variable for each casting of a given spell, or fixed?   For example, you list [[@{spell2cost}@{spell2manamod}]] as resulting in [[2d4-1]] Can you go into a bit more detail about that?
1462739805

Edited 1462739873
It's variable because each spell casting costs a certain amount of d4 +/- modifiers depending on class, specialization, etc. ... So for example players would fill out for a 2ndlevel spell specialized 2d4 into the field that I named spell2cost and -2 into the field I named spell2manamod ... which then would roll 2d4-2 ... so yeah ... it's variable. :) LVL 3 spell fields are all named spell3 somethingsomething , LVL4 spell4 somethingsomething , etc. - mostly because I split the lists by levels and made one extra section for special abilities. Edit: so the idea is to take the result of the manacost roll and deduct it from the mana-bar. :)
1462821512

Edited 1462821606
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'm sure Aaron will point this out in a bit, as it's his script, but I think you could use his  ammo script for this. I just tried it in my sandbox and a syntax like this works: !ammo @{selected|token_id} Ammo -[[2d4]] This results in the Ammo stat being reduced by whatever the result of the roll is. You would not be able to put this directly in your roll template though as it requires the API call. Your template could be rolled into a macro and read like this: &{template:default} {{name= CASTING}} {{Spell Name= @{spell2name}}} {{Spell level= [[1]] (@{Class})}} {{Type= @{spell2type}}} {{Spec./Sign.= @{spell2spec}}} {{Success= [[d20]] vs TN[[@{spell2stat}@{spell2TNmod}]]}} {{Cost= @{spell2cost}@{spell2manamod} Mana}} {{Heals/Deals= @{spell2healdeal}}} {{Range= @{spell2range}}} {{Components= @{spell2comp} (@{spell2complist})}} {{Duration= @{spell2dur}}} {{CastingTime= [[@{spell2speed}]]}} {{AOE= @{spell2aoe}}} {{Save= @{spell2save}}} {{Effect= @{spell2eff}}} {{Limit= @{spell2limit}}} !ammo @{selected|token_id} MP -[[@{selected|spell2cost}@{selected|spell2manamod}]] The roll template would no longer give what the roll is, but the functionality of automatically adjusting the MP value would work. Note that the template no longer has an inline roll for the cost. I do something similar to this in my pathfinder game, using Ammo to deduct spells per day each time a character casts something and using a Rest Macro to automatically reset the values. Sorry if I stepped on your toes Aaron. Scott C.
1462821877
The Aaron
Pro
API Scripter
No, totally great of you to mention that, accidentally marked everything as read this morning and missed this reply.  The major point as a takeaway is the fact that you'd need to move the roll down to the call to !ammo, not the roll template.  You might report in the roll template what is going to be rolled, then let the !ammo message tell you how much was actually used.
There might be another problem ... there is not just one spell#cost and spell#manamod field. The spell book is within <fieldset></fieldset> so there will be multiple of those if the player added several spells to his spellbook for that spell level: Don't judge me ... I know it's ugly at the moment, but it serves the purpose. I'll care about design later. It works for the roll template, no problem ... but !ammo @{selected|token_id} MP -[[@{selected|spell2cost}@{selected|spell2manamod}]] will not work, unless you can tell me how to make it pick that exact spell that got rolled. I tried to make it pull !ammo with a query, but that doesn't seem to work either: !ammo @{selected|token_id} MP -[[?{Spent Mana|1}]] The idea is (as a workaround) that if I can't do it automatically, that the player at least gets a prompt since the roll template will go out first anyway and then it will pull !ammo, right? He will already see what the result of the roll is and can enter the number into the query. But that is not that different from the player adjusting the number by himself. So meh ... :/
1462878713

Edited 1462878739
The Aaron
Pro
API Scripter
Try using just:  !ammo @{character_id} MP -[[@{spell2cost}@{spell2manamod}]]
Naw, it doesn't work. I get: TypeError: c is undefined :(
Shin Von Nibelung said: I get: TypeError: c is undefined :( Attribute calls (e.g. @{AC}) that are not placed within one of tabs of a Character Window (e.g. within a field on the Character Sheet Tab or within an Ability on the Attributes & Abilities Tab ) must use a keyword to let the parser know which Character you intend to call that Attribute from (e.g. @{selected|AC}). Using a Selected Token with a Macro Using a Targeted Token with a Macro
Silvyre said: Shin Von Nibelung said: I get: TypeError: c is undefined :( Attribute calls (e.g. @{AC}) that are not placed within one of tabs of a Character Window (e.g. within a field on the Character Sheet Tab or within an Ability on the Attributes & Abilities Tab ) must use a keyword to let the parser know which Character you intend to call that Attribute from (e.g. @{selected|AC}). Using a Selected Token with a Macro Using a Targeted Token with a Macro That's why I mentioned that the spell book fields are within <fieldset></fieldset>; aka they don't have an entry within the Character Sheet Tab. So my question was whether there is a way to take the rolled result from the macro and deduct it from the mana bar ... and I don't think that !ammo can be really used to achieve that. There will be potentially over 100 spells inside that spell book and most of them will have the same field name because <fieldset></fieldset> ...
1462989769
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Question, potentially a naive one. Is this like the repeating fields in the pathfinder sheet? If so, shouldn't the fields still have unique names like @{repeating_weapon_$0_attack} or @{repeating_weapon_-xjasdf4560k_attack} (as examples from the pathfinder sheet).
Scott C. said: Question, potentially a naive one. Is this like the repeating fields in the pathfinder sheet? If so, shouldn't the fields still have unique names like @{repeating_weapon_$0_attack} or @{repeating_weapon_-xjasdf4560k_attack} (as examples from the pathfinder sheet). Doesn't it use some kind of API plug-in to give those fields unique attributes?
The Aaron said: Try using just:  !ammo @{character_id} MP -[[@{spell2cost}@{spell2manamod}]] I finally figured it out! Your script saved the day after all. You're AMAZING! Thank you so much for existing and being so awesome!
Scott C. said: I'm sure Aaron will point this out in a bit, as it's his script, but I think you could use his  ammo script for this. I just tried it in my sandbox and a syntax like this works: !ammo @{selected|token_id} Ammo -[[2d4]] This results in the Ammo stat being reduced by whatever the result of the roll is. You would not be able to put this directly in your roll template though as it requires the API call. Your template could be rolled into a macro and read like this: &{template:default} {{name= CASTING}} {{Spell Name= @{spell2name}}} {{Spell level= [[1]] (@{Class})}} {{Type= @{spell2type}}} {{Spec./Sign.= @{spell2spec}}} {{Success= [[d20]] vs TN[[@{spell2stat}@{spell2TNmod}]]}} {{Cost= @{spell2cost}@{spell2manamod} Mana}} {{Heals/Deals= @{spell2healdeal}}} {{Range= @{spell2range}}} {{Components= @{spell2comp} (@{spell2complist})}} {{Duration= @{spell2dur}}} {{CastingTime= [[@{spell2speed}]]}} {{AOE= @{spell2aoe}}} {{Save= @{spell2save}}} {{Effect= @{spell2eff}}} {{Limit= @{spell2limit}}} !ammo @{selected|token_id} MP -[[@{selected|spell2cost}@{selected|spell2manamod}]] The roll template would no longer give what the roll is, but the functionality of automatically adjusting the MP value would work. Note that the template no longer has an inline roll for the cost. I do something similar to this in my pathfinder game, using Ammo to deduct spells per day each time a character casts something and using a Rest Macro to automatically reset the values. Sorry if I stepped on your toes Aaron. Scott C. You helped me out, but I had to tweak it ... basically the !ammo call comes before the roll template now ... but yeah, it works, like this: !ammo @{selected|token_id} MP -[[@{spell2cost}@{spell2manamod}]] &{template:default} {{name= CASTING}} {{Spell Name= @{spell2name}}} {{Spell level= [[1]] (@{Class})}} {{Type= @{spell2type}}} {{Spec./Sign.= @{spell2spec}}} {{Success= [[d20]] vs TN[[@{spell2stat}@{spell2TNmod}]]}} {{Cost= @{spell2cost}@{spell2manamod} Mana}} {{Heals/Deals= @{spell2healdeal}}} {{Range= @{spell2range}}} {{Components= @{spell2comp} (@{spell2complist})}} {{Duration= @{spell2dur}}} {{CastingTime= [[@{spell2speed}]]}} {{AOE= @{spell2aoe}}} {{Save= @{spell2save}}} {{Effect= @{spell2eff}}} {{Limit= @{spell2limit}}} Thanks a bunch guys! I'm soooooooo so SO happy now. :) :) :)
1463014276
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, just because I was trying to get some behavior out of putting the ammo call first in one of my macros, what did putting it first do?
Well, the problem was that this entire block of code was within value="", meaning the quotation marks made it a bit weird because even after hitting a new paragraph it didn't recognize !ammo as a new line, so putting it first made roll20 recognize it as what it is. The only downside is that it puts the whispered message sometimes before the roll template in the chat and instead of after. It might trigger some people's OCD, but my OCD is perfectly fine with it because I got it to work. :)
1463040843
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, yeah, I've run into that bug as well with !ammo, it's sort of intermittent for me
1463049817
The Aaron
Pro
API Scripter
Great!  Glad you got it working!