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

Can a script create repeating items on a character sheet?

September 03 (5 years ago)

Edited September 03 (5 years ago)

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?

September 03 (5 years ago)
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.

September 03 (5 years ago)

Edited September 03 (5 years ago)
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.

September 03 (5 years ago)
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.

September 03 (5 years ago)

Edited September 03 (5 years ago)

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.

September 03 (5 years ago)
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?


September 04 (5 years ago)

Edited September 04 (5 years ago)
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: https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b

Edit: Danger, I don't test things carefully, so use at your own (or your players') risk.

September 04 (5 years ago)

Edited September 04 (5 years ago)


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: https://gist.github.com/Bastlifa/e3b9f1d670cf24c8c7b17a06b2f2c50b

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: "<description>"
}
{
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: "<description>"
}
]

Edit2: Must not be right, cuz I get the error message SyntaxError: Unexpected token {

September 04 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

You need a comma here:

        },
{


September 04 (5 years ago)

Thanks!

And thanks again, Bast, this did exactly what I needed :)

September 05 (5 years ago)
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 awkward while loop.

September 05 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Interesting! 

September 08 (5 years ago)

Edited September 08 (5 years ago)
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. 

September 13 (5 years ago)

Edited September 13 (5 years ago)

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.

September 13 (5 years ago)
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.

September 13 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

(Stephen S. discovered it, as far as I'm aware. =D )

September 13 (5 years ago)


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?

September 13 (5 years ago)

Edited September 13 (5 years ago)
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.

September 13 (5 years ago)

Pathfinder by Roll20. Doesn't come with pre-existing buffs, only conditions, so all Buffs have to be added as repeating items.