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.

1520113418
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Well, yeah, but... dice!
1520114275
Andrew R.
Pro
Sheet Author
This sounds like it needs a post in the Suggestions forum for an addition to the Dice Roll parser. ;)
Thanks all, it was to make encounters a little more challenging for my players, so maxing HP was a down and dirty way of doing it.
1520262032
The Aaron
Pro
API Scripter
So, if you want to just set the max value on a group of selected tokens, you can use: !token-mod --set bar1_max|20 It's only auto-calculating that 20 that it can't do.
Thatswhat I did, to be honest - made a macro with a query to fill the amount  !token-mod --set bar3|?{HP|0}
1520262878
The Aaron
Pro
API Scripter
Sweet. =D
1522021018

Edited 1522021033
GiGs
Pro
Sheet Author
API Scripter
Is there a way to update multiple selected tokens, linked to different characters, at once. For example, I have the following macro, which when I run it on a group of tokens, every token ends up with the same name: !setattr --sel --HPbar_Wound|0 !token-mod --set bar1_link| bar2_link| bar3_link| bar1| bar2| bar3|  !token-mod {{ --set bar3|@{selected|HP} --set bar2|@{selected|Armor_Value} --set bar2_max| --set name|'@{selected|character_name} %%NUMBERED%%' --on showname --on showplayers_name --off showplayers_bar1 --off showplayers_bar2 --off showplayers_bar3 --off light_hassight --set aura1_radius|0 --set aura2_radius|0 --set defaulttoken }}
1522021277
The Aaron
Pro
API Scripter
Not if you're using @{selected} or setting represents.  @{selected} can't resolve to more than one token.  You can almost get there by using HP and Armor_Value instead, it will assume they are on the represented character.  There isn't a way to fix the name though.  I could probably add something to support API side resolution of some pseudo @{selected} element, but that doesn't exist right now.
1522026963
GiGs
Pro
Sheet Author
API Scripter
Okay, thanks. It's still way faster than setting everything manually!
1522027024
The Aaron
Pro
API Scripter
no problem!
1522222354
Robin
API Scripter
Is it possible to flip a boolean with the --set command?  Something like !token-mod --set light_hassight#flip
1522226300
Ziechael
Forum Champion
Sheet Author
API Scripter
You can just use the flip syntax: !token-mod --flip light_hassight :)
1522226434
Robin
API Scripter
Yes, I know this, but I was doing it like this !token-mod --set ?{Status|Blinded, statusmarkers#!bleeding-eye} And now I wanted to also toggle the has sight.
1522227375
Ziechael
Forum Champion
Sheet Author
API Scripter
Okey dokey: !token-mod --set ?{Status|Blinded, statusmarkers#!bleeding-eye} --flip light_hassight
1522228168

Edited 1522228222
Robin
API Scripter
But that doesn't work with multiple conditions, maybe I can just put a second input after the first which let me choose if the token still has sight. edit: Also, statusmarkers added with tokenmod don't trigger the change:token event?
1522230641

Edited 1522230654
Ziechael
Forum Champion
Sheet Author
API Scripter
Hmm odd, my blasé response was untested... apologies for that... now digging deeper I can't even get the flip function to work in my test area... I'll back off slowly into the shadows and let the script author deal with this in his usual timely and expert fashion...
1522239391

Edited 1522239431
The Aaron
Pro
API Scripter
The problem with Ziechael's command is just the behavior of Roll Queries.  With only a single option, you get an edit instead of a list.  The other issue is that if you separate setting the status from flipping the hassight, when you do something like Slow for another status, things start to behave weirdly.  I suggest moving the flip inside the Roll Query: !token-mod ?{Status|Blinded, --set statusmarkers#!bleeding-eye --flip light_hassight |Slowed, --set statusmarkers#!tread} You could further separate the Blinded and Not Blinded statuses, which lets you assure that the status marker and the vision state both match by explicitly setting them rather than flipping them: !token-mod  --set ?{Adjust Status|Blinded, statusmarkers#+bleeding-eye light_hassight#off |Not Blinded,statusmarkers#-bleeding-eye light_hassight#on} but gives you a longer dropdown. It's a "feature" of the API that changes made by the API don't trigger events.  There are ways around it, but it requires an "Opt-In" approach for all the scripts.  TokenMod will tell it's Observers whenever it changes a token.  The calling signature is the same as the event, so scripts that want to handle TokenMod change:token events can do so.  The instructions are at the bottom of the TokenMod help, but here they are repeated: API Notifications API Scripts can register for the following notifications: Token Changes -- Register your function by passing it to TokenMod.ObserveTokenChange(yourFuncObject);. When TokenMod changes a token, it will call your function with the Token as the first argument and the previous properties as the second argument, identical to an on('change:graphic',yourFuncObject); call. Example script that notifies when a token's status markers are changed by TokenMod: on('ready',function(){ if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(function(obj,prev){ if(obj.get('statusmarkers') !== prev.statusmarkers){ sendChat('Observer Token Change','Token: '+obj.get('name')+' has changed status markers!'); } }); } }); Hope that helps!
1522243333
Robin
API Scripter
Thank you very much for your elaborate reply! I will check this all tonight, but this will definitly help!
1522243484
The Aaron
Pro
API Scripter
No worries, definitely post back if you have any more questions. =D
Is there a way to create attributes with token mod? As well as edit them?
1527172068
GiGs
Pro
Sheet Author
API Scripter
Anthony V. said: Is there a way to create attributes with token mod? As well as edit them? For that you need the ChatSetAttr script.
1527225476

Edited 1527257247
Edit - it's working now. Weird
1527262655
The Aaron
Pro
API Scripter
Glad you got it working again!
1528998859

Edited 1528998936
Sorry if this has been answered in another forum by now. I am new to GMing and am trying to make a macro that GM rolls HP for the selected NPC token based on the NPC character sheet HP formula then sets the current and max HP to the roll. Anyone know where I can find that formula or have one on hand? I have this which does the roll but don't know how to integrate it with tokenmod in setting the individual token's hp: /w gm @{selected|token_name}&{template:npc} {{name=@{selected|npc_name}}} {{rname=^{hp}}} {{r1= [[@{selected|npc_hpformula}]]}} {{normal=1}} Thanks!
1528999490
The Aaron
Pro
API Scripter
So, if you are doing this for a single Token, you can use this command: !token-mod --set bar1|[[@{selected|npc_hpformula}]] Assuming bar1 is where you put your hit points. If you select more than one token, they will all get changed. If you're wanting to do this automatically when you drag the token out of the Journal, I have a script called MonsterHitDice that does this (also works on copying existing tokens and pasting them.)
Awesome! Thank you! Now the unrelated part, as someone who knows nothing about scripts and APIs I have no idea what I actually need to do to get TokenMod running on my machine. I found the 2000+ line script but don't know what to do with it. Halp!
1529004828
The Aaron
Pro
API Scripter
Ah.  It doesn't run on your machine, it runs in the API sandbox for a Game that was created by a currently actively subscribed Pro user. If you are a GM in such a Game, you can install it from the 1-click drop down in the API Settings page. If you aren't, you won't have access to it I'm afraid.
I had a question, I posted in a separate place, but this may be a better location. Firstly, I'm using a short API script here, to add the big red X over dead tokens. on("change:graphic", function(obj) { if(obj.get("bar1_max") === "") return; if(obj.get("bar1_value") <= 0) { obj.set({ status_dead: true }); } else { obj.set({ status_dead: false }); } }); This simply adds the big red X over any token with 0HP. - However, when I combine it with my tokenmods macro... !token-mod --set bar1_value|-?{How much damage|0} The value will drop down to 0 (or even less) but the the other script won't...umm.... activate? - It's as if the other script doesn't realize that a attribute/stat has changed. Lastly, not sure if this makes any difference, I've ALSO include the mini-api you suggested  here . If i select the 0 in the circle, and hit enter on the keyboard... it will work ok. - But if i have to click in the circle first, it kinda defeats the whole point of what I'm trying to achieve. - THANKS!
1529073308

Edited 1529076056
The Aaron
Pro
API Scripter
I believe this should do all that you want.  You need to change that 1 to whatever bar you use for HP. on('ready', () => {     const HPBarNum = 1;     const bar = `bar${HPBarNum}_value`;     const max = `bar${HPBarNum}_max`;     const constrainHPBarToMax = (obj) => {         const hpMax = parseInt(obj.get(max),10);         if(!isNaN(hpMax) && 'token' === obj.get('subtype') && !obj.get('isdrawing') ){             let hp = parseInt(obj.get(bar),10);             let changes = {};             if(hp > hpMax) {                 hp = hpMax;                 changes[bar] = hp;                 changes.status_dead = false;             } else if(hp <= 0) {                 hp=0;                 changes[bar] = hp;                 changes.status_dead = true;             } else {                 changes.status_dead = false;             }             obj.set(changes);         }     };     on("change:token", constrainHPBarToMax);     if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){         TokenMod.ObserveTokenChange(constrainHPBarToMax);     } });
Please excuse my ignorance. Is this a NEW script, or to replace an existing one? - I've added it in as an additional script and it doesn't appear to be working. In fact. Adjusting the HP down to 0 manually isn't triggering the 'Death X' anymore. 
1529076163
The Aaron
Pro
API Scripter
Whoops had 2 bugs in there, fixed above.  It was looking at less than zero and not specifically at zero.  Also I wasn't setting the dead marker to true in the dead case. This should replace both the other scripts you linked to. It applies the following rules: For tokens adjusted manually, or with TokenMod If the HP is above the max, set it to max and clear the dead flag If the HP is 0 or lower, set it to 0 and set the dead flag otherwise, clear the dead flag.
1529078558

Edited 1529081047
WOOO! - Thanks! AMAZING! Although, Ironically. - If I change... const bar = `bar${HPBarNum}_value`; const max = `bar${HPBarNum}_max`; to const bar = `bar 1 {HPBarNum}_value`; const max = `bar 1 {HPBarNum}_max`; It doesn't work. - So It looks like I'll be leaving the $ symbols in there... Seen your comment below, I won't add another comment - Just THANKS
1529079178

Edited 1529079201
The Aaron
Pro
API Scripter
Don't change those lines.  If you aren't using bar 1 for hit points, change HPBarNum:     const HPBarNum = 2; // now uses bar 2 Those two lines you changed build the property names for the bar and it's max value for later use.  The ${ variable } is the syntax for embedding the value of a variable into a Javascript Template Literal ` `. 
So I am using the Tomb of Annihilation module from Roll20. The Monsters are already pull one on a page. Some of the options for the NPC I would like to change like NPC Name In Rolls from Show to hide, Whisper rolls to GM, Can we use Tokenmod for this or does someone know of a mod that can.
1529613096
The Aaron
Pro
API Scripter
Those would likely be stored in attributes on the character sheet.  Are you using the 5e OGL or the Shaped sheet?  It's easy to fix on the Shaped sheet via the api script.   On the OGL, you should be able to fix it by changing the default on the Game Settings page (where you configure which character sheet you use) and then applying those defaults in game on the settings tab.
1529655847

Edited 1529677800
I always thought that changing the 'default' for characters only impacted on new sheets, not ones that were already made. - That said, I'd definitely believe Aaron over me!  EDIT: Seen below... OOH - Very fancy. Cheers
1529665586
GiGs
Pro
Sheet Author
API Scripter
Aaron isn't taking about token settings there, but character sheet defaults. 
1529676719
The Aaron
Pro
API Scripter
godthedj said: I always thought that changing the 'default' for characters only impacted on new sheets, not ones that were already made. - That said, I'd definitely believe Aaron over me!  There's a button under Experimental Features: If you make changes to the character sheet defaults on the Game Settings page, then load (or refresh) your table top, you have the option to apply those changes to existing characters:
Hi TheAaron! You've been so helpful in the past with various issues I've been having as I'm learning Roll20, I'd figured I'd ask this question here. I'm looking for the appropriate settings to change the tint of a token to red when raging, then back to transparent when rage ends.   I want this to not be something I control ( @{target|token_id} ), but something the player can control from their character sheet when they hit their Rage feature, and within the description, a button to end their rage (changing their tint to transparent again). Also (see pic), I want this to be able to tick/ untick a modifier to the shaped sheet called Rage that puts the extra damage in place and removes it when not raging.
1531275562

Edited 1531275600
1531277593
The Aaron
Pro
API Scripter
I'd suggest something like: !token-mod --set tint_color|!rgb(1.0,0.0,0.0) --ids @{character_id} That will toggle red tinting on and off for all tokens representing that character.  You'd need to be sure the Players Can IDs setting is on for it to work, and probably provide it as a token action to let them toggle it off easily.
1531295387

Edited 1531314623
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Here's what you can do with the ChatSetAttr script in addition to Token-mod. !setattr --sel --repeating_modifier_ -Kxv0jsJJbqVj2TOmOUx _active|1 !token-mod --set tint_color|!rgb(1.0,0.0,0.0) --ids @{character_id} %{ -Kxuzh6nmVSyQctBaYDP |repeating_classfeature_-kxv-h9bt0lj8jr91h6p_action} This will toggle the mod, as well as change the tint. The first and third lines will need to have the bold part changed in order to get the proper repeating modifier ID for your character's Rage modifier. You can find this with Chrome's inspector, and instructions are in the sheet docs . The second line is Aaron's code. The character ability I have taken this from in my own game assigns a status marker, but changing tint to red is pretty cool. The last line is optional, and is only used to decrement the uses of Rage. It is found by clicking on the class features macro button, choosing Rage, and pressing the Up arrow in chat. To turn rage off, change the first line to end with "0" instead of "1". Keep the second line, since it toggles the tint, and omit the third line, since you have already decremented your rages. 
OUTSTANDING WORK TO BOTH OF YOU!!!!  Awesomeness! keithcurtis said: Here's what you can do with the ChatSetAttr script in addition to Token-mod. !setattr --sel --repeating_modifier_ -Kxv0jsJJbqVj2TOmOUx _active|1 !token-mod --set tint_color|!rgb(1.0,0.0,0.0) --ids @{character_id} %{ -Kxuzh6nmVSyQctBaYDP |repeating_classfeature_-kxv-h9bt0lj8jr91h6p_action} This will toggle the mod, as well as change the tint. The first and third lines will need to have the bold part changed in order to get the proper repeating modifier ID for your character's Rage modifier. You can find this with Chrome's inspector, and instructions are in the sheet docs . The second line is Aaron's code. The character ability I have taken this from in my own game assigns a status marker, but changing tint to red is pretty cool. The last line is optional, and is only used to decrement the uses of Rage. It is found by clicking on the class features macro button, choosing Rage, and pressing the Up arrow in chat. To turn rage off, change the first line to end with "0" instead of "1". Keep the second line, since it toggles the tint, and omit the third line, since you have already decremented your rages. 
Ugg ... though I'm sure there is no other way than IDs to do specific actions though, is there?  Something more vanilla?  If I put the macro lines in the rage description box somehow, that would cover the usage ticking and be able to omit the 3rd line.  if the player clicks their rage, it decrements use and fires the code to turn it on.  But that won't tick the modifier to increase damage, so I still need to use an ID for that. Then also, to turn it off, I need a macro with identifiers. What I was kinda looking for is if anyone in my group wants to play a barbarian, "Here's your macros, set one in the rage box, make your own macro for the other."  But this is more my level of work - in finding their ID's for them to be able to do both as their own token macros.   Not vanilla.  Very chocolate.  Thought we had what I was looking for for a moment, and we do, it's just a lot of extra and individualized work.  Maybe I'll get lucky and no one will roll a barbarian .... lmao.
1531364025
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Unfortunately, the only option to make it more vanilla is to ensure that all characters have their Rage mod and Rage class feature in the same order, so that you can refer to them by sequence number instead of discreet ID.
1531365439
The Aaron
Pro
API Scripter
On the bright side, you only need to figure out that identifier once per character. 
1531430544

Edited 1531431190
If they change it (Both Rage Class Feature and Modifier) to the first in line, will that change the way I can do this?  (Looks upward with hope)  I only worry that the sequence number wouldn't update on an order change. If it does do this, what codes do I need to enter in that instance and get the code to fire on the class feature click (I know I need to make a macro to turn off the rage)?  I know there will be times people just want to 'check' their feature, but it still should run irregardless.
1531443586

Edited 1531443717
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It would likely be something like: repeating_modifier_$0_active Or possibly, @{Name of the Character|repeating_modifier_$0_active} I can't remember off the top of my head if ChatSetAttr assumes the selected character if none is given. Attributes start numbering at $0. More info on how to reference them is in the sheet docs, here .
1531671789
The Aaron
Pro
API Scripter
Update v0.8.39  -- Added Min and Max bounds to status marker numbers (Thanks  Morgan ) You can append two additional numbers separated by  : . These numbers will be used as the minimum and maximum value when setting or adjusting the number on a status marker. Specified minimum and maximum values will be kept between 0 and 9. !token-mod --set statusmarkers|blue:+1:2:5 Omitting either of the numbers will cause them to use their default value. Here is an example limiting the max to 5: !token-mod --set statusmarkers|blue:+1::5
1531789911
The Aaron
Pro
API Scripter
Update v0.8.40  -- Added adv_fow_view_distance setting (Thanks  Wolf Thunderspirit ) Numbers or Blank Just like the Numbers fields, except you can set them to blank as well. Available Numbers or Blank Properties: light_radius light_dimradius light_multiplier aura1_radius aura2_radius adv_fow_view_distance Here is setting a standard DnD 5e torch, turning off aura1 and setting aura2 to 30. Note that the  |  is still required for setting a blank value, such as aura1_radius below. !token-mod --set light_radius|40 light_dimradius|20 aura1_radius| aura2_radius|30 Just as above, you can use  = ,  + ,  - ,  * , and  /  when setting these values. Here is setting a standard DnD 5e torch, with advanced fog of war revealed for 30. !token-mod --set light_radius|40 light_dimradius|20 adv_fow_view_distance|30