Advertisement Create a free account

[Script] TokenLock -- Allows GMs to selectively prevent players from moving their Tokens.

1406171611

Edited 1461260107
The Aaron
Forum Champion
API Scripter
Update v0.2.2 &nbsp;-- removed requirement for isGM, moved to Git. Update v0.11 -- Minor update to restrict rotation along with movement. This brought up by William R. in this thread: <a href="https://app.roll20.net/forum/post/1358099/#post-13" rel="nofollow">https://app.roll20.net/forum/post/1358099/#post-13</a>... Ari K. was looking for a way to prevent players from moving their tokens in a theater of the mind game. This is a script for that purpose. TokenLock allows the GM to selectively restrict the moving of player tokens. Since there isn't any way to tell who is moving a token from the on('change:graphic',...) callback, this script assumes that any token with a controlled by (either on the token or the character that token represents) is a player token. TokenLock can be either Locked or Unlocked . When Locked , it will move any moved player token back to the spot where it was before being moved. When Unlocked , player token movement works as normal. Cards can still be moved no matter what lock state TokenLock is in. There are 3 commands: !tl lock -- This locks the tokens. !tl unlock -- This unlocks the tokens. !tl -- This will print out the help and instructions Git:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/To" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/To</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.
1406172289
The Aaron
Forum Champion
API Scripter
It occurred to me that this might be useful for GMs that are afraid their players will log in between sessions and move their tokens around.. probably a small subset of people, but still..
1406186219

Edited 1406186290
Brian
Sheet Author
API Scripter
Worth noting: even if you immediately return a "locked" token to its previous position, the player can get a glimpse beyond a DL wall. Consider a locked state which modifies who can control the token rather than simply altering the token's position. I would recommend having both options available, such as if the GM wants players to have access to token actions but not movement. (Of course, you would have to store the original controller of the token somewhere so that it can be restored when the token is unlocked.) Worth testing: when I made my collision detection script, I discovered problems with this sort of motion detection when the user selected a token and held down an arrow key to move. If you haven't already, test what your script does in that case. There might not be a solution, but if it's a problem, it is best to know about the problem. Potential enhancement: locking specific tokens (such as the one controlled by a rambunctious/impatient player) rather than simply locking all tokens on the table.
1406198667
The Aaron
Forum Champion
API Scripter
Fair points, Brian! I'll certainly test the arrow keys. If I swing back around to work on this again or someone wants the other features, I'll see about adding them. Since the controlled by is just a string, I could probably just change each entry to LOCKED:{player_id}... I'm curious to see what that would do.
This is exactly what I needed! Thanks! Since DnD 5e came out, I've been wanting to do less tactical combat stuff. We played Pathfinder for so long that all the players were just used to counting squares and moving their tokens, and I wanted them to more or less describe their actions try more dramatic resolutions instead of just "I move five squares and swing my sword" type of combat. Locking tokens temporarily, I think, will keep the groups focused everything that is happening in the scene instead of where there character should be moving or what they should be doing. Thanks again!
1406262643
The Aaron
Forum Champion
API Scripter
No worries! =D
This is awesome. I tried out this script really early this morning and it works nicely. I've read a lot about trusting your players and for the most part I would (once I finish designing the game that got me on roll20 in the first place), but this just gives me peace of mind to know I can lock things down if it becomes necessary or makes things easier. Anyway, just wanted to say thanks, Aaron.
1406265559
The Aaron
Forum Champion
API Scripter
Thanks Julian! If you're interested in the deeper lockdown suggestions Brian made, let me know and I'll see about adding them. :)
I would, actually. A movement phase where you can lock or restrict control of a token after it's been moved rather than waiting for everyone to finish would be 'safer' and wouldn't have to be toggled for things like a character getting knocked back/thrown/pulled/etc.
I am extremely new to API stuff. How would i load this into my campaign and use something like what you have provided?
1407181276
The Aaron
Forum Champion
API Scripter
1st: Upgrade to Mentor status 2nd: On your campaign, details page, click API Scripts : 3rd: Paste the contents of the gist into a script, give it a name, and click Save Script . 4th: Enjoy!!
guess what, this is the other script I was talking about. how about an option to allow only the token at the top of the initiative panel to move, while keeping the others locked down? combined with your initiative tracker, this would make combat almost completely automated in my games, and i'm spectacularly lazy that way. (always too busy looking over notes for the next round while they are busy whomping on monsters, Im the one who slows down combat the most if they have to wait for me :P)
1407189432
The Aaron
Forum Champion
API Scripter
That should be pretty easy. I'll see about adding that in the next iteration. In the interim, you can just add this between lines 99 and 100 to get this effect: && ( ('' !== Campaign().get('turnorder')) ? (JSON.parse(Campaign().get('turnorder'))[0].id) : undefined) !== obj.id
1407781003

