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 .
×
D&D 2024 has arrived! Pre-Order the new core rulebooks now.
Create a free account

Can a script create repeating items on a character sheet?

1567538823

Edited 1567539262
In the game I'm running, there are certain actions any player can make during combat. They aren't already included on the character sheet, so I thought to add them as actions on each sheet. It would be a time consuming process to add all these actions to each sheet one by one, so that got me wondering if it would be possible to make a script that could take a set of repeating items that I enter into the script's interface, then apply them to multiple character sheets. I know there are scripts that can create abilities and attributes, and ones that can identify repeating items, but is it possible for one to directly add repeating items to the actual sheet?
1567540899
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, you just have to generate a row id to use for all the attributes in the repeating item. You can find a generateRowID() function I got from somewhere (I think Aaron) in my Pathfinder Companion Script. There are several others that use the same function like chatSetAttr I believe.
1567541181

Edited 1567541190
Jakob
Sheet Author
API Scripter
The thing you have to be careful about is that generateRowID() is not guaranteed to create unique IDs (in fact, in generally won't). If you are creating several in a row, you have to make sure somehow that you are never reusing IDs. Anyway, what you want to achieve is probably possible using ChatSetAttr.
1567541948
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, haven't run into that myself Jakob. Wasn't even aware it was a potential issue.
1567548687

Edited 1567548750
Thanks for your suggestions! How could I go about doing this with ChatSetAttr? What I'm wanting to do is add the 10 combat maneuvers (plus one for maintaining grapple and one for breaking grapple) in Pathfinder as attacks for each player (using Pathfinder by Roll20 sheet). This would need to adjust multiple parts of each repeating item, including changing the attack type to CMB, toggling off damage, and toggling on and filling out the description.
1567549387
The Aaron
Roll20 Production Team
API Scripter
Jakob said: The thing you have to be careful about is that generateRowID() is not guaranteed to create unique IDs (in fact, in generally won't). If you are creating several in a row, you have to make sure somehow that you are never reusing IDs. Are you talking about the replacing of _ for Z? Or something else?
1567561772

Edited 1567561937
Bast L.
API Scripter
Hey, I've been working on something similar, and so, since you're in my game, I threw this together. It only does Bull Rush atm, but look at the maneuvers constant. Should be clear how to add more. To use, select a bunch of PC tokens, hit !CombatManeuverBatch in chat. gist:&nbsp; <a href="https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b" rel="nofollow">https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b</a> Edit: Danger, I don't test things carefully, so use at your own (or your players') risk.
1567562288

Edited 1567563681
Bast L. said: Hey, I've been working on something similar, and so, since you're in my game, I threw this together. It only does Bull Rush atm, but look at the maneuvers constant. Should be clear how to add more. To use, select a bunch of PC tokens, hit !CombatManeuverBatch in chat. gist:&nbsp; <a href="https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b" rel="nofollow">https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b</a> Edit: Danger, I don't test things carefully, so use at your own (or your players') risk. Awesome, thanks Bast! I'll test it out and let you know how it goes. Edit: Does this look like the right syntax for adding more maneuvers? (changed some of the features it changes to suit my other campaign's needs). Also, for descriptions with multiple paragraphs, is \n what I would use to mark breaks in the text? const maneuvers = [ { atkname: "Bull Rush", atktype: "cmb", atkmod: "0-[[{(floor((1-(floor((@{hp}/@{hp|max})*4)/4))*3)),3}kl1]][WND]", atkvs: "cmd", dmgflag: "unchecked", descflag: "checked", atkdesc: "&lt;description&gt;" } { atkname: "Dirty Trick", atktype: "cmb", atkmod: "0-[[{(floor((1-(floor((@{hp}/@{hp|max})*4)/4))*3)),3}kl1]][WND]", atkvs: "cmd", dmgflag: "unchecked", descflag: "checked", atkdesc: "&lt;description&gt;" } ] Edit2: Must not be right, cuz I get the error message SyntaxError: Unexpected token {
1567569576
The Aaron
Roll20 Production Team
API Scripter
You need a comma here: }, {
Thanks! And thanks again, Bast, this did exactly what I needed :)
1567702716
Jakob
Sheet Author
API Scripter
The Aaron said: Jakob said: The thing you have to be careful about is that generateRowID() is not guaranteed to create unique IDs (in fact, in generally won't). If you are creating several in a row, you have to make sure somehow that you are never reusing IDs. Are you talking about the replacing of _ for Z? Or something else? No, creating several IDs in a row is likely to end up in a collision. The function looks like it's supposed to prevent that, but that does not seem to work. My workaround is to use an&nbsp; awkward while loop .
1567720513
The Aaron
Roll20 Production Team
API Scripter
Interesting!&nbsp;
1567960755

Edited 1567961098
Bast L.
API Scripter
Hmm, looking at the generateUUID function I copied from some thread (probably from one of you), it looks like it generates based on the Date, so if the different UUIDs are generated within the same ms, it'll be the same? Or is it something else? Would a simple setTimeout of x ms inside generateUUID fix it? Otoh, trying to understand this function, b's elements are generated by Math.random(), which.. I don't know how it's seeded.&nbsp;
1568347766

Edited 1568347961
So on a sort of related note, I've been wondering: Is it possible to edit the row IDs of existing repeating items? Or to simply create an item with a set name, row ID, and other details, and use a script to apply it to a sheet, so that every sheet I apply it to uses the same ID for it? I ask this because I have things like the combat maneuvers mentioned above where I add the same maneuver as an Attack item to each of my players' character sheets, but the attack item has a different ID on each sheet. This means when I want to create a macro that involves that particular maneuver, I need to have it include each of the unique IDs in order to work with each player's sheet. If there's a way to edit the IDs of these items on each sheet so that they are all the same ID, that would allow me to simplify a lot of my macros. Example: I use Bast's script to add an attack called Bull Rush to each player's sheet. Since each sheet's version of Bull Rush has a different ID, I have to include each ID in a macro that involves the Bull Rush maneuver. But this won't work with some macros or scripts because all but one of the IDs are not found on a given sheet. If I could make sure Bull Rush has the same ID on each sheet, the macro would only need to look for that one ID.
1568347981
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Short answer yes. Long answer yes, but you don't want to. They have a unique row id so that they are unique entities. I'm not sure what would happen if you set it to a repeated row id, but I seem to remember Jakob (?) discovering that if you did, the data was shared across all characters that had the row with that id.
1568348378
The Aaron
Roll20 Production Team
API Scripter
(Stephen S. discovered it, as far as I'm aware. =D )
Scott C. said: Short answer yes. Long answer yes, but you don't want to. They have a unique row id so that they are unique entities. I'm not sure what would happen if you set it to a repeated row id, but I seem to remember Jakob (?) discovering that if you did, the data was shared across all characters that had the row with that id. So if each sheet had a Bull Rush with the same row ID, changing, for example, the description for that Bull Rush would make the same changes to each other character's Bull Rush? I probably would avoid using for things like that then. The main use I was hoping to implement was for custom Buffs on the PF sheet, since I use ChatSetAttr to toggle buffs and conditions of and on. But if I'm understanding you correctly that would mean setting the toggle for one buff to 1 would do the same for each sheet with that buff?
1568349600

Edited 1568349647
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Correct. Which Pathfinder sheet are you using? And thanks for the correction Aaron; couldn't remember who found that, or if I was even remembering the problem right.
Pathfinder by Roll20. Doesn't come with pre-existing buffs, only conditions, so all Buffs have to be added as repeating items.