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

Trying to get this script to work

Lightning / thunder effect Original Source:&nbsp; <a href="https://app.roll20.net/forum/post/9061191/lightningfx-script/?pageforid=9061191#post-9061191" rel="nofollow">https://app.roll20.net/forum/post/9061191/lightningfx-script/?pageforid=9061191#post-9061191</a> Updated by someone else for UDL:&nbsp; <a href="https://app.roll20.net/forum/post/9518550/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/9518550/slug%7D</a> So the code i ended up having looks like this const LightningFX = (() =&gt; { const scriptName = "LightningFX"; const version = '0.1'; var globalKill = true; const LIGHT_NAME = 'Lightning'; const checkInstall = function() { log(scriptName + ' v' + version + ' initialized.'); }; const flashOff = function(src) { src.set('bright_light_distance', 0); src.set('low_light_distance', 0); src.set('emits_bright_light', false); src.set('emits_low_light', false); } const flashOn = function(src, dim, timeout) { let rand = Math.random() * timeout; if (dim) { src.set('emits_bright_light', false); src.set('emits_low_light', true); src.set('low_light_distance', 500); src.set('bright_light_distance', 0); } else { src.set('emits_bright_light', true); src.set('emits_low_light', false); src.set('bright_light_distance', 500); } setTimeout(flashOff, rand, src); } const handleFX = function(sources, minInterval, maxInterval, maxDuration, active) { let dim = false; if (active) { let rand = Math.floor(Math.random() * (maxInterval - minInterval + 1) + minInterval); if ( randomInteger(2) === 2 ) { dim = true; } else { dim = false; } setTimeout(function() { sources.forEach((src) =&gt; { flashOn(src, dim, maxDuration); }); if (!globalKill) { handleFX(sources, minInterval, maxInterval, maxDuration, true); } }, rand); } else { sources.forEach((src) =&gt; { flashOff(src); }); } } const handleInput = function(msg) { //set defaults let minInterval = 200; let maxInterval = 10000; let maxDuration = 400; try { if(msg.type=="api" &amp;&amp; msg.content.indexOf("!lightning") === 0 &amp;&amp; playerIsGM(msg.playerid)) { who = getObj('player',msg.playerid).get('_displayname'); let cmd = msg.content.split((/\s+/)); cmd.shift(); switch (cmd.length) { case 0: //no commands, do nothing sendChat('Lightning',`/w "${who}" `+ 'No commands given to !Lightning script'); break; case 1: //on or off break; case 2: //minInterval minInterval = parseInt(cmd[1]) break; case 3: //minInterval maxInterval minInterval = parseInt(cmd[1]) maxInterval = parseInt(cmd[2]) break; case 4: default: //minInterval maxInterval maxDuration minInterval = parseInt(cmd[1]) maxInterval = parseInt(cmd[2]) maxDuration = parseInt(cmd[3]) break; } if ( isNaN(minInterval) || isNaN(maxInterval) || isNaN(maxDuration) ) { sendChat('Lightning',`/w "${who}" `+ 'Error. Non-Numeric timer settings detected'); return; } var sources = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", name: LIGHT_NAME }); if (!sources) { sendChat('Lightning',`/w "${who}" `+ 'No Lightning Sources on Player Page!'); globalKill = true; return; } switch (cmd[0].toLowerCase()) { case "on": //TURN ON FX globalKill = false; handleFX(sources, minInterval, maxInterval, maxDuration, true); break; case "off": //TURN OFF FX globalKill = true; handleFX(sources, minInterval, maxInterval, maxDuration, false); break; default: sendChat('Lightning',`/w "${who}" `+ 'Unrecognized command. Expected Lighting \"on\" or \"off\"'); return; } } } catch(err) { sendChat('Lightning',`/w "${who}" `+ 'Unhandled exception: ' + err.message); } }; const registerEventHandlers = function() { on('chat:message', handleInput); }; on("ready",() =&gt; { checkInstall(); registerEventHandlers(); }); })(); But after doing !lightning on or !lightning on 400 nothing happens I placed a transparent token, double clicked it - named it "Lightning" and I see nothing happening
Update -&nbsp; I got it "WORKING" - the token can't be attached to a character sheet. So my previous transparent token is used for something else and has its character sheet. So it wouldnt work - I grabbed a random map token and changed the name, that worked. So make sure the transparent token is under Generic/None sheet.&nbsp; BUT I AM STILL HAVING a weird issue: I got the light aspect working - but it is also throwing shadow beams. I expected this: Person Token ---- Tree ---- Lightning Token = The lighting would create a Shadow that hits my player... that is understandable But if it's a person token + nothing in between + lightning token - sometimes I get weird shadows popping at my player token. It almost looks like an inverse effect is happening. The player token is on Darkvision 60ft.
1660642001

