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 Update] TokenMod -- An interface to adjusting properties of a token from a macro or the chat area.

1717637356
The Aaron
Roll20 Production Team
API Scripter
I can't imagine how TokenMod could affect that.  It doesn't have any events for `add:graphic` so should not become active in those cases.
Jarren said: This is a current known bug, reported here . I suggest adding your comment there to see if others also have some resolution if they disable TokenMod, and if that's the case then I'm sure TheAaron will start taking a look right away! :)  You can also  file a  Help Center Request  to get more visibility on the issue. Thanks for the heads up i'll look into it there than.
1718211071

Edited 1718300260
Playing D&D 5e using the  D&D 5E for Roll20  character sheet. When I use the following macro to set a token's vision, the night vision color becomes set to black (#000000) instead of "transparent" as designated in the macro: !token-mod {{ --set bright_vision|on night_vision|on night_vision_distance|60 night_vision_effect|nocturnal night_vision_color|transparent has_directional_bright_light|off directional_bright_light_center|360 directional_bright_light_total|0 light_color|transparent }} Here is a screen shot of the token settings after using this macro: EDIT: I got the color setting to change correctly by adding the following to the macro before the final "}}": --ignore-selected --ids @{target|Target 1|token_id} The annoying consequence of this is that I now can't select multiple tokens when applying these vision settings. I have two PCs who have items that give them darkvision; I use this macro when they activate those items.
1718300740

Edited 1718300784
Hi there I wasn't sure where to post this (and it could possibly be a bug with a jumpgate update itself). I GMed a game yesterday where one of my players were perfectly able to use the currentside property to switch sides of their token. I have come on today to make changes to the macro that does this (the character can now change sizes so was adding that into the macro). I have found that the currentside property no longer is working. I have created multiple new multisided tokens, wrote the command directly into chat while token selected, but there is nothing happening. The rest of the tokenmod commands work perfectly (the resizing, adding of status marker, moving) just not the currentside. Trying in a non-jumpfgate game it works perfectly which is why i think it is a jumpgate centric problem but thought I would ask/make it known here. I wonder if they have broken multisided tokens.
RPGMer said: I have found that the currentside property no longer is working. I have created multiple new multisided tokens, wrote the command directly into chat while token selected, but there is nothing happening.  What is the macro code you are using?
Apologies, I wrote all that and forgot to include the actual macro; !token-mod --set currentside|2 !modbattr --sel  --silent --other_resource|-1 /w gm Number of shifts left: [[@{other_resource}-1]] I have it set as a token action to make sure they have the token selected when performing the macro. I have it on another token that also and that doesn't work either. All i can conclude is that they did something in the latest jumpgate update that effected multi-sided tokens
1718406149
The Aaron
Roll20 Production Team
API Scripter
One thing to check is if the images you are using in the sides are in the user library or marketplace.  The production API can't set marketplace images at all, even by setting the current side.
They are both images I've uploaded myself. It was working perfectly when we played on Tuesday but then when I was testing the changes to the macros on Wednesday it no longer switched.
Hi scripters, is there a way to use TokenMod (and potentially other scripts) to do this: Select some tokens Set the color dot status marker (say purple) for each token with ascending number 1, 2, 3 ... Something like below but 1 goes to 2 for the next token, 3 the next token, and so on --set statusmarkers|purple:1 I'm not too bothered if the method runs out of numbers after 9, would be nice if it can cycle through colours but 9 numbers is usually plenty. The intent is to quickly and easily number any tokens. I know about TokenNameNumber but wanting a way that doesn't require the token names to be set with the placeholder. Something that will work with any token with minimal setup.
I don't have a specific solution that matches what you are looking for, but there are two other options that may satisfy you: Create a single macro that will number all selected tokens without any previous setup .  Just select a group of tokens and run this command (I have it saved as a Collections Macro called 'RenumberTokens': !token-mod --set name|"?{New Token Name?|@{selected|token_name}} %%NUMBERED%%" !tnn --renumber Yes, it will still add numbers to the tokens, but it satisfies your intent to quickly and easily number any tokens and doesn't require  having their default token set with %%NUMBERED%%. You can also turn on the Colored Dots option with TokenNameNumber . Just use the TNN command '!tnn-config --toggle-use-dots' and each token will get a unique set of colored dots.  You can configure which dots to use (or not use) in the config menu as well, so if you use a red dot for some specific other meaning, then you can exclude it from being used for TNN. In terms of giving each token a unique number on a colored dot, that should be possible.  FlyMore can add numbers to colored dots (or custom status markers), so you'd just need a way to add logic for randomizing the number and making it unique on each token. I believe some combination of the Metascripts  can do this.
1719584439

