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] MovementRange – Visualize Remaining Movement Per Turn

1748089236

Edited 1748089653
Hi everyone!&nbsp; It's my first contribution to the Roll20 community and also my first API script!&nbsp; Since I couldn't find any script that did what I wanted, I decided to create one myself. I've created a script called MovementRange that tracks and highlights the remaining movement a token can make during its turn. It supports multiple movement rules (like D&amp;D 5e or Pathfinder), and can be customized for feet or meters. It’s been super helpful for our group to quickly see what squares are still reachable! Features : Automatically displays reachable tiles at the start of a token’s turn. Highlights squares based on remaining movement. Supports diagonal movement rules ("dnd", "pathfinder", "manhattan"). Allows quick reset to the original position for the turn. Compatible with square grids (70px tiles). Sends a customizable macro each turn. How it works : When the active token’s turn begins, it calculates how many squares it can still move, and visually displays all reachable tiles. If the token is moved, the range updates dynamically. Once movement is exhausted, the highlights disappear and the player is notified. Commands : !mr show : Toggle automatic display on/off. !mr reset-turn : Return token to its starting position for this turn. !mr clear : Manually remove highlights from the map. Note : This script assumes 70px grid tiles and uses a transparent PNG image to highlight the movement range. You can change the image URL to fit your style. Script Gist : <a href="https://gist.github.com/Filrahen/bcdcb3dfde6454785dcb915a805ac478" rel="nofollow">https://gist.github.com/Filrahen/bcdcb3dfde6454785dcb915a805ac478</a> Initially, I intended for the tiles to be visible only to the active player, but this doesn't seem to be possible. Feel free to try it out, suggest improvements, or fork it for your own use! Let me know if you run into issues.
1748120267
The Aaron
Roll20 Production Team
API Scripter
That's a great idea!&nbsp; I've started writing a script for this several times but keep getting bogged down in some details. =D I would suggest you wrap your whole script either in your on('ready',...) event, or use something like the Revealing Module Pattern.&nbsp; All Scripts in the Roll20 Mod API Server get concatenated together and share a single namespace, so you will get conflicts if anyone else has a function named 'handleChatMessage' or 'getDistance' or the like. If you want to make yoru squares only appear to the current player, you can use a trick with a square aura of 0 radius on an transparent graphic.&nbsp; Just set it to be controlled by the current player (or whoever controls the token in question), and set the aura to only be visible to the editor.&nbsp; You can look at Bump for some inspiration there (it does something similar, if not identical... can't remember. =D).
1748171543

Edited 1748173273
Thanks for the feedback! I’ll definitely do that.&nbsp; I actually tried the aura trick already, but I ran into two issues I couldn’t figure out: The player can’t see the aura, even though they’re listed in the Controlled By field. The auras show up as circles, even though I set aura1_square: true (and the token’s Shape field even shows "Square"). I’m pretty sure I did something wrong, but I can’t tell what exactly. EDIT: I found a solution to the first issue by creating the tokens on the objects layer and then moving them to the foreground. However, I still haven’t found a fix for the second one: If I open the token settings and click Save Changes (without modifying anything), the aura correctly appears as a square. But doing this manually is not an option !&nbsp;
1748191269

Edited 1748191293
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
There have been some issues lately with some interface elements not updating properly if set with the API (like grid color). I don't know if this could be related. You could try using the&nbsp; force_lighting_refresh function described in the wiki , but I don't know if that actually does anything anymore.
1748195405

Edited 1748195563
Thanks for the suggestion! I tried using force_lighting_refresh, &nbsp;but unfortunately it didn’t have any visible effect.
1748198326
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yeah, it was kind of a desperation suggestion. I have no idea when that note about being deprecated in the coming months was written, if it was in fact deprecated, and whether it actually does anything. I wrote it into the Dynamic Lighting Tool script as a just-in-case measure. When you move to a new page and back, or refresh the game itself, does that resolve the aura shape display? At the very least, despite not being as aesthetically pleasing as it could be, at least the circular auras are functional.
Unfortunately, no, switching to another page and back doesn't fix the aura shape display, and even a full page refresh doesn’t help either. You're right though, at least they're still functional, even if not ideal visually. But yeah, kind of frustrating!
Is this how it's supposed to work?
Yes, that’s exactly how it’s supposed to work! I’ve just updated the Gist with the changes recommended by Aaron. So if you want a version that’s more robust against potential conflicts and that uses auras (sadly still circular), feel free to update the script.