Edited 1407781092
+2 for Michael, one for his idea (sorta what I was hoping when coming here), and one for admitting to his laziness :P I'll try the extra line and see if it works.
1407782010
The Aaron
Forum Champion
API Scripter
Laziness is one of the 3 virtues of a computer programmer... =D
1407798279
Just a quick question. I'm wondering, if !tl was used by another script the two would conflict. If I were to Control+F and search for every !tl and replace it with like !turnlock, would it work or would it crash somewhere?
1407798998
The Aaron
Forum Champion
API Scripter
It will work just fine. 2 instances, line 53 and line 80. Line 80 is the only functional one, but the help will be wrong if you don't change 53.
1407801891
Thanks buddy! You da best!
1407802326
The Aaron
Forum Champion
API Scripter
;)
1408744351
Thanks for the script. I'm also using the modification @Aaron suggested in responde to @Michael H.'s suggestion
1408745530
The Aaron
Forum Champion
API Scripter
No problem Leo! Let me know if there's anything else you think it should do.
1411758183
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Aaron.... Thinking about the Dynamic Lighting issue.... What if... when a token is "locked" you turn off the token's light.... and drop a non-player controlled "transparent" token under it with light visible to the token's owner (or on the map layer or something.) Point is when you "cheat" move a locked token... it has no light.... and your visibility is limited to your tokens locked location? Make sense? Or even worth it?
1411760917
The Aaron
Forum Champion
API Scripter
Certainly a possibility. Brian suggested taking away the player's control of it, which might work better, as players could just re-enable the light (unless I prevent that too.. can't remember... =D )
1411769093
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Don't think they can change their light.... The trouble with disability access is you take away their token actions they might properly have access to. You blind them... put a light next them they can't touch... maybe they try to move... but they will be blind and snap back to their light. And still having access to to their token actions. Brian could use lights that follow for his wall scripts... players never have a light just a light token that follows them and the light token only follows to legal locations.. Might fix his wall breaks. Don't know.
1411773550
The Aaron
Forum Champion
API Scripter
Good points. We'll have to try that out.
1416421077
The Aaron
Forum Champion
API Scripter
Update v0.11 -- Minor update to restrict rotation along with movement. This brought up by William R. in this thread: <a href="https://app.roll20.net/forum/post/1358099/#post-13" rel="nofollow">https://app.roll20.net/forum/post/1358099/#post-13</a>...
1416421840
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
The Aaron said: Minor update to restrict rotation along with movement. That cracked me up. GM: "Dave, what are you doing." Dave: "Looking around." GM: "You are turned to stone." Dave: "So I can't look around?" GM: "No." Dave: "So how come I can turn my token?"
1416423021
The Aaron
Forum Champion
API Scripter
Hahahaha, yeah.. totally. =D
1417898914
Hi, I'm currently having problems with this script. It could possibly be due to a conflict with other scripts you made and changed in the last month (Ammo, TurnMarker, TokenMod) as I didn't have problems with it until recently (first noticed 2 weeks ago). Basically, if I have 2 tokens with associated initiatives, and its the turn of token A, no one can move token A: it returns to its previous location. The same is true for token B, but that's expected in the turn of token A. If you want to debug, you already have access to my campaign. Thanks! Leo
1417901788

Edited 1417901893
The Aaron
Forum Champion
API Scripter
I'm about to head to the company Christmas party, but if its persisting tomorrow, I'll be sure to jump in. In the interim, did you make this mod to allow the token whose turn it is to move? <a href="https://app.roll20.net/forum/post/1033747/#post-10" rel="nofollow">https://app.roll20.net/forum/post/1033747/#post-10</a>... I don't think that feature is in the main script. If you grabbed version v0.11, you'll need to add that change back in. I'll try to get that added with a config soon.
1417921682
Ahhh, I completely forgot about that modification. I added it back and it works perfectly now =) Thanks and enjoy the party!