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
This post has been closed. You can still view previous posts, but you can't post any new replies.

[Script] TokenMod -- An interface to adjusting properties of a token from a macro or the chat area.

1413174760

Edited 1457504283
The Aaron
Roll20 Production Team
API Scripter
Update v0.8.18 &nbsp;-- Fixed crash bug on --help from recent changes to sendChat(). (Thanks&nbsp; RMcD &&nbsp; andrew M. ) Update v0.8.17 &nbsp;-- Added support for blanking represents by using --set represents| (Thanks&nbsp; Vince ) Update v0.8.16 &nbsp;-- Added --order for pushing tokens to the front or back (Thanks Nosaj !): !token-mod --order tofront For to front, use one of: tofront, front, f, top For to back, use one of: toback, back, b, bottom Update v0.8.15 &nbsp;-- Fixed the bug preventing setting some properties to blank. (Thanks&nbsp; Jacob !) Update v0.8.14 &nbsp;-- Fixed the bug causing a crash for empty arguments. (Thanks&nbsp; Gozer the Gozerian !) Update v0.8.13 &nbsp;-- Added # as an alternative to | in commands. &nbsp;This makes some macros easier to write. !token-mod --set ?{Feature|Dead, statusmarkers#dead|Red 3, statusmarkers#red:3} Update v0.8.12 &nbsp;-- Fixed explicit set with = for number and numberText fields. (Thanks again, Ziechael!) Update v0.8.11 &nbsp;-- You can now preface a + or - number with an = to explicitly set the field to that value (Thanks Ziechael!) !token-mod --set light_radius|=-10 Update v0.8.10 &nbsp;-- You can now set light_losangle and light_angle to be 360 degrees (Thanks Vince!). &nbsp; !token-mod --set light_losangle|360&nbsp; Added a syntax to allow incrementing and decrementing status markers without adding statuses on other tokens. &nbsp;Also removes the status marker when the number reaches 0. (Thanks DK Heinrich!). !token-mod --set statusmarkers|?red:-1 Update v0.8.9 &nbsp;-- Added the argument --ignore-selected which allows writing macros that won't change any tokens that happen to be selected. !token-mod --ignore-selected --set statusmarkers|red:3 --ids -Jny0PfbtztLnCQv4M5y This is most useful when you are using hidden tokens as a backing store for state information (time, rounds, money, etc). &nbsp;(Thanks OldSchoolChris!) Update v0.8.8 -- Added expansion of Rollable Tables. You can now specify rollable tables in places you would use text: !token-mod --set name|"[[ 1t[ClueNames] ]]" Be sure to put " " around the call if you have multi word results. (Thanks Pat!) Update v0.8.7 -- Fixed crash when attempting to affect graphic tokens with bar*_reset operations. (Thanks RMcD!) Update v0.8.6 -- Added bar1_reset, bar2_reset, bar3_reset. You can use them to set a bar back to it's max value while selecting many tokens: !token-mod --set bar2_reset| This will individually set each token's bar2_value to whatever it's bar2_max is. The | is still required because of the way the parser is written, but I might be able to remove that later. Hope that helps! Cheers! (Based on this discussion , thanks RMcD!) Update v0.8.5 -- Bugfix for empty list of statuses. Update v0.8.4 -- Bugfix against an undefined statusmarkers return. Update v0.8.3 -- Fixed some log message detritus. Update v0.8.2 -- Added multiple status markers. I haven't updated the help for it yet, but basically, anything that works for a single status works for one with an index. The first command here sets the blue status marker on with a number of 1. The second line adds a second blue status marker and sets it's value to 2: !token-mod --set statusmarkers|blue:1 !token-mod --set statusmarkers|blue[2]:2 You can use an empty set of brackets to add a new marker: !token-mod --set statusmarkers|blue:1|blue[2]:2|blue[]:3 Just like other status operations, you can add all of these at once: !token-mod --set statusmarkers|blue:1|blue[2]:2|blue[]:3 Markers are indexed from 1 starting at the left most marker of a particular type. New markers are added to the right, so multiple markers can be interspersed as you like. Update v0.8.1 -- Added support for Multi-line commands via {{ }}, light_multiplier, startup version logging, and config API Button. You can now use the multiline syntax for your TokenMod commands: !token-mod {{ --set light_radius|40 light_dimradius|0 light_multiplier|1.5 layer|objects --flip showname --off light_otherplayers --set bar1_value|25 bar2_value|Foe --ids @{target|target 1|token_id} @{target|target 2|token_id} @{target|target 3|token_id} }} An API startup, it will now log out the version number and last update date: "-=&gt; TokenMod v0.8.1 &lt;=- [Sun Mar 29 2015 00:40:56 GMT-0500 (CDT)]" This will get updated as I make further changes (coming soon to all my scripts!) The Help menu is reorganized a bit, and there is now a toggle button for turning on/off Players Can IDs. Update v0.7 -- Added support for unlinking bars by passing an empty Attribute Name. (Thanks Ari K.!) Update v0.6 -- Switched to git and pushed into the Roll20 Official repo as well. Update v0.53 -- You can now toggle status markers on and off by prefacing them with the ! symbol. This will add the Rook piece if it isn't there, but remove it if it is: !token-mod --set statusmarkers|!white-tower Adding with a number will set the number if the status was not present, so this would add blue with a value of 3 if it wasn't already there, but clear it if it was: !token-mod --set statusmarkers|!blue:3 Adding relative numbers is less useful since they would always be operating on 0 (if the status wasn't there) or not being applied (because the status is being removed if it was there already), but they don't cause an error. I also expanded the help to show --ids and how to use it for multiple token ids (Thanks John C.), as well as cleaning up a few other points. Update v0.52 -- Setting Number and Number or Blank can now be decimal. (Thanks Black Falcon) Update v0.51 -- Setting represents now supports character names instead of just character_id. You can use the full name (quoted if it contains spaces) or just a partial name that is unique among your characters. It is not case sensitive, so Max = max = MaX = MAX. Update v0.5 -- Added delta changes to all reasonable number fields. You can now specify +3 or -2 instead of just a number, even on status numbers: !token-mod --set statusmarkers|blue:-1 bar1_value|+3 This can be used on any field that is one of: Number, Number or Blank, Degrees, Text, Status Status fields will be bound between 0 or 9, other fields will not be bound. Also added the ability to set the represents for a token. You need only specify the character_id, probably with @{&lt;character name&gt;|character_id}: !token-mod --set represents|@{Bob|character_id} Note that this will clear out any links that bars have currently... So I've also added setting links for the bars, using the fields bar1_link, bar2_link, bar3_link. You need to specify the name of an attribute on the character the token represents. If you're specifying these in the same command as represents, be sure they are after: !token-mod --set represents|@{Bob|character_id} bar1_link|npc_HP bar2_link|npc_ac bar3_link|npc_temp_HP One final caution: There seems to be a bug with updating a token bar via the API when it is tied to an attribute, such that other tokens that are tied to the same attribute do not get updated. Be sure to leave a comment if you experience that, particularly if you can narrow down the case. Update v0.4 -- Added --config command for setting configurations. Currently the only config option is players-can-ids which allows players to use the --ids command to target tokens they don't control. Updated documentation to add bar1, bar2, bar3 meta properties, added notes about support for inline rolls in --set. Turn on players ability to use --ids with: !token-mod --config players-can-ids|on Play slots with this: !token-mod --set statusmarkers|red:[[1d9]]|green:[[1d9]]|blue:[[1d9]] Set hit points with this (sets both bar2_value and bar2_max to the result of the expression): !token-mod --set bar2|[[3d8+4]] Update v0.32 -- Added expansion of inline rolls and the Meta-Properties bar1, bar2, bar3 which set the _value and _max values to whatever is supplied. (Thanks for the suggestion Leo!) Update v0.31 -- Minor update to fix the issue with HTML special entities. Update v0.3 -- Fixed a bug with --ids (Thanks again James!) Update v0.2 -- Fixed a bug with colors, made the help work for non-GMs. (Thanks James!) This script lets you change just about any property of a token from a macro or the chat (Thanks GenKitty for the idea!). You can only change tokens you control (enforced by the ability to select them), unless you are the GM, in which case you can specify token_ids with the --ids command. The same operation is applied to all selected tokens, so it makes batch changes fast and easy. Commands !token-mod -- This is the interface command, with the following options: --help -- Displays the help script. --on &lt;arguments&gt; -- Toggles supplied boolean arguments to on. --off &lt;arguments -- Toggles supplied boolean arguments to off. --flip &lt;arguments&gt; -- Toggles supplied boolean arguments to their alternate state. On becomes off, off becomes on. --set &lt;arguments|values&gt; -- Sets an property to the supplied value. The help is extensive, but I'll hit the highlights below. --ids &lt;arguments&gt; -- The GM can supply a list of token_ids, probably with @{target|1|token_id}, etc. Details for --set Mostly, properties should work like you expect. If it's a color, it takes a color, if it's a number, it takes a number. Any argument with an invalid value is ignored. Here's a few examples that should make things clearer. Turning on name plates for all selected tokens: !token-mod --on showname Moving selected tokens to the gmlayer: !token-mod --set layer|gmlayer Turning on aura1 for players, setting it's radius to 35, setting it's color to blue: !token-mod --on showplayers_aura1 --set aura1_radius|35 aura1_color|0000ff Setting up 5e style darkvision, moving to the objects layer, flipping the setting on show names, set bar1 to 25, set bar2 to 'Foe': !token-mod --set light_radius|40 light_dimradius|0 layer|objects --flip showname --off light_otherplayers --set bar1_value|25 bar2_value|Foe I've carefully ignored status markers until now. Status markers have a more complicated syntax to allow more flexibility. Multiple status markers can be set at the same time, this will add the blue, green, red, padlock, and broken-shield status markers. !token-mod --set statusmarkers|blue|green|red|padlock|broken-shield They can also take a number by appending it with a : separator to the end of each status name. (note that the number following the dead status is ignored, as it is special.) !token-mod --set statusmarkers|blue:0|green:3|red:9|padlock:7|broken-shield:8 Numbers are bound between 0 and 9. You can also remove status markers by prefacing them with a -. This will remove the blue and broken-shield status markers: !token-mod --set statusmarkers|-blue|-broken-shield If you want to completely clear all status markers when you set your new one, you can preface it with a =. Note that this will affect all previously applied status markers, even if you are applying them as part of this same set command. This will set only the red, green, and blue markers: !token-mod --set statusmarkers|=blue|green|red If you need to just remove all status markers, you can specify the same status marker twice, first with = and second with -: !token-mod --set statusmarkers|=blue|-blue Example using --ids and other things: !token-mod --set layer|objects aura1_radius|35 aura1_color|00ff00 tint_color|transparent --on showname --ids @{target|token_id} Here's the help (a bit fuzzy, I know... ), but you can see it in the game with: !token-mod --help GitHub: <a href="https://github.com/shdwjk/Roll20API/blob/master/TokenMod/TokenMod.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/TokenMod/TokenMod.js</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.
1413193838
Gen Kitty
Forum Champion
Aaron, I adore you. I will test this stuff this evening when I've time to really poke at it.
1413204801
The Aaron
Roll20 Production Team
API Scripter
:)
I am checking it out today, I had just ask @King if his summoning script could do some of the stuff i believe this script will do. You don't do small do you? Great looking script! Thanks for what you do for the community. Jim
1413211708
The Aaron
Roll20 Production Team
API Scripter
Yeah, my brother keeps telling me "better is the enemy of good enough," but I just keep ignoring him. =D Really, I just like to be thorough... Let me know if you need any more features, or have any issues! =D
Aaron, Using this script can a player write a macro to bring a token back from the gmlayer to the objects if the ids is known?
1413216022
The Aaron
Roll20 Production Team
API Scripter
Nope. Players can only affect tokens they can select. Only the GM can pass token ids with the --ids option. However, it wouldn't be too difficult to adjust that so that they could pass ids and it would strip out the ones they didn't control. That said, they'd have to know the token ID to do it with, and it would be different for each page's copy of the token. I could add an option for looking for a token that represents a character and is on the page the player is currently on.
=-( roll20 needs to add another layer that players can use...
1413216786
The Aaron
Roll20 Production Team
API Scripter
Right, but I think I can still solve that uses case for you. (And just to be clear, the select limitation is one that I have imposed. =D) The only complicated part is how to handle character id derived tokens for the GM, who does not have a page to consider. Could just use the current players page or the GM's page if his avatar is dragged to another. That would make it work identically to the players, with the added annoyance that it might not be the page that the GM is currently on. =D
Holy ding dong Aaron... this is awesome, just what I've been missing !!! Thanks A LOT!! - I'll test it out in a moment. //Lukas
1413288125
The Aaron
Roll20 Production Team
API Scripter
Thanks Lukas! Let me know if it needs anything!
I have a newbie question, about the -ids and it's use. Lets say I make a macro and call it "Room-Darkness" I'll hit this button everytime the players are in complete darkness, and I'd like to have it autoamtically set the sight and light of all the characters, except the one that has "Darkvision" Would it be possibly? and what would that macro look like? Something like !token-mod --set light_radius|40 light_dimradius|0 --off light_otherplayers --ids -JRQ43K2KTXuuunwlYDk !token-mod --set light_radius|5 light_dimradius|5 --off light_otherplayers --ids -JRQ43Jh9VHZJtKWESXa
1413294073
The Aaron
Roll20 Production Team
API Scripter
If you know their Token IDs, it would be possible. I mentioned above that I might add a method for adding Character IDs. Token IDs are specific to each instance of a character's token on each page. Character IDs are constant for the campaign. That means you would need a button specific to each page of your campaign if you are using Token IDs. I guess that should be feature request #1. To do it, you would do just like you have above, save that you can put all the ids together: !token-mod --set light_radius|40 light_dimradius|0 --off light_otherplayers --ids -JRQ43K2KTXuuunwlYDk -JRQ43Jh9VHZJtKWESXa -JAdfafd123s342sdfs -JR1243a23asadf141 -J8134adfadfasas2ffad You could also just create the macro without the --ids, and select them all and run it: !token-mod --set light_radius|40 light_dimradius|0 --off light_otherplayers Or you could have it take targets: !token-mod --set light_radius|40 light_dimradius|0 --off light_otherplayers --ids @{target|Character 1|token_id} @{target|Character 2|token_id} @{target|Character 3|token_id} @{target|Character 4|token_id} @{target|Character 5|token_id} @{target|Character 6|token_id} With fewer than 6 tokens to click, you would just click the same one for the remaining targets and the script eliminates duplicates. (You can actually do all three of those code blocks with my Torch script, too. It provides !torch , !snuff for players and GMs to control light. As well as !nighttime and !daytime which allow the GM to toggle the dynamic lights on a page.)
Should this work? !token-mod --set layer|objects --ids -JZBUpMQ8acO81EYRUK4
1413309943
The Aaron
Roll20 Production Team
API Scripter
Yes, it should, provided you are a GM (as identified by the isGM script, say something as yourself with the (GM) moniker to be sure) and -JZBUpMQ8acO81EYRUK4 is a valid token id.
I am getting this: Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: Unexpected token + I have a test campaigns that I am running the script on, I will now remove all scripts expected TokenMod and IsGm and retest.
1413311050
The Aaron
Roll20 Production Team
API Scripter
PM me an invite and I'll jump in and take a look!
1413311100
The Aaron
Roll20 Production Team
API Scripter
It's probably this bug: <a href="https://app.roll20.net/forum/post/1258350/api-html" rel="nofollow">https://app.roll20.net/forum/post/1258350/api-html</a>...
I see something like that on line 190
1413315383
The Aaron
Roll20 Production Team
API Scripter
Update v0.2 -- Fixed a bug with colors, made the help work for non-GMs. (Thanks James!)
1413315685
The Aaron
Roll20 Production Team
API Scripter
Update v0.3 -- Fixed a bug with --ids (Thanks again James!)
No Problem, thank you!
Love it! I am adding this to power macros like "warlocks curse". It should help speed up things. !token-mod --set statusmarkers|overdrive --ids @{target|Target 1|token_id}
1.) I broke version = 0.3 I was running this command in chat, on a token that didn't have an aura set, i didn't notice anything change, so I checked the API and re-saved. As soon as I saved I received this message: "Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: Unexpected token + " I fixed it by cut and pasting the script over itself and it is now working, although I don't seem to be able to set auras on all the tokens, some take it some don't. 2.) Question one, is there a way to set letters (a.b.c...) instead of numbers on status markers? 3.) Question two, is there a way to get a screen location like how the @{target|Target 1|token_id} works, maybe @{target|Target 1|loc}? 4.) Question three, Do you have a list of your Roll20APIs Jim
1413480548

