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] UsePower -- Use tracking and flagging of Encounter and Daily Powers.

September 02 (11 years ago)

Edited February 23 (8 years ago)
The Aaron
Roll20 Production Team
API Scripter
Update v0.4.1 -- Removed dependency on isGM and added use of playerIsGM() instead.
Update v0.31 --Fixed the HTML Entities issue.
Update v0.3 -- Fixed off-by-one bug causing the listed powers to be instrumented one higher than they should have been.
Update v0.2 -- Fixed minor bug preventing schema version from being written into the state object.

UsePower

UsePower provides a way to instrument and track daily and encounter powers. It is intended for D&D 4E, but could be used for any system that requires the capability to flag abilities as used and reset them. Using an instrumented ability will mark it used and remove it as a token action. (Caveat: it will disappear the next time the owner deselects the token.)

Daily powers are restored to token actions after !long-rest is executed. Encounter abilities are restored to token actions after !short-rest or !long-rest is executed. Activating a used power will whisper to the player and GM that the power was already used.

Commands

!add-use-power --<Character Name> [--[ encounter | daily ] <number> [<number> ...] ...]
(GM Only) For all character names, case is ignored and you may use partial names so long as they are unique. For example, "King Maximillian" could be called "max" as long as "max" does not appear in any other names. Exception: An exact match will trump a partial match. In the previous example, if a character named "Max" existed, it would be the only character matched for --max.

Omitting any --encounter and --daily parameters will cause a list of the character's powers with the expected index numbers (Caveat: These numbers will change if you add powers to the character. You should look them up again before instrumenting if you have changed the list of powers.)
  • --<Character Name> — This is the name of the character to list or instrument powers for.
  • --<[ encounter | daily ]> <number> [<number> ...] — This specifies a list of abilities to instrument as either encounter or daily powers. You can specify as many powers as you like by number after these arguments. Numbers that do not index abilities or values that are not numbers are ignored. Duplicates are ignored. If you specify the same number to both an --encounter and a --daily parameter, it will be reported as an error. Powers that are already instrumented will be changed (So, if an ability is already instrumented as an encounter power and you specify it as a daily power, it will be changed to a daily power.).
!short-rest
(GM Only) This command restores all expended encounter powers to token macros.
!long-rest
(GM Only) This command restores all expended encounter and daily powers to token macros.
!use-power <Type> <Ability ID>
This command requires 2 parameters. It is usually added by the instrumenting code. If you copy it from one ability to another, it will be updated with the correct Ability ID on save. Duplicating an existing character will also cause the new character's abilities to be corrected. All abilities are validated and updated on restart of the API.

!use-power or !add-use-power by with no arguments produces the help:


Example uses (for character named "Foo"):
First, listing the abilities on that character:
!add-use-power --foo

Now flagging some as encounter and some as daily:
!add-use-power --foo --encounter 2 3 --daily 5 6
Then listing again:
!add-use-power --foo

Oops. I meant to have 5 as an encounter
!add-use-power --foo --encounter 5


Now using them:

Using Power 2, then using it again (notice the error that is issued to the player (and also to the GM if they are different):

Token Macro bar after a few uses:

!short-rest

Use some more:

!long-rest


Looking forward to improvement suggestions!

Git: https://github.com/shdwjk/Roll20API/blob/master/Us...


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.
September 03 (11 years ago)
Looks nice. First feature request for me is a tie in with your ammo mod. I currently use your ammo mod not only for weapons but also for class abilities and such in pathfinder that have x number of uses per day. e.g. Channel energy for a cleric

If the script could monitor the uses remaining attrib and then remove it from your bar when that hits 0 it would be nice. Not sure how you would go about resetting it though as the max value is another attrib so it becomes much more complex I guess.
September 03 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Hey Zepth,

Probably not too complex. So the situation you have is something like Channel Divinity (is it Channel Energy in Pathfinder?), where you have several powers that all count against a single pool? And the maximum value for that pool is in a different attribute than the current remaining?

So, say Healing Word and Turn Undead both use the Channel Energy pool in @{channel_energy_current}, with the maximum in @{channel_energy_max}. You'd like to be able to set it up so that each use of either ability reduces @{channel_energy_current} by some number (I'm assuming there are abilities that use more than one charge, to be as general as possible), and when @{channel_energy_current} reaches 0, disable any of the abilities that use that pool.

I think that's doable at some point.
September 03 (11 years ago)
Not even a case of shared uses. More just single items or powers that have multiple uses per day. In the cleric example in pathfinder Cleric class ability channel energy which heals everyone in a 60ft burst. Can be used 3 + CHA mod times per day. So in the pathfinder sheet I have max uses calculated, and uses remaining as attributes in the class ability section.
My current macro casts the ability and uses your ammo script to reduce the uses remaining attribute by 1. If it could remove the token action when it hits 0 as well that would be awesome. The tough part is what to set the attrib to when it resets.


