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

[Scriptlet] Light Meter

1721881576

Edited 1722373564
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
This is a little scriptlet I wrote for characters who have special abilities that are determined by how much light they are in. Drow have sunlight sensitivity, which imposes disadvantage on certain rolls while in bright light. Gloom Stalker characters can become invisible invisible to any creature that relies on darkvision to see them while they are in darkness. The Shadow Blade spell grants advantage to  attack a target that is in dim light or darkness. These examples are all from D&D 5e, but this should work for any game. The problem is, it's not always easy to tell if the illumination they have is bright light, dim light, or darkness. This becomes even harder if the character has darkvision, since their personal view will artificially change how they perceive their light. This scriptlet appends a tag to the end of the token's name plate that shows if they are standing in  bright light, dim light, or darkness. It will updated automatically whenever the token moves. To activate it on any token, make sure that dynamic lighting is turned on, and that you are on the page with the player flag. Change the name of the token by adding a space and a double asterisk to the end. "Gloomstalker" becomes "Gloomstalker **". Then, whenever you move the token, the tag will update automatically. To stop the script from acting on that token, just edit the token name to remove the tag at the end. This video will demonstrate. To function, this script requires that you have already installed the  checkLightLevel  script by Oosh  (thanks for doing the heavy lifting, Oosh!) . This script is available in OneClick on your game's mods page.  The code is in a gist, because it uses a few emojis, and the forum does not play nice with those. [ Code Link ] You can edit these lines if you find my choices of cutoff not to your liking. These seemed to match what I was seeing on screen, but YMMV. The values are expressed a integers from 0 to 100:             let dimLight = 50;             let darkness = 20; If no one finds any horrible bug with it, I'll put it up on One Click in a week or two.
Very cool!  The Roll20 Forums don't like a lot of emojis and ate the ones you were using. :)  It looks like they are Full Moon , Last Quarter Moon , and New Moon for anyone that is looking for them before the code is added to the One Click. My only other feedback is it would be great if there was a  toggle  command to adjust selected tokens instead of having to manually open the Token Settings and add or remove the '**'. Something like: !light-meter --on !light-meter --off !light-meter --toggle SelectManager and TokenMod can add the ** to selected characters' tokens pretty easily ( !forselected token-mod --set name|"@{selected|token_name} **") , but there's no easy toggle to remove it or the emojis. 
1722270171

Edited 1722270591
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yeah, the emojis presented some other difficulties, being two byte characters. I'll see about making it a bit more user friendly. I think timmaugh has an "unsanity" script to help with character translation for the site.
Keith, I'm experiencing some odd behavior with this script. When I add the ** to the token name and move the token it creates an empty square rather than one of the light level emoji's. For every further move of the token the square remains but the last letter of the name is deleted until eventually the whole name is gone. My group normally don't show the token names so I tried just entering ** for the token name but nothing happens. However if I enter a blank space before the ** then when moving the token the blank square still appears but the blank space is unaffected by further movement.
FFR said: Keith, I'm experiencing some odd behavior with this script. When I add the ** to the token name and move the token it creates an empty square rather than one of the light level emoji's. For every further move of the token the square remains but the last letter of the name is deleted until eventually the whole name is gone. My group normally don't show the token names so I tried just entering ** for the token name but nothing happens. However if I enter a blank space before the ** then when moving the token the blank square still appears but the blank space is unaffected by further movement. If you copied the code from keithcurtis' post above, you need to replace the emoji characters in four of the lines (because the Roll20 Forums don't like many emoji characters). These four lines:                     newName = obj.name.slice(0, -3) + " ";                     newName = obj.name.slice(0, -3) + " ";                     newName = obj.name.slice(0, -3) + " ";             let illumination = [" **", " ", " ", " "]; Replace them with the emojis here:  Full Moon ,  Last Quarter Moon , and  New Moon .
1722372789
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yup. I won't be able to fix this until after Gen Con, unfortunately. But those emoji characters are 2-byte characters, which means the scrip want to replace what it thinks are three characters at the end. If you switch for a single byte character, it wants to replace two characters with three, and you keep getting those added spaces. Sigh, I really dislike the Roll20 text editor...
1722373485

Edited 1722373600
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Here is a raw gist of the script . Github seems to keep the emojis. I have edited to top post to just show the link instead of the code.
Keith, Works perfectly now. Thanks for resolving
1722714047

Edited 1722714881
Pak
Pro
Jarren said: Very cool!  The Roll20 Forums don't like a lot of emojis and ate the ones you were using. :)  It looks like they are Full Moon , Last Quarter Moon , and New Moon for anyone that is looking for them before the code is added to the One Click. My only other feedback is it would be great if there was a  toggle  command to adjust selected tokens instead of having to manually open the Token Settings and add or remove the '**'. Something like: !light-meter --on !light-meter --off !light-meter --toggle SelectManager and TokenMod can add the ** to selected characters' tokens pretty easily ( !forselected token-mod --set name|"@{selected|token_name} **") , but there's no easy toggle to remove it or the emojis.  I wrote a quick scriptcard to turn the meter on and another one for turning it off. When executed, it asks you to choose a target token. TURN ON: !scriptcard {{   --#title|Light Meter ON   --#emoteState|false   --#whisper|gm   --#targetToken|@{target|token_id}   --&TokenNameOrig|@{target|token_name}   --&TokenTest|[&TokenNameOrig(contains, )][&TokenNameOrig(contains, )][&TokenNameOrig(contains, )]   --?[&TokenTest] -inc 1|>Ignore |>Append --X|      --:Ignore|   --+| Light Meter is [b][#f09][i]already ON[/i][/#][/b] for this token! --X| --:Append|   --&TokenNameAppend|[&TokenNameOrig] **   --!t:[*T:t-id]|name:[&TokenNameAppend]   --+|Light Meter is now [b][#f09][i]ON[/i][/#][/b]! [br]Move the token for the Light Meter to take effect! --X| }} TURN OFF: !scriptcard {{   --#title|Light Meter OFF   --#emoteState|false   --#whisper|gm   --#targetToken|@{target|token_id}   --&TokenNameOrig|@{target|token_name}   --&TokenTest|[&TokenNameOrig(contains, )][&TokenNameOrig(contains, )][&TokenNameOrig(contains, )]   --?[&TokenTest] -inc 1|>Remove |>Ignore --X|      --:Ignore|   --+| Light Meter is [b][#f09][i]already OFF[/i][/#][/b] for this token! --X| --:Remove|   --&TokenNameRemove|[&TokenNameOrig(before, )]   --&TokenNameRemove|[&TokenNameRemove(before, )]   --&TokenNameRemove|[&TokenNameRemove(before, )]   --+|Light Meter is now [b][#f09][i]OFF[/i][/#][/b]!   --!t:[*T:t-id]|name:[&TokenNameRemove] --X| }} NOTE: Due to limitations in the Roll20 text editor, the full moon, last qtr moon, and new moon icons are converted to   . These    icons will need to be changed to the appropriate icons. I'll paste a picture below. WARNING: I'm not a scriptcard guru by any stretch... so there may be a more streamlined way to do this using scriptcards!
Picture of script with icons