Edited 1414527511
The Aaron
Roll20 Production Team
API Scripter
2) nope. Limitation of Roll20 3) not currently. I can certainly write something that finds tokens based on coordinates. 4) <a href="http://gist.github.com/shdwjk" rel="nofollow">http://gist.github.com/shdwjk</a> - no discussion here, of course, but all the scripts are there. You can take the URL of a script and search the forum to find the original discussion though. :)
Thank you. Keep Calm and Code On! Jim
1413491919
Falcon
Pro
Sheet Author
The Aaron is THE MAN!
1413492534
Falcon
Pro
Sheet Author
Aaron - Is there a way to lower all token numbers on the map? For example at the end of the round all status markers need to be lowered by -1. Or do I have to name them one by one?
1413492900

Edited 1414526571
The Aaron
Roll20 Production Team
API Scripter
I'm not aware of a script that does that currently, but I could add increment/decrement operations to Token-mod, as well as some alternate token selection methods (all on page). Then we'd just need a way to cause it to happen automatically. Alternately, it wouldn't be too hard to write a script that listens on the turnorder change, and when it moves off a token, decrements all it's status marker numbers by one, removing (optionally) any that reach 0.
I've got an initiative/status tracker that does something like that. It's primarily for personal use, so it's a bit quirky and not as polished as it could be, but you might be able to get some use out of it: <a href="https://github.com/manveti/roll20/blob/master/trac" rel="nofollow">https://github.com/manveti/roll20/blob/master/trac</a>... It adds two commands: !tracker for showing/modifying the initiative tracker configuration, and !status for managing tracked status effects. Each status effect has a duration, an icon ("!status icons" for a list of icon names, in the same order they are in the selection box), and a description (displayed when you do a "!status list" and when the effect expires if expiration announcements are enabled).
There is a script Black Falcon said: Aaron - Is there a way to lower all token numbers on the map? For example at the end of the round all status markers need to be lowered by -1. Or do I have to name them one by one? you could modify the Conditions tracker script currently on the Roll20 list.
The Aaron , When is v0.4 -- that allows players to use --ids without being a DM/GM? Jim
1413732580
The Aaron
Roll20 Production Team
API Scripter
Soon, hopefully I can work on that today!
Super sweet, if you have not heard Jonathan Coulton aka JoCo's song code monkey, you should!
1413746914
The Aaron
Roll20 Production Team
API Scripter
I definitely have. =D
how about re: ur brains and Tom Cruise Crazy?
1413749516
The Aaron
Roll20 Production Team
API Scripter
Haven't heard Tom Cruise Crazy, but I've heard a lot of them. =D
Good stuff =-)
LOVING this script, I've been going nuts with it! Making stuff like conditions macros, Torch and vision macros for the players (im assuming it works kinda like your torch mod) and even player usable doors! The only thing i'd love to see is this usable by the players (example: when my Drow player casts Faerie Fire, I've made a macro that adds a small aura to the target) I'd love to be able to put that command in his spell macro.
1414210139
The Aaron
Roll20 Production Team
API Scripter
Glad you're liking it! I'm hoping to get some of that working this weekend. =D
Hi Aaron. I have a request for your script if you are willing. I'd like the ability to assign linked attributes to a token that represents a character. Input: !token-mod --set bar1_link|npc_AC --set bar2_link|npc_HP Logic: If the token "represents" a character (if not spit an error), Find the ID of the attribute object linked to the name in the command Set the bar1_link to that ID Set the values of the bar according to the ID Worth it?
I'm getting those attribute names off the D&D 5e character sheet, which I'm starting to assemble for a campaign. I was about to write a script to do all of this for token management, but you have done all of the heavy lifting here.
1414524899
The Aaron
Roll20 Production Team
API Scripter
Probably. =D Either way, it shouldn't be too hard. I should probably add a syntax for setting which character it represents as well.
1414527436
The Aaron
Roll20 Production Team
API Scripter
Update v0.31 -- Minor update to fix the issue with HTML special entities. Prepping for doing v0.4 work. I've replaced all the &amp;#39; type things with a call to a function that constructs them, thereby alleviating the issue where they get converted by the API Scripts page, thus breaking the script.
1414554584

Edited 1414554638
Hello, Thanks again for the great script! I know that it's been around for some time but I'm just discovering it. I wonder if you could use it to set monsters HP. For example, I was hoping something like the following line would work: !token-mod --set bar2_max|[[2d6]] This simply sets the bar2 maximum value to $[[0]] . Is there a different syntax that could make this work? Or alternatively, do you know a way to save the result of a dice roll on a temporary variable, then reference the value from that variable on the !token-mod call? Thanks, Leo
1414556995
The Aaron
Roll20 Production Team
API Scripter
Thats a great idea! However, !token-mod --set bar2_max|[[2d6]] will probably be unsatisfactory, as you'll have a current of blank and no way to set it to the right value... ... which is why I added 3 new set parameters: bar1, bar2, bar3 You can now do this: !token-mod --set bar2|[[2d6]] and it will set the value and max both to the result of the 2d6. Note that the 2d6 will be the same for all selected or supplied tokens. I'm in the middle of some updates for v0.4, so I haven't fully documented this feature yet, but you can start using it immediately in version v0.32.
1414557082

Edited 1414557148
The Aaron
Roll20 Production Team
API Scripter
Update v0.32 -- Added expansion of inline rolls and the Meta-Properties bar1, bar2, bar3 which set the _value and _max values to whatever is supplied. (Thanks for the suggestion Leo!)
1414561259
The Aaron
Roll20 Production Team
API Scripter
Update v0.4 -- Added --config command for setting configurations. Currently the only config option is players-can-ids which allows players to use the --ids command to target tokens they don't control. Updated documentation to add bar1,bar2,bar3 meta properties, added notes about support for inline rolls in --set. Turn on players ability to use --ids with: !token-mod --config players-can-ids|on Play slots with this: !token-mod --set statusmarkers|red:[[1d9]]|green:[[1d9]]|blue:[[1d9]] Set hit points with this (sets both bar2_value and bar2_max to the result of the expression): !token-mod --set bar2|[[3d8+4]]
1414561283

Edited 1414561415
Awesome @`The Aaron`! Thanks for the fast update =) I'd like to try it out but gist.github.com / shdwjk/357e0632a1096375de58#v0.32 (I broke the link to avoid getting the long preview) seems to still be version 0.31 (supposedly 9 hours ago, so 8 hours before you posted about the changes). Anyhow, I'm sure that you are testing and tweaking things (or sleeping, are you human!? hehe). See you tomorrow!
ohh! It's up to v0.4 now!
1414561713

Edited 1414561739
The Aaron
Roll20 Production Team
API Scripter
Yup. Gists have always been weird on the forum. Usually changing the url will get you an updated display in the forum, but it doesn't seem to be doing it right now...