September 03 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Ah. That's a much simpler case. That's totally doable. Let me think about it for a few days but I don't see any problems supporting that case. And the reset isn't such an issue. If it's in an attribute, we can just pass it to the command.
September 03 (11 years ago)
This is exactly what I asked for and it's brilliant! Just what I needed, thank you for this and I've been testing it with no issue what so ever at the moment.

Zepth's comment made me realize that, since I have Psion whole uses power points to augment her abilities (so some use 2 power points or 1 and can't be used if below those values), that it would be a brilliant addition to the script also.

Again thanks for the effort and the skill you've put into this.
September 03 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Glad you like it! =D

So, tell me more about how you see the Psion bit working? Would it be as I described it in my first response to Zepth?
September 03 (11 years ago)
Indeed but with a minor adjustment to when it can be switched off. Since some augmented moves, which Psions use, can require 2+ power points. So there could be a variable limit to when those can be disabled. and these points reset after a short rest instead of daily.

Otherwise very much similar.

September 03 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
hmm.. Yeah, let me think on that. The biggest problem to solve is how to turn off other abilities that depend on the same stat. I can think of several ways to do it, I just want to be sure I arrive at the most elegant solution. =D
September 03 (11 years ago)

Edited September 03 (11 years ago)
How about something like !add-use-power --foo --<attribute name> <power number>
then monitor the attribute. While attribute > 0 token action is true
September 03 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Yeah, something like that, but I want to handle the case where the attribute for current and max are separate, where the amount used is variable (cast fireball at level 3, 4, 5, etc..), and where the cost is other than 1, etc
September 05 (11 years ago)

In essence it sounds akin to the "Ammo - Automated ammunition management" script you have where you can take a custom amount of ammo away from the stat and track how much ammo there is and if usable. That's what I get from the sound of it right now.

September 05 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Right. The hard part is the turning off of all macros that use that resource.
September 05 (11 years ago)

Edited September 05 (11 years ago)
Yeah I think I have a process in my head that might make it work, Is use something like "!add-use-power --foo --limited 5 --cost 3 --stat PP" so on the use part it can be distinguished and can determine the stat and cost.

Then when used at the start it removed the allocated amount of points from the stat (down to 0 or more depending.) So in this case makes PP 1/4. Similar to how the ammo script works.

Then, like you did with the list scan to see what powers are encounter and daily, scan to find all those that have the PP and the cost that is greater than what they currently have. And hide each in turn depending on those two extra variables.

That's what I have in my head right now and I hope it helps out with the ideas you currently have in mind.

As an extra idea
Maybe the stat could have a tag if possible like PP--short-rest or something that could recharge it on a sort or full rest script use.
September 05 (11 years ago)
The Aaron
Roll20 Production Team
API Scripter
Yeah, that's largely what I'm thinking. However, I'll probably preparse the abilities that use !use-power the way I do to fix character IDs and store them in the object, that way at use time, I don't have to reparse them all. I can use the on('change:ability',...) to make adjustments to the stored graph as needed, and everythging is nice and fast. =D
September 29 (10 years ago)
Hey Aaron, did you ever get this working with "x times per day" feature working on this script? I'd love to use it for daily powers like Turn undead or smite evil that have multiple uses per day.
If so how do I set it up?

Thanks!
September 29 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Haven't done it yet, but still planning to get to it. :)
September 30 (10 years ago)
*cracks the whip* while i got your attention.... i had 2 minor glitches...

  1. How do you remove daily/encounter from an ability? (i mislabeled one bc of the next issue).
  2. When i assigned daily to my 4th macro, i was actually assigned to the 5th macro, you think the default Initiative token button caused this? (its not listed on your table when you use !add-use-power --<charactername>) FYI i use Diana's 3.5 Character sheet
September 30 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
=D Slashing immunity!!

1. You can just edit the macro. it will have inserted a line at the beginning that looks something like:
!use-power daily -hjho8797ugi6tiiyg
Either delete the line and re add with !add-use-power or edit it and change daily to encounter. You can actually add these manually by typing something like:
!user-power encounter foo
On changing of an ability, the script will check for that line, and replace the 3rd parameter with the correct ability id (I did this to support duplicating character but it totally works for this as well. =D)

2. So, are you saying you did:
!add-use-power --character
and it gave you a list, and you came back with:
!add-use-power --character --daily 4
and the power it added the !use-power to was your 5th power?

Do you have a duplicatable case I can test out?


September 30 (10 years ago)
OK so maybe this will help:

then....


FYI i tried it again with #1 hoping to get spear... I ended up with Light Crossbow lol
September 30 (10 years ago)

Edited September 30 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Weird. Obviously I have an off-by-one error in referencing the array of abilities. I thought I'd accounted for that. =D

