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][d20] Dynamic Lowlight Vision Light Source Generation

1400883474

Edited 1407609869
First post in the API forum, since I've only been a mentor for a day. Currently, I think the only way to properly represent lowlight vision is to make one extra light source visible only to players controlling tokens with lowlight vision for every source, group them together, and trust your players to not be dicks. At least, that's what @Gauss was saying a few months ago. So, I automated that janky process, but I think the solution really lies in the expansion of light_hassight from boolean to number (where 0 is false and positive numbers represent practically blind / normal / lowlight / darkvision / Riddick). Setup: Have at least one token with sight representing a character with the attribute 'vision' set to 'lowlight.' Have at least one light source with 'light_otherplayers' set to 'true.' You might have to replace my token imgsrc with your own. Suggestions welcome. New in v0.3.2 (August 9th, 2014) --- - Script now applies globally, on ready. - Cleaned up the population of lowlight and darkvision character arrays. - Added "!dll" chat command to rebuild/refresh lowlights. - Added "!dll-kill" chat command to reset all lowlight sources (and move lowlight to grid unit (2,2) on the GM Layer for manual deletion. New in v0.2.0 (June 22nd, 2014) --- - reworked script to determine if a light source has already been affected by the script (by tinting the parent object a specific shade of yellow) ( Garth R. ) - fixed bug where a token with sight but not representing a character crashed the script ( Entola ) - set up script framework for global application of script ( Aaron ) <a href="https://gist.github.com/shnizmuffin/296caf6549d5fc54bae8" rel="nofollow">https://gist.github.com/shnizmuffin/296caf6549d5fc54bae8</a>
I'm getting the error below when I enable your script. "Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: TypeError: Cannot call method 'replace' of undefined at fixNewObject (evalmachine.&lt;anonymous&gt;:1338:19) at evalmachine.&lt;anonymous&gt;:1309:20 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at Sandbox.&lt;anonymous&gt; (evalmachine.&lt;anonymous&gt;:1293:7) at eval ("
Yeah that "fixNewObject" function was a hack to get around a dev server bug. If you don't have any sources of lowlight (tokens with light that other players can see) already on the map before loading the script, the thing will probably fail. It's kludgy right now, but I'm definitely dedicated to making it work properly.
This will really help me out. thanks! One question... When I update lighting, the api doesn't notice until I "Save script" then it creates a second lightsource for the ones already active. How do I fix that?
1402685346
The Aaron
Roll20 Production Team
API Scripter
I would suggest moving the contents of on('ready', [...] ) to a function, then call that function from on('ready'). Then add an on('chat:message') event that calls that function to reset lights (possibly on !reset-lights). You could also hook into add:graphic, change:graphic, destroy:graphic to make updates when light sources show up and go away.
Aaron C. M. said: I would suggest moving the contents of on('ready', [...] ) to a function, then call that function from on('ready'). Then add an on('chat:message') event that calls that function to reset lights (possibly on !reset-lights). You could also hook into add:graphic, change:graphic, destroy:graphic to make updates when light sources show up and go away. Yeah ready() isn't the best way to fire this. I'm still learning the API. What I really want to do is add an attribute "has_lowlight" to light sources, default it to false, and then flip it to true after building the secondary light sources. Then, only plop lowlight sources on light sources that appear with has_lowlight set to false, listening for tokens added to the stage with light_otherplayers set to true. Which fixes Garth's problem. I'm going to write v0.2.0 this week.
1402891583

Edited 1402891631
Question: To get Riddick vision in your game, do I have to go to a slam, one where the sun doesn't sun? Also, I only have marlboro reds. Will those work instead of 20 menthol cools?
No, Marlboro Reds are incapable of lighting other players.
Entola said: I'm getting the error below when I enable your script. "Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: TypeError: Cannot call method 'replace' of undefined at fixNewObject (evalmachine.&lt;anonymous&gt;:1338:19) at evalmachine.&lt;anonymous&gt;:1309:20 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at Sandbox.&lt;anonymous&gt; (evalmachine.&lt;anonymous&gt;:1293:7) at eval (" I've updated the script to fix this error. Now, tokens with sight yet without characters attached won't crash the script. In my campaign, I created two new character sheets "Generic Lowlight NPC" and "Generic Darkvision NPC" that I attach to NPCs who have better than average sight. Any player controlling those characters will be able to see what they see.
Garth R. said: This will really help me out. thanks! One question... When I update lighting, the api doesn't notice until I "Save script" then it creates a second lightsource for the ones already active. How do I fix that? I've updated the script to fix this error. Now, light sources with lowlight successfully applied are tinted yellow (since I couldn't set a new attribute on the token as a "flag"). The script now checks to see if light sources are tinted that (very specific) shade of yellow before attaching a lowlight source to them.
New in v0.3.2 (August 9th, 2014) --- - Script now applies globally, on ready. - Cleaned up the population of lowlight and darkvision character arrays. - Added "!dll" chat command to rebuild/refresh lowlights. - Added "!dll-kill" chat command to reset all lowlight sources (and move lowlight to grid unit (2,2) on the GM Layer for manual deletion.
I think you need some more robust setup instructions, because just dropping the script in and hitting Save throws the same "TypeError: Blah blah" failure.
1407692362

Edited 1407692390
Did you just drop the script in and hit save, or did you follow the setup instructions? Could you give me the specific error text, so that I can reproduce the problem? You might have to replace my token imgsrc with your own in the script itself to reference a token in your library . I'm not sure of this, because i need to be logged as me to test scripts. Have at least one token with sight representing a character with the attribute 'vision' set to 'lowlight.' Have a character with this: And the token for that character is like this: Have at least one light source with 'light_otherplayers' set to 'true.' And then a light source: The script tints light sources it has applied lowlight to. Also, you'll notice the light radius in the image has doubled because there is a lowlight.
1407706607
The Aaron
Roll20 Production Team
API Scripter
Dom B. said: You might have to replace my token imgsrc with your own in the script itself to reference a token in your library . I'm not sure of this, because i need to be logged as me to test scripts. People should be able to use your tokens just fine, so long as you don't delete them. The orange magic circle from my turn tracker is loaded from my library.
Dom im getting an error as soon as i save the script, TypeError: Cannot call method 'get' of undefined at evalmachine. :1190:37 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at populateLowlightCharacters (evalmachine. :1176:5) at dynamicLowlight (evalmachine. :1092:28) at evalmachine. :1024:3 at eval ( I added the attribute to the lowlight characters and attached them to the token (followed your Picture instruction) but im unclear if the lightsource adds itself? (the img you mentioned) im a dummy when it comes to this stuff, just blindly hacking my way thru it.
The script scans for tokens that emit light, so you need a token that emits light in order for this to have any effect. However, the error you're getting leads me to believe you don't have any characters with sight. Cannot call method 'get' of undefined [...] at populateLowlightCharacters is because i'm running an each loop assuming you have defined sightedTokens with at least one object. I'll take another pass at the script when I get some free time this weekend, but for now i'd comment out line 10: // dynamicLowlight(); and call the script manually with !dll when your campaign is set up.
i'll give it a shot Dom, i have my players "has sight" all check (we're running an adventure set in caverns so im making use of the dynamic lighting) and i have many light sources, I even tried tinting them with you color code. Ill go double check everything tho, thanks for looking, i hope it works you had a great idea making low-light vision possible, its something i mentioned should be in the game.
1411058462

Edited 1411058476
Actually, specifically DON'T tint those lights with my color code, I'm using it as a flag (eg. if it has this color, then it already had lowlight applied, so IGNORE it).
1411087133

Edited 1411087192
Well ive done everything you said, ive even started from scratch, let me tell you what ive done... maybe im not setting this up correctly, i'd hate for you to go thru the code if it's just me missing a step... I Copy/Paste your code into the API settings page. Then i comment out line 10 using // dynamicLowlight(); then save script I went to the sandbox, Added the attribute vision lowlight (in the 1st field) to my half-elf wizard with lowlight vision. and checked "has sight" Added a light source token with 10/5 light and set it to "all players see" enter your !dll (that is a DLL right?) command. Nothing changes, then when i check the API settings page i get the above error :( I hope I can get this working, like you i thought it would be great for those with low-light to actually have the advantage of it in the Roll20 app :) Thank for the assistance Dom
Are you on the dev server? Try having ownership of the character? I'm not sure what's going on - it sounds like you're doing everything right. Here's how I have my page set up, but it really shouldn't matter:
OMG.. i wasn't on the Dev Server.... /facepalm that did it.. your code's fine... im a noob =p Thanks for the help Dom :)
OK scratch that, once I transferred my campaign over it broke again, in not sure what's wrong, but I had it working on the Dev server on a blank campaign. Is OK I'll just finish the session were running then I'll see if I can't get it sorted then.
1414323933

Edited 1414324025
I had the same problem. I had to make sure that for every token with sight that represented a character, the connected character also had an attribute "vision". Just leave the fields empty for normal vision. I'm not on the Dev server. I also added the line: 'showname': false, to the createObj attributes in the function dynamicLowLight() because the lowlight sources showed annoying names if the nameplates of the original light sources were shown.
So Tobias are you saying you got it working?
1414454559

Edited 1414491499
yes, I've got it working. I added some minor tweaks in the script, but it's working correctly. For tokens with sight mapped to characters, teh chars have to have the vision attribute, I added the darkvision to the max field, but it's not in use yet, because I have some characters with both lowlight and darkvision. I thought about implementing a similar approach to creating an object emitting light only visible to the character, but right now I implement darkvision simply as giving the character 60/60' light not seen by all characters. tokens with sight not mapped to characters also don't hinder the script. I moved the created Objects to the "map"-layer, because they were annoying me in the objects layer, removed their nameplate, and added maybe some null-checks. It's not yet where I want this to be, the object removal is a bit clunky. If you miss deletion of some source in some page, they stay there. So just tiny changes, but here it is for reference: dynamicLowlight.js with own changes All the thanks go to Dom B. Edit: I added a couple changes: merging the two graphic change functions into a single one for faster location updating, and on dll-kill turning the moved lowlights off (radius=''). I would have loved to move all killed lowlights to the active page, but that's not possible.. The changes don't update here, so go directly to the gist page via the link to get the current version.
1415736693

Edited 1415736737
Good news, everyone! I mentioned the "real" solution to Low Light Vision when I wrote this hack: ...I think the solution really lies in the expansion of light_hassight from boolean to number (where 0 is false and positive numbers represent practically blind / normal / lowlight / darkvision / Riddick). And, according to the newsletter, that's happened! See here: You can now restrict movement of tokens so that they can't cross over walls on the Dynamic Lighting layer. You can also add Global Illumination and adjust the multipliers of light on tokens to better work with Low Light Vision rules in systems such as Pathfinder. So yeah, I think we can safely abandon this Gist. Thanks to everyone who contributed! Dom