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.

1430063801
The Aaron
Pro
API Scripter
Yeah, I'll be curious to see if and how it gets used.
1430073710
Gen Kitty
Forum Champion
Got this error, updated to newest version of script, still getting this error: For reference, the error message generated was: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ TypeError: Cannot call method 'split' of undefined at decomposeStatuses (evalmachine.<anonymous>:1726:34) at applyModListToToken (evalmachine.<anonymous>:1762:12) at evalmachine.<anonymous>:2033:6 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at handleInput (evalmachine.<anonymous>:2032:7) at eval ( Macro being used is: !token-mod --off showname showplayers_names showplayers_bar1 and the error occurs when attempting to modify more than one token at once. If I do one at a time, it works fine.
1430074666
The Aaron
Pro
API Scripter
Hmm.. I can't duplicate the problem, but I can see how it might happen. I put a fix in for it in v0.8.4 which is now in the repo. Can you give that one a try?
1430077184

Edited 1430077273
Gen Kitty
Forum Champion
Will try, amid gaming right now :> Ok, it works, thanks!
1430077840
The Aaron
Pro
API Scripter
Great! =D Thanks!
1430082901
The Aaron
Pro
API Scripter
Update v0.8.5 -- Bugfix for empty list of statuses. !token-mod --set statusmarkers| Caused a crash, now it doesn't. =D
I have seen the light. This script is amazing. Thanks again The Aaron
1430743941
The Aaron
Pro
API Scripter
No problem! :)
1431414339
Ziechael
Forum Champion
Sheet Author
API Scripter
Since you never have enough to do I was wondering if this could be modified to allow it to control rollable table token graphics or is that outside of the realm of API? Case study: 1. Rogue activates stealth mode 2. Macro rolls for move silent/hide check 3. On success token changes 'side' to a transparent token 4. Small aura activated for player only to see Based on the discussion you had yesterday morning in another thread i thought i'd at least raise the question of automation :)
1431430622
The Aaron
Pro
API Scripter
Unfortunately, while the API can change the sides property of a graphic, that doesn't cause the imgsrc to update. :/ That prevents the API from changing a rollable table token.
1431434187
Ziechael
Forum Champion
Sheet Author
API Scripter
That is as I feared... oh well, lets consider that a dream for another day then
I wanted to post this into the Initiative Assistant but realized it might fit better here. HA. Really need to add that. I have a really awesome version 2 of TurnTracker mostly written... time is what I really need more of... Could you maybe slip the functionality into it to simply repeat the given command once for each selected token? This might fit maybe even better into the TokenMod script but I would mainly require it as a GM to roll the initiative for all combat participants. In general this is a feature I really really miss on roll20. And a highlight to the currently processed token would be great. If there is no prompt the highlight would not be visible or just pop up very shortly but that doesn't matter for me. Especially if it would be possible to acces the representing character. Something like the following would be amazing! !token-mod --foreach /em @{selected|token_name} rolls for initiative [[%{@{selected|character_name}|Initiative} &{tracker}]]
@TheOtherKevin - What you are really looking for is GroupInitiative, I would suggest using that. The ability to process a command for each token is likely feasible with the API but would probably be better for a separate script request rather than an integration into an existing script. GroupInitiative * time to look for another forum name, starting to feel a bit overcrowded in the "Kevin" realm.
1431872011