Edited 1719584618
timmaugh
Pro
API Scripter
Here is how to do that with the Metascript Toolbox in combination with TokenMod: !forselected(^) token-mod --set statusmarkers|-purple[]|-purple[]|{^&if {&i+1} > 9}purple[]:{^&math floor({&i+1} / 10)}|{&end}purple[]:{^&math {&i+1} % 10} That will first remove all purple markers from each token (it should only take one instance of  -purple[]  to remove all purple markers, but it isn't working for me, for whatever reason -- I've reached out to Aaron for some help on that). For now, the above command is set up to work from 1-99, so I only have to remove up to 2 purple markers, anyway. Then it uses the forselected index tag {&i} to know what number of token it is working with (it counts up with every new token selected and worked on). I add 1 to the base: {&i + 1}  ...so that we start at 1 rather than 0. After that, it's just math... if we're over 9, we'll need a tens digit, so we extract that... then the ones digit is just {&i} modulo 10. As an Added Trick... For my set up, I used a similar command to first name my tokens (though this could be combined with the TokenMod line, above). I manually selected them on the VTT and ran: !forselected token-mod --set name|Obelisk{&i+1} That gave me tokens named Obelisk1, Obelisk2, etc. From then on, when I want to select those tokens as a group, I don't have to physically select them on the VTT... I can use: {&select Obelisk*} ...and they will become the selected tokens for the purposes of the message. So I can add that {&select} tag to the first command and arrive at: !forselected(^) token-mod --set statusmarkers|-purple[]|-purple[]|{^&if {&i+1} > 9}purple[]:{^&math floor({&i+1} / 10)}|{&end}purple[]:{^&math {&i+1} % 10} {&select Obelisk*} Then I don't have to actually select the tokens on the VTT. EDIT : The above could easily be expanded to accommodate orders of magnitude... so up to 999 tokens, or up to 9999 tokens... but... what kind of masochist do you want to be? I always say, "Set your sights high," but... I mean... damn. =D
Reposting this because it must have got missed in the flurry of other posts :) Playing D&D 5e using the  D&D 5E for Roll20  character sheet. When I use the following macro to set a token's vision, the night vision color becomes set to black (#000000) instead of "transparent" as designated in the macro: !token-mod {{ --set bright_vision|on night_vision|on night_vision_distance|60 night_vision_effect|nocturnal night_vision_color|transparent has_directional_bright_light|off directional_bright_light_center|360 directional_bright_light_total|0 light_color|transparent }} The work-around that I mentioned in my previous post (adding  --ignore-selected and  --ids @{target|Target 1|token_id}) stopped working after the first day for some reason. Yes, I tried clearing cache, logging out then back in and  re-starting, and also in incognito mode. This also happens when I use Firefox instead of Chrome. This may have something to do with the color for night vision always defaults to black    (#000000), no matter what I set up under the game settings (yes, I've sent in a bug report about that weeks ago, and they've been 'looking into it')
Thanks Jarren and Timmaugh, both of your methods work as advertised. Will play around with both to see which one suits the group best.
1722709729
Siveron
Pro
Marketplace Creator
There are a lot of pages to look through and I am sure what I need is very easy to do. I need a command to change the current and the max HP of a group of creatures. Basically, I need to modify every single monster on a map. If there are 15 werebats, I want to change all of their max and current HP to 42. I tried !token-mod --set bar1_42 and it did nothing.
Siveron said: There are a lot of pages to look through and I am sure what I need is very easy to do. I need a command to change the current and the max HP of a group of creatures. Basically, I need to modify every single monster on a map. If there are 15 werebats, I want to change all of their max and current HP to 42. I tried !token-mod --set bar1_42 and it did nothing. Your syntax is incorrect. !token-mod --set bar1|42 or  !token-mod --set bar1#42
1722719654
Siveron
Pro
Marketplace Creator
Perfect!!! thank you so much. I knew I was missing something stupid-simple.
1722726843
The Aaron
Roll20 Production Team
API Scripter
You can also specify --ids @{werebat|character_id} to get all Werebat tokens in the game, or add --current-page to get all the tokens on the page you're on.  
1722913088
Siveron
Pro
Marketplace Creator
That will definitely make things MUCH faster... now for the next challenge... the reason I am needing/wanting to do this is because I have a pre-written campaign (DOTTM). It is written for 4 players, but I have 6 players in the game. As you can imagine there are probably 100 monsters in the campaign. With each monster is given the average HP, my goal is to set each token to the MAX HP instead of the average. I assume that is not something I could do easily and that I will have check what the possible max HP is for each monster, then use the command like this !token-mod --ids @{Animated Armor|character_id} --set bar1|144.
Siveron, not to hijack the TokenMod thread but one possible option is you could use ScriptCards for this. ScriptCards can be used to calculate the max hp from the npc_hpformula attribute and either set the token's HP directly or call token-mod to do it. ScriptCards even has the ability to execute on certain events like adding a graphic. I have a ScriptCards trigger to randomize NPC HP based on the formula. It could easily be modified to do max HP instead of random. If you want to go down that route, you could make a new thread here or add a post to the ScriptCards thread  and I could help you out. I'm sure there are other possible options, I bet timmaugh could calculate max HP from the npc_hpformula with some MetaScript magic.
1722924353
timmaugh
Pro
API Scripter
Ha! I appreciate the confidence, Joshua! I do need to get some more string manipulation functionality into the Metascript Toolbox, but for this one I think you could manage with just the Plugger replace() function. Assuming the max HP for a formula like "2d8+6" would be 22, then the way to get that from the toolbox would be: {&math {&eval}replace(--source|@{selected|npc_hpformula} --find|d|*){&/eval} } To see that output to the console, start it with a bang (!) and include a {&simple}: !{&math {&eval}replace(--source|@{selected|npc_hpformula} --find|d|*){&/eval} }{&simple} Putting that in the TokenMod line, you don't need the {&simple} (since that stops the message from continuing on to TokenMod, which is what we want). This command sets the bar1_max value to be the result of the npcformula: !token-mod --set bar1_max|{&math {&eval}replace(--source|@{selected|npc_hpformula} --find|d|*){&/eval} } Solution But, to make this most efficient -- to make it so you wouldn't have to select specific NPCs based on their creature type -- you can use a {&select} statement to get your NPC tokens on the page,   a forselected operation to iterate over those tokens,   and a Fetch retrieval of the individual token's npc_hpformula: !forselected(^) token-mod --set bar1_max|{^&math {^&eval}replace(--source|@^(selected.npc_hpformula) --find|d|*){^&/eval} } {&select *, +npc} Extended Solution That only gets you the max value for bar1. If you also wanted to get each individual token an individual value for the current value of bar1, you can set it in the same TokenMod command we are iterating. Here is a version that writes the max value like we did, just above, but which then also *rolls* the formula to see what the current value should be -- and all on a token-basis. !forselected(^) token-mod --set bar1_max|{^&math {^&eval}replace(--source|@^(selected.npc_hpformula) --find|d|*){^&/eval} } bar1_value|{^&r}@^(selected.npc_hpformula){^&/r} More Cowbell: Really Exploring the Space There are different approaches to getting the current/max values for a given creature. Options for Deriving Max Value Take the maximum possible value of the hp formula (as if every die had maxed out). This is what we did, above. Or... Roll the formula for max (a specific max for this instance of this creature type), or... Use the formula to roll for current, but use that value as the max value, too.  Options for Deriving Current Value Use the formula and roll for *actual* current HP. Or... Once you've derived a max HP value for this token, roll some number of dice to subtract that many hits and use that as the current value. Or... Roll for Current value using the HP formula, and use the value as both  The above "extended solution" is just one way of using the formula to derive max and current values. If it doesn't fit what you're doing, post back with the rule you'd rather follow (just a verbal explanation), and we can tweak the command line to make that happen.
I have a Macro Button for quick use of healing potions in game.  Just click it, pick your potion and it gives you the roll result... Easy Peasy.  But the player is then required to update their token.  And here is this spectacular API mod that SHOULD allow the token to just get updated, but I can't for the life of me figure out the syntax to make it work. &{template:default} {{name=Healing Potion}} {{Effect= ?{Choose a Potion? | Healing, **Potion of Healing** @{selected|token_name} Regains [[2d4+2]] HP. | Greater Healing, **Potion of Greater Healing** @{selected|token_name} Regains [[4d4+4]] HP. | Superior Healing, **Potion of Superior Healing** @{selected|token_name} Regains [[8d4+8]] HP. | Supreme Healing, **Potion of Supreme Healing** @{selected|token_name} Regains [[10d4+20]] HP.} }} and if I'm reading the documentation correct, then I would want to use ! token - mod - - set bar1_value | $[[0]] or ! token - mod - - set bar1_value# $[[0]] to then use the dice roll to update the value of the token, but I'm in the weeds here about the right syntax to include that api call to update the selected token as a part of the overall selected line of code.
1723903914
The Aaron
Roll20 Production Team
API Scripter
The TokenMod part would look like: !token-mod --set bar1_value|+$[[0]]! The + tells it to add the value, the ! tells it to not go over the max value, and it defaults to the selected token. You'll have to test to make sure you're getting the value you expect with $[[0]]. You can leave the leading ! off and see what gets sent to chat to make sure. 
1723904857

