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

Simulate lightning

Looking for help simulating lightning with UDL or any other method. Not the most knowledgeable so if someone could break it down for me that would be great. 
1643291866

Edited 1643293091
David M.
Pro
API Scripter
I wrote a lightning script a while ago that flashed at random intervals, though it was written for LDL. It could be modified for UDL by changing the name of the token properties in the flashOn function (those properties can be found here  -  emits_bright_light,  bright_light_distance,  emits_low_light,  low_light_distance ). Note that there was a bug in UDL that prevented immediate application of light changes that I think  was resolved, though I can't remember at the moment, so YMMV.  EDIT - I can't compile & test right now, but if you have any issues I can try to get to it later.
sorry to ask , when you say changing the name of the token properties in the flashOn function which do you mean , sorry to ask but if you could explain i would appreciate it very much
1643293561

Edited 1643293622
David M.
Pro
API Scripter
Looks like my edit and your response cross-posted! There are actually two functions to edit. Here's the LDL versions (found in the code posted in the link above): const flashOff = function(src) { src.set('light_radius', 0); } const flashOn = function(src, dim, timeout) { let rand = Math.random() * timeout; if (dim) { src.set('light_dimradius', -15); src.set('light_radius', 200); } else { src.set('light_radius', 200); } setTimeout(flashOff, rand, src); } Try replacing them with this (untested) const flashOff = function(src) { 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_low_light', true); src.set('low_light_distance', 400); } else { src.set('emits_bright_light', true); src.set('bright_light_distance', 200); } setTimeout(flashOff, rand, src); } If this doesn't work, let me know and I can check it out after work tonight.
No luck , at least not on my part but I am still new to all this stuff . I set up the scene like the example you gave used !Lightning on but no effect.
1643295347

Edited 1643564454
The Aaron
Roll20 Production Team
API Scripter
Here's a little API called Flash that simulates a lightning strike by turning on daylight mode for 300ms Trigger it with: !flash Code (Fixed): on('ready',()=>{ const FLASH_TIME = 300; // milliseconds const getPageForPlayer = (playerid) => { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; const flash = (page) => { if(page.get('dynamic_lighting_enabled') && !page.get('daylight_mode_enabled')){ page.set({daylight_mode_enabled: true}); setTimeout(()=>page.set({daylight_mode_enabled: false}), FLASH_TIME); } } on('chat:message',(msg)=>{ if('api' === msg.type && /^!flash(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let page = getObj('page', getPageForPlayer(msg.playerid)); if(page){ flash(page); let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); sendChat('',`/w "${who}" ⚡ FLASH ⚡`); } } }); });
thank you for your help both of you, I just cant get them to work , i think im going to have to do some more reading up on this stuff im just not understanding what im doing wrong
1643297485
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Just in case it is a basic installation problem, here is a very quick and useful introduction to APIs: How to Install Roll20 API Scripts
thank you, yes unfortunately I have installed the scripts they just don't seem to activate or turn on when I'm in game. Unfortunately it seems i will have to do without for next session and keep reading up on how API's work
1643298851
Kraynic
Pro
Sheet Author
kyle said: thank you, yes unfortunately I have installed the scripts they just don't seem to activate or turn on when I'm in game. Unfortunately it seems i will have to do without for next session and keep reading up on how API's work Just to be sure...  While you are logged into the game, have you opened the api settings page up in another browser tab and hit the button to restart the api sandbox?  Then you can see if there are any errors when it restarts.
No errors :( sorry guys i know it will be something ridiculous and small that I'm doing or not doing but unfortunately I just don't know enough to realise what it is yet. 
How are you testing the actual viewing of the lightning?  I strongly recommend using a Dummy Player Account , as what you see as GM will be impacted by your GM-level viewing settings (such as the opacity of the GM layer) as well bugs that still exist with UDL. It's possible that the lightning is showing correctly for your players, but you're not seeing it as GM.
@Aaron I try your script but it did not work. I check the sandbox no error, I select the map with the ribbon. I activate by with !flash on chat but nothing happen. UDL was on, and the token had vision. 
1643307475

Edited 1643307510
The Aaron
Roll20 Production Team
API Scripter
Do you get the message "⚡️FLASH⚡️" in the chat?
No, I try everything that I could think. once I enter !flash on chat nothing happen.
same here tried all i could think of. 
kyle said: same here tried all i could think of.  same
1643564434
The Aaron
Roll20 Production Team
API Scripter
Ok, I got on and tested this.  Turns out I'd completely borked that script at some point, here's a new version that I just tested which works for me: !flash Script: on('ready',()=>{ const FLASH_TIME = 300; // milliseconds const getPageForPlayer = (playerid) => { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; const flash = (page) => { if(page.get('dynamic_lighting_enabled') && !page.get('daylight_mode_enabled')){ page.set({daylight_mode_enabled: true}); setTimeout(()=>page.set({daylight_mode_enabled: false}), FLASH_TIME); } } on('chat:message',(msg)=>{ if('api' === msg.type && /^!flash(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let page = getObj('page', getPageForPlayer(msg.playerid)); if(page){ flash(page); let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); sendChat('',`/w "${who}" ⚡ FLASH ⚡`); } } }); });
@The Aaron, Thank you it works great :) 
1643603149
The Aaron
Roll20 Production Team
API Scripter
I wrote another version that uses the UDL daylightModeOpacity to fade back to darkness (or the current opacity setting) that looks awesome, but unfortunately seems to be broken in the API for client updates. =(  Hopefully that will get fixed and I can release it.
hopefully, from what ive found it seems there are a few ways to do what im after in the older version i hope they update the UDL soon. 
Are there certain settings I need to have to have this work?
1643648393
The Aaron
Roll20 Production Team
API Scripter
It works on a page set up for UDL lighting.  You need to not have Global Illumination on for it to activate.
Well I am doing something wrong lol. The Aaron said: It works on a page set up for UDL lighting.  You need to not have Global Illumination on for it to activate.