Edited 1431872211
The Aaron
Pro
API Scripter
Kevin said: * time to look for another forum name, starting to feel a bit overcrowded in the "Kevin" realm. (Have you considered "The Kevin" ? =D That's half the reason I added it... ) “Why do you wear a 'the'? Was your name burned by acid or something?" "Oh no. It's just they're terribly comfortable. I think everyone will be wearing them in the future.”
1431872369

Edited 1432394830
The Aaron
Pro
API Scripter
Wandler said: I wanted to post this into the Initiative Assistant but realized it might fit better here. HA. Really need to add that. I have a really awesome version 2 of TurnTracker mostly written... time is what I really need more of... Could you maybe slip the functionality into it to simply repeat the given command once for each selected token? This might fit maybe even better into the TokenMod script but I would mainly require it as a GM to roll the initiative for all combat participants. In general this is a feature I really really miss on roll20. And a highlight to the currently processed token would be great. If there is no prompt the highlight would not be visible or just pop up very shortly but that doesn't matter for me. Especially if it would be possible to acces the representing character. Something like the following would be amazing! !token-mod --foreach /em @{selected|token_name} rolls for initiative [[%{@{selected|character_name}|Initiative} &{tracker}]] GenKitty suggested something similar for skills at one point, and I wrote a small part of it. The Kevin is right though, GroupInitiative is your man for group initiative rolls.
1431872961

Edited 1431873012
Formerly known as "Kevin", The "Kevin" was simply the default name, I have switched it to "Wandler" now to create less confusion. The idea was much more general which i thought might fit well into TokenMod. Using foreach for any command I passed is what I really hoped for as this would allow to call other scripts and macros once per token and if this is possible, GroupInit is possible as well. The GroupInit script itself looks extremly tailored to D&D. I played around with it a lot but was not able to get a different roll per token depending on it's abilities and macros. I was not able to produce anything usable with group-init. Shouldn't it be quite easy to simply use sendChat once for each selected token with the provided text? (I don't program Javascript but just looked through some of the scripts).
1431874203

Edited 1432394787
The Aaron
Pro
API Scripter
I've tried to make GroupInitiative work more generally, so if you have a case it doesn't work for, definitely let me know so I can fix it. =D As for calling macros or issuing chat messages from the point of view of tokens, it's slightly more complicated than it seems. Having every token say "Hello World" is pretty trivial. However, once you start to add attribute and ability references, it becomes much more complicated. Attribute references are expanded in the client before issuing the command to the API server, so assuming you had multiple token selected, the first of which is named Bob, and the rest of that syntax is actually valid (I don't think you can use an attribute reference as the first part of an ability reference), the API would get this as the command: !token-mod --foreach /em Bob rolls for initiative [[14]] For a group of selected tokens, @[selected|token_name} would only get expanded to the first token in the list, on the client side. Additionally, only %{Bob|Initiative} would get executed (assuming that name reference works) and it would add Bob to the Turn Order before sending the command to the API server. &{tracker} doesn't actually work from the API because it relies on having a token selected by the current player in the virtual table top, and the API is not a player. To get this to work wold require entering things in a slightly peculiar syntax. I handled this in my PCPP script like this: !token-mod --foreach /em @#{selected|token_name} rolls for initiative [#[%#{@#{selected|character_name}|Initiative} &#{tracker}]#] Something like this might be possible for this issue as well, I'll think about it after CharMod is done. =D
Such a great tool! Thank you for it!
1432394900
The Aaron
Pro
API Scripter
TokenMod is definitely my most popular script, so far as I can tell. =D It's certainly the one I use most! And you're welcome!
TokenMod and PowerCards are the two that I rely on the most. :)
1432687028
The Aaron
Pro
API Scripter
Me too! =D
I don't suppose there would be a way to add a number to the token name automatically. ie I select 5 tokens and it appends a number 1-5 at the end of the token name? I know there is a seperate script for this, but not sure if it could be done in this script.
Hi Aaron, Thank you for making this very helpful script. I have a question about it. I tried to use it from inside on of my own script and it doesn't work: newmsg.content = "!token-mod --set statusmarkers|!snail"; TokenMod.handleInput(newmsg); i have this error message in the output: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ TypeError: Object #<Object> has no method 'handleInput' at Attack (evalmachine.<anonymous>:4555:15) at Object.AttackScript.Process (evalmachine.<anonymous>:4307:5) at evalmachine.<anonymous>:4242:22 at eval ( I use other scripts in the manner and it works without problem. What am i doing wrong ?
1432741825