Ok, fixed in version 0.3! =D

Thanks for tracking that down!
September 30 (10 years ago)
Works perfect Aaron, another great job (btw i think your scripts are the only ones ive got to work 100%) ok ill leave you be to get finished on the "times per day" changes ;)
September 30 (10 years ago)

Edited September 30 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
You're welcome! I strive for perfection, but you're lucky if you're getting 100% success. =D Certainly let me know if you run into other problems and I'll endevor to resolve them. =D

And thanks for the kind words!
October 26 (10 years ago)
Hey Aaron, is there a way to handle encounter powers that can be used twice per encounter, such as Healing Word? Did I miss that somewhere?
October 26 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
No, you didn't miss that. It's on my list of things to do... If you have any suggestions, though feel free to post them. I always reread the thread when I embark on updates and try to do as much as possible when I'm modifying. =D
October 28 (10 years ago)
I'm not sure about incrementing the use, but as a workaround, it's pretty easy to copy/paste into a new power and call them Healing Word 1 and Healing Word 2, so they disappear when used. Not elegant like Jedi script, but it works!
October 28 (10 years ago)

Edited October 28 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Nice workaround! Sorry it's taking so long to get that feature in...
October 30 (10 years ago)
No worries! Thanks for all you've done for us!
October 31 (10 years ago)
Scott, you might want to check out his Ammo script, altho it refers to everything as "ammo" i've been using it as a power tracker as well. For example, in Pathfinder im using it for Ki pool points, Lay on Hands, Channel energy etc... works great

November 04 (10 years ago)
I've made a Frankenstein's monster of this and Aaron's Ammo script
It adds "!use-ammo <Character / Token ID> <attribute name> <quantity to remove>

I've done it this way for my Psions, with 3 different powers per augmentable power, e.g.