Edited 1723905804
Hrm.... Ok, so when I try this: &{template:default} {{name=Healing Potion}} {{Effect= ?{Choose a Potion? | Healing, **Potion of Healing** @{selected|token_name} Regains [[2d4+2]] HP. | Greater Healing, **Potion of Greater Healing** @{selected|token_name} Regains [[4d4+4]] HP. | Superior Healing, **Potion of  Superior Healing** @{selected|token_name} Regains [[8d4+8]] HP. | Supreme Healing, **Potion of Supreme Healing** @{selected|token_name} Regains [[10d4+20]] HP.}}} !token-mod --set bar1_value|+$[[0]]! I don't get the expected behavior, that is, none of the bar values are changing.  Is it placement? ETA: I've tried it at different scope levels and don't get a status bar change.
1724051387
Chris Jones
Pro
Sheet Author
Apologies if this has already been asked - its quite the thread! Is there a way to link this macro to a character sheet, so when I click a button on the sheet, it effects that sheet's token without having to manually select the token first? I've got my buttons working in general here, but only when the token's selected first.
1724062804
The Aaron
Roll20 Production Team
API Scripter
Chris Jones said: Apologies if this has already been asked - its quite the thread! Is there a way to link this macro to a character sheet, so when I click a button on the sheet, it effects that sheet's token without having to manually select the token first? I've got my buttons working in general here, but only when the token's selected first. You can pass a character id to --ids to affect all tokens that represent that character. 
1724068176
Chris Jones
Pro
Sheet Author
I'd been trying something to that effect, and I can get it working when I specify a name - such as: <button class="details-roll" button type="roll" title="Token Mod roll" value="!token-mod {{--set statusmarkers|!white-tower --ids @{ john_Doe |character_id} }} " name="roll"></button> But when I use a variable - such as the attr_character_name it doesn't function: <button class="details-roll" button type="roll" title="Token Mod roll" value="!token-mod {{--set statusmarkers|!white-tower --ids @{ attr_character_name |character_id} }} " name="roll"></button> I know how to find a character ID from a token in general, I just don't know if this can be done dynamically.
1724107397