Edited 1432741852
The Aaron
Pro
API Scripter
Kunguru said: I don't suppose there would be a way to add a number to the token name automatically. ie I select 5 tokens and it appends a number 1-5 at the end of the token name? I know there is a seperate script for this, but not sure if it could be done in this script. try: !token-mod --set name|"@{selected|token_name} ?{Number?|1}"
1432741963
The Aaron
Pro
API Scripter
Laurent said: Hi Aaron, Thank you for making this very helpful script. I have a question about it. I tried to use it from inside on of my own script and it doesn't work: newmsg.content = "!token-mod --set statusmarkers|!snail"; TokenMod.handleInput(newmsg); i have this error message in the output: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ TypeError: Object #<Object> has no method 'handleInput' at Attack (evalmachine.<anonymous>:4555:15) at Object.AttackScript.Process (evalmachine.<anonymous>:4307:5) at evalmachine.<anonymous>:4242:22 at eval ( I use other scripts in the manner and it works without problem. What am i doing wrong ? That should work, provided you're waiting for on('ready', ) before calling it. (Otherwise, it would be luck of the draw regarding initialization order.)
Hi, All scripts are already launched and working when i try to use this one. (i've tested the token-mod with a macro and it works fine just before having this error) The error part about "Object #<Object> has no method 'handleInput'" make me think that the api cannot understand the "TokenMod." part. Any other idea why it shouldn't work ?
1432757547
The Aaron
Pro
API Scripter
Oh, sorry, I got confused for a second. I know precisely why it doesn't work. TokenMod only exposes two functions: CheckInstall and RegisterEventHandlers. TokenMod is an Object returned by the anonymous function that starts on line 5. All the contents of that function are accessible to the Object (by closure), but not exposed to the outside world. You can add HandleInput to the exported functions (and thereby void the warranty! =D) by adding: HandleInput: handleInput, on line 1097, right after return {
Thank you again !
1432758828
The Aaron
Pro
API Scripter
Yup! I'll be curious to hear about how it works out. I'm interested in cross script dependencies (have a few script ideas for that.. (just have to say that in case Ziechael is about.. =D ( but I really do... =D ) ) ) .
Is there a more elegant way of unseting a certain status wherever it is set beyond iterating over all tokens? e.g. !power --name|Hunter's Quarry ... !token-mod --set statusmarkers|-archery-target --all-ids !token-mod --set statusmarkers|archery-target --ids @{target|token_id} I have come up with this, adding to HandleInput at line 1056 case 'all-ids': ids=_.union(_.map(findObjs({_subtype: 'token'}), function(o){return o.id}), ids); break; which seems rather brute force
1432774546
The Aaron
Pro
API Scripter
That would be across all pages. If you just want to do the current page, you could select everything. TokenMod operates on all selected tokens by default (which might cause a certain bug, but I digress). Technically, you probably don't need the union as any token Id specified would be a duplicate. Also, I'm pretty sure you could use _.pluck(findObjs(...), 'id') instead of _.map().
I don't suppose there is a way to add attributes to a character sheet with this too?
1432821938

Edited 1432821958
The Aaron
Pro
API Scripter
No, but I'm working on a script for that, a CharMod script. There are a few other scripts floating about, but nothing comprehensive, so far as I know.
I can't wait for CharMod... so many glorious uses. I currently use one of the other scripts, but it's somewhat limited and doesn't have enough error checking so very easy to crash the script.
1432827883
The Aaron
Pro
API Scripter
Yeah, me either! I've been slightly side tracked by a character export/import edit script for Her Majesty, the Wondrous GenKitty, then it's back into CharMod, which is waiting on writing an inline dice parser (which I've been meaning to do for a long time).
1432846266
Gen Kitty
Forum Champion
The Queen of Kitannia is well pleased by the efforts of her Court Scriptomancers, and they will be remembered come the Yuletide season.
I managed to call this script in one of my own and it works perfectly. I followed your instruction to add HandleInput to the exported functions and i also had to add the line : msg.selected = [{"_id":desttoken.id,"_type":"graphic"}]; to call TokenMod.HandleInput correctly. Thank you very much again for your help.
1433866288
The Aaron
Pro
API Scripter
No problem! =D
I want to use this script to adjust the light radius of a given token, but I don't know the syntax. My usage case is: I've got a character with infravision 60', so I have him emitting light that only he can see with a radius of 60' and a dim radius of 30'. But torches spoil infravision. Other characters which are carrying torches I have using the Torch script (usually with flicker), and when the infravision character is within the range of the torchlight, I'd like for his infravision to be cancelled out. Then, when he moves out of the torchlight, I use a targeted macro to give him his infravision back. What would be the syntax for this? BONUS: Is there a way that this could be handled automatically, so that as a token moves into the radius of the torchlight flicker, it stops emitting light until it moves out of the flicker? EDIT: Nevermind, I just realized, I can use Torch for this functionality. D'oh! However, the automated part would be nice, if anyone has any bright ideas on that (excuse the pun). :)
1434036608
The Aaron
Pro
API Scripter
I love puns! =D The automated idea could be handled via another script (which would need writing). The simplistic implementation could do: 1) on token move 2) find all tokens emitting light on the page 3) if in the radius of their light, turn off (store) the light settings on the current token 4) otherwise, turn them back on (from the store) if they were off. Simplistically, step 3 would just check the radius. The real solution would involve checking for dynamic lighting lines blocking that light to determine the actual collision condition. That would require some complex math which is not impossible, but puts it in the realm of "more than a hacked together script". You could reach a halfway point by having step 3 prompt the GM with a button to turn off/on if it thinks the token is in the condition.
1434040669