!use-ammo @{Abel d'Sivis|character_id} power-points 2
!power --format|dnd4e --name|Kinetic Trip (Augment 2) --title|Psion Attack 3 --usage|At-Will ...

It finds all the abilities of that character that draw from the same attribute pool to hide the token actions when the pool empties, and fills them again on both !short-rest and !long-rest

https://gist.github.com/Caleth/77aa90a4d0a328bfca4...
November 04 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Nice work!

I do have a couple suggestions and a request.

It looks like you've lost this line out of the GIST:
var UsePower = UsePower || (function() {
You'll need to add it back between lines 2 and 3.

Also, I updated this script earlier today with some code to fix a bug that crops up sometimes with scripts that contain HTML entities (like &gt;). You might want to merge those changes in.

My request is that you change the name of the Module from UsePower to something like UsePowerWithAmmo and start a separate version number Sequence. Not a big deal, but it will prevent confusion when I release a version 0.4 later. =D

Let me know if you need any help!
November 04 (10 years ago)

Edited November 05 (10 years ago)
No problem about the name change.

I'll have a look at the > thing again, I think I ran into that copying it from github

and good spot on the missing first line

I need to work on hiding token actions once the amount they require more than what remains. I have some ideas but haven't gotten round to trying them, my Psion only uses Augment 2s, so it hasn't cropped up with 4PP

Edit: trying my first idea
November 05 (10 years ago)
I am GM and it says to me: "Only the GM can initiate a short rest"

November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
You need to speak in chat as yourself (the version with (GM)) at the end. That will let isGM detect that you are a GM. From then on it will work for you as expected.
November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Looks like I forgot to publish that HTML Entities update... Here it is.

Update v0.31 --Fixed the HTML Entities issue.
November 05 (10 years ago)
Just because i am a macro idiot and i wish to share my paltry knowledge with others in the same shoes; selecting the characters token (i assume unless it has been renamed something custom) and using the !add-use-power --@{selected|token_name} macro may save people some time setting this up the first time. Awesome script btw Aaron, well done.
November 05 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Ooh, that is a fantastic tip Kenny! I had not thought of doing that.

The way I setup the name, you can use the shortest unique piece you like to identify the character, here are some example names:
Balde
Withelm
Lofa
Wulfa
Rica
Rewilh
Gerey
Wulfre
Gauwis
Given the above characters, you could write any of:
!add-use-power --Lo      <== For 'Lofa'
!add-use-power --c       <== for 'Rica' (only name with a 'c' in it)
!add-use-power --ga      <== for 'Gauwis'
!add-use-power --Bald    <== for 'Balde'
!add-use-power --Withelm <== for 'Withelm'
Just food for thought.

Thanks for tip and the kind words!
November 05 (10 years ago)
awesome yeah that makes alot of sense aaron, i was trying to use the whole !add-use-power --[[?{character name?|}]] --[[?{e#?|}]] --[[?{d#?|}]] but could not seem to get that to work >.>
November 09 (10 years ago)
Will
Pro
Hey Aaron, it's your friendly neighborhood script breaker again! We recently ran into an issue with this script and we are stumped. One of the players gets the same error every time the script is run. I apologize for the amount of data I'm going to post, but it's the only way to explain it.

!add-use-power --2 - Briar Patch
Available Powers:
  1. Shield-Utility-2-E
  2. Sequester-Lvl-11-encounter
  3. Hypnotic-Pattern-Encounter-3 [encounter]
  4. Thunderwave-at-will
  5. Orbmaster's-Incendiary-Detonation-Lvl1-E[encounter]
  6. Chameleon'sMask C-E
  7. Suggestion-C-E
  8. PixieDust-E-U
  9. Shrink-E-U
  10. Prestidigitation-AW-C
  11. Arcane-Mutterings-Utility-[daily]
  12. Horrible-Whispers-Daily-1
  13. Hypnotic-Pattern-E-3[encounter]
  14. Orb-of-Imposition-E-Class
  15. Warmage's-Uniform-+2-Daily
  16. Accurate-Orb-of-Enduring-Magic[encounter]
  17. Flaming-Sphere-damage
  18. Flaming-Sphere-Daily-1[daily]
  19. Lucky-Charm--Daily-Item[daily]
  20. Visions-of-Avarice-daily5[daily]
  21. Visions-of-Avarice-secondary-attack
  22. Wizard's-Escape-Util-6[daily]
  23. Pixie-Invisibility-Util-6[encounter]
  24. Charm-of-the-Defender-Enc-7 [encounter]
  25. Light [encounter]
  26. Wall-of-Fire-Lvl-9-D[daily]
  27. Taunting-Phantoms-Lvl-9-D [daily]
  28. Blur-Lvl-10-D
  29. Arcane-Gate-Lvl-10-D
  30. Philospher's-Crown-D
  31. Bracers-of-Defense-D
  32. Phantasmal-Assault-lvl-1-At-Will
  33. Melee-Basic
  34. Ranged-Attack
  35. Fireball-Daily-5 [daily]
!add-use-power --2 - Briar Patch --encounter 1 2 3 5 6 7 8 9 11 13 14 15 16 23 24 25 --daily 12 13 15 18 19 20 22 26 27 28 29 30 31 35
Error: Powers cannot be both encounter and daily. Please specify each power only for one type. Duplicates:12, 14

So as you can see, when we run the script to assign the powers as encounter or daily it returns the above error. 12 and 14 are not in both lists, and I have run the script after deleting 12 and 14 from the macro. Any suggestions?
November 09 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Weird!

What happens if you do each of these:
!add-use-power --2 - Briar Patch --encounter 14
!add-use-power --2 - Briar Patch --daily 12
!add-use-power --2 - Briar Patch --encounter 14 --daily 12

if you want to PM me an invite, I'd love to come debug it. :)
November 12 (10 years ago)
Will
Pro
Sorry Aaron, I've been distracted by work and haven't had time. I'll send you an invite now. (Should just leave you as a permanent member of the group with how often we manage to break stuff.)
November 12 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Add it to the list. I just went through all of them looking for that 5e status and hp script I modified.... 20 or so..
December 15 (10 years ago)
Hello Aaron

Is there a way to use your macros without the rolls and damage? i use a seperate script for combat but would like to use this script to keep track of dailies and encounters.

Thanks for all your hard work.
Nirav
December 15 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
This script doesn't do anything with rolls or damage. It only tracks the on off state of a power. The example images just happen to also have output as testing would have been hard without it.
December 15 (10 years ago)
Thanks Aaron, just noticed that myself before i started testing. I replied before i tested and was basing it on the sample images. It works great btw, thank you!

Nirav
December 16 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
No worries!
December 16 (10 years ago)
Aaron, i ran into a bit of a weird issue. Your script works great without issue. But today i wrote a separate basic script that turns on/off a character's aura based on the power used. It pretty simple and works fine as well. But all your scripts i use (UsePower and TurnTracker) gets an error whenever the aura scripted is enabled. I can't even pull up the help. When i disable the your script, it works perfectly. I haven't touched your code at all and have isGM() installed as well.

The error message generated when i typed !add-use-power : TypeError: Cannot call method 'get' of undefined at evalmachine.<anonymous>:1373:29 at eval (

Here is the code for my aura script:
https://gist.github.com/Nirav328/036458158b4696bf4...

Thanks again for all your assistance!
Nirav
December 17 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
That sounds bizarre. If you want yo PM me a join link, I can jump in tomorrow and see if I can track it down.
December 17 (10 years ago)
Invite sent
December 17 (10 years ago)
The Aaron
Pro
API Scripter
Resolved!
After reading this whole post... to my understanding there is now a tracker for quantities alongside encounters/dailys? So I could set up spells per day like 5e now ? :)