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] CharUtils -- A collection of utilities for manipulating character data.

1407252223

Edited 1493068316
The Aaron
Roll20 Production Team
API Scripter
Update: v0.6.3 &nbsp;-- Removed dependency on isGM, added some commands for sub copies, moved to git. Update v0.51 -- Removed direct use of HTML entities to prevent the substitution bug. Update v0.5 -- Added !replace-attr command which takes the same arguments as !rename-attr, but does a per character replace of references to the attribute name in abilities with the specified attribute name. Currently supports @{attr-name}, @{Char ID|attr-name}, @{Char name|attr-name}, @{target|attr-name}, and @{selected|attr-name}, all with and with out |max appended. It's possible there may be some edge cases that it won't hit because of looking specifically in abilities of each character separately. Let me know if you run into any issues. Update v0.4 -- !rename-attr now works. It was !attr-rename in the code but not matches the help docs. =D Update v0.3 -- !rename-attr now requires each argument to be prefaced by ' --' . This is to support attributes that have a space in the name. Additionally, it will now copy the current and max values to any attribute on the character that exists with the rename name, and change the original attribute's name to DELETE ME . This script grew out of this discussion . Currently, 2 operations: !chardup -- copy all the abilities from a source character to one or more destination characters !rename-attr -- rename attributes on all characters. !replace-attr -- replaces references to attributes in abilities. Git:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Ch" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Ch</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.
1407416878

Edited 1407416907
Does this override the value for the new name if one exists? I just realized the new attribute name is created automatically by the character sheet so I although haven't tested it yet, am going to need it to override the existing value if there is one. (for !rename-attr)
1407418150
The Aaron
Roll20 Production Team
API Scripter
It does not. It could be adjusted to do that, however the API can't delete things, so it would then have to renamed all the dupicates as something like 'DELETE ME';
Could instead of renaming the duplicates, just update all the duplicates as well? I'm afraid when it comes to the character sheet if it is using one of the duplicates rather than the first one found etc.
1407421401
The Aaron
Roll20 Production Team
API Scripter
Right, that's what I was suggesting. if you're moving Dex to Dexterity, and Dexterity already exists, you would set Dexterity to the value that Dex has and rename Dex to DELETE ME.
Okay, good, we are on the same page.
I might need to take a look at this tonight to see what needs to be modified.
I have one named "Armor Class" Not sure how to get it to work for that one.
I don't see what I am trying to rename it to on the list, it is on the character sheet, and it isn't updating, no message, not sure if I am using the correct format: !rename-attr ("Armor Class") AC (was my attempt at what I need to do - nothing Then I manually renamed Armor Class to Armor_Class on one sheet, and it still didn't do anything. !rename-attr Armor_Class AC With both IsGM and this ulti script in a test campaign.
1407685154
The Aaron
Roll20 Production Team
API Scripter
Updated. It will now handle names with spaces, but you'll need to preface all arguments with --. It also properly updates exiting attributes with the destination name on a character by character basis (in which case the old attribute is renamed 'DELETE ME'). Note that this is case sensitive. Example for your case: !rename-attr --Armor Class --AC You can still chain multiple renames: !rename-attr --Armor Class --AC --Hit Points --HP --Something to --Something Else
Still not working for me :/ !rename-attr --Armor Class --AC
1407796631
The Aaron
Roll20 Production Team
API Scripter
Same game?
Yes, that is the one we are in right now.
Aaron, I have a 2nd issue. Now that I changed the attribute names, I have over 200 sheets that have macros that pull from the old names :/ Is there anyway to go through each ability for every character and switch all calls to those attributes I changed, to also be changed to the new ones?
1408390188
The Aaron
Roll20 Production Team
API Scripter
That is a harder problem, but still solvable. Just need to pull all abilities, search for the renamed attributes in there, and replace them, then update the abilities. Algorithmically not too difficult.. I'll see what I can do later tonight...
1408414306

Edited 1408414749
The Aaron
Roll20 Production Team
API Scripter
Ok. Added! Update v0.5 -- Added !replace-attr command which takes the same arguments as !rename-attr, but does a per character replace of references to the attribute name in abilities with the specified attribute name. Currently supports @{attr-name}, @{Char ID|attr-name}, @{Char name|attr-name}, @{target|attr-name}, and @{selected|attr-name}, all with and with out |max appended. It's possible there may be some edge cases that it won't hit because of looking specifically in abilities of each character separately. Let me know if you run into any issues.
Aaron, you always kill me without examples. It seems like !replace-attr @{attr_STR},@{attr_strength_mod} should work, now? or does it still use --?
1408570206

Edited 1408570219
!replace-attr --@{STR}--@{strength_mod} isn't working it seemed without the @ and { }s it kind of worked, it threw an error at least.
!replace-attr --STR --strength_mod is throwing this error SyntaxError: Invalid regular expression: /@{Daefor (Day)(Mountain/Swamp\|STR}/: Unterminated group at new RegExp (&lt;anonymous&gt;) at evalmachine.&lt;anonymous&gt;:2891:32 at /home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:120:25 at _.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:81:22) at Function._.reduce._.foldl._.inject (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:115:5) at evalmachine.&lt;anonymous&gt;:2884:13 at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:81:22) at evalmachine.&lt;anonymous&gt;:2882:6 at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:86:24) at attributeReplace (evalmachine.&lt;anonymous&gt;:2881:5)
I deleted that characters name and it seemed to fix the issue, thanks Aaron!
It's actually not fully working together in my other campaign, there are some creatures I vaulted in and they don't seem to work. (just a handful), but it seems interesting.
1408572382
The Aaron
Roll20 Production Team
API Scripter
hmm.. this the campaign I'm invited to? Example: !replace-attr --old name --new name --other old name --other new name --yet a third old name --and a third new name
yeah, got it all to work except for a few that I used the vault for, which is odd.
And unfortunately no, it's my Sunday campaign, it's only 6 sheets, so I can fairly quickly change them manually.
1408633496
The Aaron
Roll20 Production Team
API Scripter
If you get it duplicated in the one I'm joined to, let me know. I'd love to fix whatever the problem is. Were the attributes that you were trying to rename to not attributes on the characters? The current version only renames to attributes on the character. This could fail if the character has a macro that uses @{target| AC } and you're changing it to @{target| Armor Class }, but the character doesn't have Armor Class themselves. I probably need some better feedback in the UI about that, and possibly a force option.
I did notice that as I was working with it yesterday. I made sure I did the rename, before the replace. However for just those 6 it wasn't working. I only needed it one time, so I rather not consume all of your time with it. It was a stop gap measure to hold me off until I can update each creature with the 5e beastiary. I will then probably be using the copy macro for the creatures though, very extensively. chardup sounds like I will have to use a macro that grabs the selected token's name for the destination. I need a "wipe all existing abilities" for a selected character as well. Many, many hours of work ahead of me.
1408638300

Edited 1420235532
The Aaron
Roll20 Production Team
API Scripter
The API cannot delete things, so there is no current way to write a wipe function. Currently, the names for chardup don't have to be exact, so long as what you provide either matches exactly with one name or matches part of exactly one character. I could see adding a fuzzy match ability to say match everything with goblin in it, that sort of thing. That actually wouldn't be extremely difficult.
Well my old ones use /as @{name} So that might just be fine as is.