Edited 1434043803
Hey Aaron, One of the big things that I'm making use of your TokenMod script for is handling lighting in my game. I have two macros setup; one to set the light settings for a token, and another to return the settings to the default. My default lighting settings on a token are 10/-10 (it provides just enough light to let my players stumble around in the dark). However, using the script to set " light_radius|-10 " just increments the value by -10, and doesn't actually set the value to -10. I get why that's happening, of course. I'm just curious to know if there's any workaround I could use for this? EDIT: Nevermind, I found an easy workaround. I just first set the radius to 0, and then set it to -10. I really should have tried that before posting >.<
1434047032
The Aaron
Pro
API Scripter
Ah, that's an interesting point. I'll ponder a cleaner way to handle that. The script uses the leading +/- to determine if the number is an adjustment, or a literal value. Probably I'll add some syntax to specify that it is a literal value despite appearing to be an adjustment. Glad you found a work around!
1435500745

Edited 1435500799
The Aaron
Pro
API Scripter
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!)
By the way it breaks if you select non-tokens (like a drawing). Is there anyway to make a character sheet have multiple tokens (so instead of just one skeleton token, you might have a variety) or do you have to make a character sheet for each token? I'm using "!token-mod --set bar1_link|speed bar2_link|ac bar3_link|HP" for now to link them all to the same character sheet (but you lose out on rolling HP), and the AC link isn't working. I can manually select AC, but it doesn't work if I use it like above. Also is there a way to link it then unlink it without doing two separate commands?
1435504188
Gen Kitty
Forum Champion
It sort of makes sense that it breaks if you try to adjust non-tokens, it's called 'TokenMod' after all ;) You can have one sheet have multiple different-looking default tokens , if you use rollable tables . You can have an infinite number of non-default tokens ' representing ' a character
1435504427

Edited 1435505068
Perfect scripts never crash ^^, but sure I see your point. I just selected the entire map and that included some random drawings, just letting him know. Never used rollable tables, will have to look into it thanks. Edit: This doesn't seem to function, every time I push the token button it uses the same image, regardless the image never remembers the settings I've used before (ie turned one of the images into linking with a bugbear). It also doesn't roll random HP. Unless I'm completely misunderstanding this is not useful for this purpose.
1435504558
Gen Kitty
Forum Champion
No worries, just me teasing you. ^_^
1435504732
The Aaron
Pro
API Scripter
Update v0.8.7 -- Fixed crash when attempting to affect graphic tokens with bar*_reset operations. (Thanks RMcD!) No such thing as a perfect script, but I try to get as close as I can. =D
Any videos of this scrpit in action?
1435506551
The Aaron
Pro
API Scripter
It mostly adjusts stats that are imperceptible, the easiest way to see what it does is probably to just install it and try some of the examples in the help screen ( !token-mod --help ) Effectively, anything you can change on the token settings can be set with the script, and set across all the selected (or indicated with --ids) tokens all at one time. Here's a video of the most resent feature in action: