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

Seeking Script for Changing Token Images with Movement Input

February 05 (5 months ago)

Thanks for taking the time to check this out, I'm a complete novice when it comes to scripting and working with Roll20's api/macros, so I'm well out of my depth here. I've scoured the web for information about what I'm trying to do, hoping for a plug and play, but I may not be using the correct key words to pull up anything helpful or it may be locked behind a pro feature I have not seen.

What I'm trying to do, is make a Multi-Sided Token change its image correlating to a directional input by the player (the token would be connected to a player's character sheet). So what that would look like is similar to a sprite from an rpg having a front, back, left, and right. A sprite that "walks" so to speak, but I'm not interested in any animation at the moment, just "turning" in a direction. Maybe one day if someone has the patience to work on that.

I'd appreciate any help someone has to offer, whether that's taking me to the side to explain something or pointing me in the right direction to look. Thank you again for your time!

 

February 05 (5 months ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Hi Soros!

There have been several scripts that rotate the token or provide a facing indicator based on direction moved, but none that switch token faces, to my knowledge.

February 06 (5 months ago)
timmaugh
Forum Champion
API Scripter

I think it might be pretty trivial to code up a token-move listener script. Run it like OnMyTurn: if a token moves AND represents a character AND that character has an ability named OnMyMove (or something similar), then run that OnMyMove ability.

You might want the script to dump info to an attribute on the sheet. For instance, an attribute called OnMyMoveDirection. It is a number between 0 and 360 degrees that renders the direction of the token's move caught by our listener.

Then you could drop any command in the OnMyMove ability that you might want to fire, and reference the direction attribute as necessary (or new location attributes via Fetch). In this case, you'd drop a TokenMod command that used conditionals from the Metascript Toolbox. So if you only were concerned with images for the 4 cardinal directions, you'd have a case for 0, 90, 180, and 270:

!token-mod {{
  --set
    {&if @{OnMyMoveDirection} > 270}
      currentside|4
    {&elseif @{OnMyMoveDirection} > 180}
      currentside|3
    {&elseif @{OnMyMoveDirection} > 90}
      currentside|2
    {&else}
      currentside|1
    {&end}
}}

So, to sum up, you'd need TokenMod, the Metascript Toolbox, and this yet-to-be-written OnMyMove script. =D