Edited 1660642099
Oosh
Sheet Author
API Scripter
A couple of things: 1. There shouldn't really be a reason why it's not working with a linked token, provided the token definitely has the correct name set in the token settings. The only filter there is that the script only looks for light tokens on the page with the player ribbon - if you're messing around as GM, this script won't do anything at all on other pages you look at if you don't also move the player ribbon. You can remove this if you want to - unless you have a crazy number of lightning tokens on loads of maps, the overhead isn't likely to be enormous - on par with changing the HP of tokens on inactive pages when someone is hit, which Roll20 already does. 2. Do you have a screenshot (or even better, a GIF) of the lighting issue? Sounds like an issue firmly in Aaron's wheelhouse, but a visual would definitely be helpful.
1660649744
David M.
Pro
API Scripter
Aside from everything Oosh said: 1. Do you have several lightning tokens on the map? That script flashes the light settings of each lightning token on the map, which will often be offset from each other timing-wise. If there are DL "walls" between any of the lightning tokens and the player token, then you will occasionally see shadows from those flashes. 2. What does it look like when the lightning token(s) are manually "turned on" one-by-one (not through the script)? Could be some weird DL artifacts in your map somewhere. 3. Since you're using UDL, The Aaron wrote a much simpler and less fiddly implementation that merely toggles the global illumination setting of the page.&nbsp; You can find it here . No shadows will appear at all with this script, since light isn't being emitted from tokens but being applied uniformly throughout the map. Note that if some player tokens are inside a completely closed room, the inside of that room will still flash. When I wrote that, I was trying to get a spooky forest vibe for my players ( I wanted shadows dancing around)&nbsp; and wanted to avoid the "indoor lightning" scenario. But tbh the global illumination method is going to be simpler long term, will work for most situations, and still gets the point across.&nbsp;
1660673764

Edited 1660674014
dont know how to make a gif I was gonna test it today on a blank map but it seems Roll20 is doing something, cause I cant even see my DL lines anymore, but if I highlight the area, it shows something is there....Typical Roll20 breaking shit that wasnt broken.... A --- B --- C D --- E --- F G --- H --- I So last night, I had the player token on "B" and the lightning token on "H" with no DL on E. Bunch of Trees with DL circle on C, F, I and a house DL on D I would get shadow artifact - cone shape emitting sometimes from Player Token or a large Cone shape from F going toward D. On rare occasion - I saw the tree shadows go reverse, toward player or lightning token instead of away from lightning token.&nbsp; ---- I did tried Aaron script - it's soooo different from this version, as this gives it more realistic feel, seeing lightning / light sources happening in different directions, as opposed to 1 entire flicker of light illuminating everything
1660679230
David M.
Pro
API Scripter
OK, so there is only one lightning token on the map right now? If so, does the cone-shaped shadow appear when you manually turn on light emission for the lightning token in position H? If not, that makes it seem that there are other lightning tokens to the right and left side of your map.&nbsp; If you are using a transparent image for your lightning tokens, you might not be able to easily find them if there is no gm aura on them.&nbsp; Does the same thing happen on a fresh map where you can be sure there are only lightning tokens where you think they are? Don't forget to move the player page ribbon if you test on another map.&nbsp;
No other lightning token was on the map.&nbsp; I got the UDL working now, so I will test this scenerio in a blank map with 1 squared DL, lightning token and player token.
1660681459

Edited 1660681470
So, I expect to see the shadow going NorthWest when the lightning happens, and I do get that, but than I get an inverse lighting as well, where what should be the shadow, is the only lighted area and everything else goes back.&nbsp; Here is the gif - the first 2 flashes are correct, the 3rd one is weird
1660681859
David M.
Pro
API Scripter
That's funky alright! I'm assuming it looks ok when you manually turn on light emission for the lightning token? This is sounding more and more like a UDL bug to me. Wait, I wonder if it is a ctrl-L rendering issue? Do you have a dummy account you could log into on a different browser or incognito window so you can see what the players would actually see, rather than relying on ctrl-L?
ahhh - perhaps that might be it - since I am using Ctrl-L and have heard of that bug issue!
Yup, had my player come in to test it and he doesnt see what I see
1660685366
David M.
Pro
API Scripter
Whew! Annoying, though :/