Edited 1724107523
vÍnce
Pro
Sheet Author
@Chris Jones are you literally using "attr_character_name"?  The "attr_" portion is only used in the character sheet code to create/link an attribute with the sheet. AFAIK, it's never used outside of that. Try using "character_name" instead.
1724139458
Chris Jones
Pro
Sheet Author
Morning, using: <button class="details-roll" button type="roll" title="Token Mod roll" value="!token-mod {{--set statusmarkers|!white-tower --ids @{ character_name |character_id} }} " name="roll"></button> doesn't work either - I can only update a token when I have it selected, not just via the character sheet
1724160297
timmaugh
Pro
API Scripter
Chris Jones said: Morning, using: <button class="details-roll" button type="roll" title="Token Mod roll" value="!token-mod {{--set statusmarkers|!white-tower --ids @{ character_name |character_id} }} " name="roll"></button> doesn't work either - I can only update a token when I have it selected, not just via the character sheet I think this might be a problem of when things are resolving. If this text is sent when the button is clicked: !token-mod {{--set statusmarkers|!white-tower --ids @{character_name|character_id} }}  ...then "character_name" will never resolve. When that command line is sent through the chat, Roll20 sees the @{character_name|character_id} construction, and it looks for a character named "character_name". You are wanting a way, at design time, for the character sheet to know -- at run time -- what the name of this particular character is. The only way (other than selecting the token so that you can use @{selected|character_id} ) is to refer to the @{character_id} attribute -- which is the shorthand way you can refer to attributes/properties from the character sheet. So, that construction won't work for buttons that originate off the character sheet (like chat buttons generated by typing them into chat, where you don't have the context of the character sheet), but from the character sheet, you should be good to get the character ID in that fashion.
1724171091
Chris Jones
Pro
Sheet Author
That all makes sense, thanks for looking over it and confirming :)
I am trying to add TokenMod to a Jumpstart game. I am always getting this message:  Possible infinite loop detected, shutting down. What if the fix?  
1726088363
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Paul! Do you have other scripts installed? I have token-mod installed on several Jumpgate games without issue.
1726105973
Andrew R.
Pro
Sheet Author
Same here. I install MetaScriptToolbox, TokenNameNumber, TokenMod, & ScriptCards in all my games and I’ve never seen that error message.  It might also be a clash with the Character Sheet, because they share the Sandbox too IIRC. 
Hi everyone. Complete novice who barely scrapes by with macros that turn lights on and off.  My brain isn;t wired for understanding new linguistic conventions and any level of "coding" remains elusive to me... I'm trying to think of up a macro for Call of Cthulhu 7E (Roll20 character sheet) where a player clicks their macro, chooses a weapon from a drop down, it applies the weapon icon to the token, and adds both the weapons base range and personal (DEX/5) Point blank in the form of 2 auras. I THINK Token Mod is the way forward, but I really need help. Anyone have an example of a macro that does something like this that already exists, that I can take a look at try to reverse engineer?  cheers in advance
1726333724
The Aaron
Roll20 Production Team
API Scripter
I'd start by creating a TokenMod command that does what you want.  TokenMod creates a handout with the help contents, and if you pop it out of the VTT, you can use ctrl-f to search it. This sets the auras visible, round, and at 10 units and 2 units radius: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set aura1_radius|10u aura2_radius|2u From there, you can modify it to use the actual values: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set aura1_radius|10u aura2_radius|[[floor(@{selected|DEX}/5)]]u  Then you can add this to a query: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set ?{Choose Weapon|Rifle,aura1_radius#10u aura2_radius#[[floor(@{selected|DEX}/5)]]u|Pistol,aura1_radius#5u aura2_radius#[[floor(@{selected|DEX}/5)]]u} Note that I swapped out the | (vertical pipe) for a # in the TokenMod parts in the Roll Query.  That prevents it from conflicting with the division between the options.
Thanks very much, I didn't know if I needed to somehow create an integer for the DEX thing to draw on, but this looks far easier to understand. I'm fairly sure I have the Icon thing figured out and can fit that into that query example. Just out of interest, what's the command syntax to turn off an individual aura, is it just reduce the aura to 0? Or is there a way to make them work like lights where you can effectively "store a setting" and flip between statuses? The Aaron said: I'd start by creating a TokenMod command that does what you want.  TokenMod creates a handout with the help contents, and if you pop it out of the VTT, you can use ctrl-f to search it. This sets the auras visible, round, and at 10 units and 2 units radius: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set aura1_radius|10u aura2_radius|2u From there, you can modify it to use the actual values: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set aura1_radius|10u aura2_radius|[[floor(@{selected|DEX}/5)]]u  Then you can add this to a query: !token-mod --on showplayers_aura1 showplayers_aura2 --off aura1_square aura2_square --set ?{Choose Weapon|Rifle,aura1_radius#10u aura2_radius#[[floor(@{selected|DEX}/5)]]u|Pistol,aura1_radius#5u aura2_radius#[[floor(@{selected|DEX}/5)]]u} Note that I swapped out the | (vertical pipe) for a # in the TokenMod parts in the Roll Query.  That prevents it from conflicting with the division between the options.
1726444009
The Aaron
Roll20 Production Team
API Scripter
You'd set them to empty to turn them off. 0 radius would be circle that fills the token only.  There isn't a way to toggle them on/off (though you could hide them from players, but your screen would be cluttered). 
The Aaron said: Chris Jones said: Apologies if this has already been asked - its quite the thread! Is there a way to link this macro to a character sheet, so when I click a button on the sheet, it effects that sheet's token without having to manually select the token first? I've got my buttons working in general here, but only when the token's selected first. You can pass a character id to --ids to affect all tokens that represent that character.  Hello - just to play things safe, running the -ids|on command allows players to edit all tokens without touching them, not just their own (ie Player "A" runs "!token-mod --set currentside|2 --ids @{<another players character>|character_id}", they can change a side that does not belong to them. Is there a way to give a player permission to do this with only characters which they have permission to use?