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] checkLightLevel - check the current level of light on a token

1664771896

Edited 1665492407
Oosh
Sheet Author
checkLightLevel v0.4.2 GitHub repo This script requires Path Math (available from the one-click library) Description: A simple script to check the current light level of the selected token ( originally from Craig M's thread ). The script will process all relevant light emitters on the map, determine their light level if in range, and whether or not the light is blocked. Usage: Select a token and type: !checkLight Example output: Limitations: The blocking check for walls is currently a simple center-to-center check. If the center of a token has unblocked LOS to the center of a light-emitting token, it is considered to be lit by that emitter. The light radius check is also center-to-center. The bigger a token is, the more of it could be visible inside a dim light source even though it's considered to be out of that light source's range, due to its center being outside the light's radius. This is difficult to address, as (at least in 5e) a token doesn't actually fill the grid squares the token is in, it only controls that space. Any kind of calculation on a token with an edge lit would need to make a heap of assumptions, and probably isn't worth doing. For those reasons I'd recommend keeping a light source as a full grid size where possible, as the calculations will be more accurate External Usage: The total illumination on a target can be called from Plugger , part of the Meta Toolbox. Details in the v0.4.1 post. checkLightLevel can also be called from other scripts: checkLightLevel.isLitBy(tokenOrTokenId) Example return: { bright: false, dim: [<token>, <token>], daylight: 0.3, total: 0.75 } This would indicate a token lit by 2 dim sources, with a map daylight setting of 30%, with a total illumination of 75%. Changes: v0.3.0: Added support for one way walls Added public method to call the script from other scripts v0.4.1: dim light falloff calculations additive light sources minor metamancy tokens on gmLayer no longer included in light calcs see post for details
1664772815
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Very cool script. I especially like that it can be called from other scripts. Would there be any value to reporting back whether the token itself has sight?
1664773404

Edited 1664773462
Oosh
Sheet Author
"I can't see you, you can't see me"? :D It's simple enough to add in, though I'm not sure whether a token having sight has any effect on how illuminated it is.... do you have a use case in mind? Or do you mean whether the light emitter has sight? That would be trickier - the script uses an efficiency method of breaking the check as soon as it finds a bright emitter which is illuminating the selected token. So it would only report on the first token it finds... the simple center-to-center check is probably insufficient for a proper LOS check. I could probably change that if you think a full report on "who can see me?" would be useful? Do people generally have sight switched on for npcs and mooks? It seems like it might be too unreliable to be useful, but /shrug I'm not the DM, I'm just the guy with the crayon.
1664808125
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I was just thinking of it more as a diagnostic tool ("Why is the map black for this player?"). It could provide a one-stop command to say, "yeah, there's light here and you should be able to see it.", or help users find the source of a problem.
1664851280
I like this script, it will be helpful with the radar script determining line of sight with normal vision vs darkvision.  Now if we could get a script to determine cover and combine the three. lol
1664866375

Edited 1664866451
Oosh
Sheet Author
Update v0.4.1 Features: Dim light falloff: the script now calculates the amount of light hitting a token in dim light, as 'dim light' is not necessarily helpful. It covers everything from 0.01% illumination up to 99.99%. Light is calculated as a cubic falloff which seems to align fairly well with my testing - around 7 torches just hitting a target will fully illuminate it. Additive light: the script will now add together all sources of dim light it finds (with the new falloff calculation), plus the global daylight setting. So for example, the final grid square of a dim circle provides around 10-15% illumination. Two of these, plus a 50% daylight setting would give you around 80% total illumination. Meta Toolbox plugin - must have Plugger installed (one-click) - this is currently very basic, but you can grab the total light level from inside a Meta macro. Usage is {& eval}checklight(){& /eval} and returns a floating number from 0 to 1 representing the illumination multiplier (1 is 100%, 0 is darkness). Simple example which reports light over 90% as 'bright', over 5% as 'dim', anything less as 'darkness': !@{selected|character_name} is in {& define ([totalLight]{& eval}checklight(){& /eval}) }{& if (totalLight > 0.9)}bright light{& elseif (totalLight > 0.05) }dim light{& else}darkness{& end}.{& simple} Changes: Standard chat output has changed to accommodate the additive light changes - it will now report the total light level as a percentage. This adds the map's daylight illumination to any token light sources it finds. Bugfixes: Tokens on the GM layer will no longer have their light calculated
1664867608

Edited 1664869132
Oosh
Sheet Author
Kilter said: I like this script, it will be helpful with the radar script determining line of sight with normal vision vs darkvision.  Now if we could get a script to determine cover and combine the three. lol It's probably worth noting that Radar uses a different LOS method, I think David uses all 4 corners as well as the center of the token. So the results may not match the light level results... I haven't tested the two together though (or used Radar at all!). Cover is all kinds of difficult, and would need to be system-specific. And probably only for a full-on tactical combat game, where cover is precise and encoded into tokens on the map from the get-go. I'm really not sure how you'd even approach it for a game where other tokens and art on the map can situationally provide partial cover. The number of assumptions needing to be made would likely make the script fairly useless.
1665024803
Would it be possible to add a group check type feature? selecting a group of tokens to check.
1665048320
Oosh
Sheet Author
It would indeed, I'll add it in when I get some time.
1665492476
Oosh
Sheet Author
Kilter said: Would it be possible to add a group check type feature? selecting a group of tokens to check. I've updated the script to process all tokens selected. This doesn't apply to the Meta plugin - that will still only return the text result for the first token selected.