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

FLICKERING LIGHTS

November 22 (10 years ago)

Edited November 25 (10 years ago)
Here is a little script I wrote to make flickering torches in D&D 5E
It affects tokens with the name of TORCH, you must set the torches token attributes in the advanced tab to all players see light and the emits light boxes 20,20,360.
To turn the lighting fx on type !LIGHTFX ON.
To turn lighting fx off type !LIGHTFX OFF
It updates every 1/5 of a second. I am not sure if this update rate is too fast. I also thought it would be very easy to adapt the script to make rotating beams of light and to simulate other objects such as candles. One of my players had problems though when I used the script below, it seemed to send his browser into a tail spin. Note the script only animates lights on the page the players are on.

//FLICKER SCRIPT CAUSES OBJECTS WITH A TORCH TOKEN NAME TO FLICKER
//WRITTEN BY JACK TAYLOR NOV 2014 FOR THE ROLL20 SCRIPT ENGINE
var MyTimer;
var light_fx = false;

function flicker()
{
var i,c,r;
var Torches = findObjs({ 
_pageid: Campaign().get("playerpageid"), 
_type: "graphic", _subtype: "token", name:"TORCH" 
});
c = Torches.length;
for(i=0;i<c;i++)
{
r = Math.round((0.9 + 0.1 * Math.random()) * 2000) / 100;
Torches[i].set("light_radius",r);
}
};
on("chat:message", function(msg) {
try
{
if(msg.type == "api")
{
var S = "";
if( msg.content.indexOf("!LIGHTFX ") != -1)
{
S = msg.content.replace("!LIGHTFX ", "");
if(S=="ON" && !light_fx)
{
MyTimer=setInterval(function() {flicker()}, 200); 
light_fx = true;
log("LIGHT FX ON");
}
if(S=="OFF" && light_fx)
{
clearInterval(MyTimer);
light_fx = false;
log("LIGHT FX OFF");
}
}
}
}
catch(err)
{
sendChat("LIGHT FX SCRIPT EXCEPTION",err.message);
}
//}
});
November 22 (10 years ago)
Pat S.
Forum Champion
Sheet Author
Moving this to the API forum.
November 22 (10 years ago)
vÍnce
Pro
Sheet Author
Hey Jack, first off thanks for contributing and second, is there anything in your script specific to d&d5e?
November 23 (10 years ago)
vÍnce
Pro
Sheet Author
Cool script Jack. My players are going to like this.
November 23 (10 years ago)
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
This is really cool idea. Thanks, Jack.
November 23 (10 years ago)
vÍnce
Pro
Sheet Author
Just some observations from playing around with the script. Token's named "TORCH" cannot be moved while !LIGHTFX ON is active and it appears that the flickering effect only works on a map that includes the players ribbon.
November 23 (10 years ago)
The flickering effect is only designed to be on for the players screen to cut down on engine overhead. Also I guess as each torch gets saved once every 200 ms it re-saves the torches position whilst it's being dragged causing it to become un-dragable. You can turn !LIGHTFX OFF to drag the torches around.
November 23 (10 years ago)
On yeah the only specific to d&D 5e is the hard coded lighting radius for a torches.
November 23 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
You should edit the original post and put the code in a code block. Just select the code and click the paragraph symbol on the toolbar (all the way to the left).

You might be able to listen to change events for tokens and enforce the move when it happens.
November 25 (10 years ago)
Code in a code block now.
November 26 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Just got a chance to try this. Pretty cute idea.

Vince said:
Token's named "TORCH" cannot be moved while !LIGHTFX ON is active
I don't know if it solves any problems for you, but you can move it with my TokenMod script. Just change the 10's to the coordinates (1-biased):
!token-mod --set top|[[( 10 *70)-35]] left|[[ ( 10 *70)-35]]

November 26 (10 years ago)
vÍnce
Pro
Sheet Author
I just knew it was only a matter of time before I fell into the TokenMod black hole. "All hail script synergy."
November 26 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Hehehehehe
November 27 (10 years ago)
I don't think there is anyway within the API to detect when a token is being dragged as there is no event for it. I had a look at using the on (change:graphic :lastmove) which detects when a token has moved, but it is not fired until after the event. I think in order to sort the issue out a Dev Team member would have to change the way Roll20 works. They would need to flag tokens as being dragged and possibly add in a dragging event. Alternatively they could implement their own flickering light function which didn't interfere with the tokens position as it is being dragged. I would imagine that this problem is going to apply to any sort of animation attempted with roll20 using interval timers.


November 27 (10 years ago)
vÍnce
Pro
Sheet Author
This is still a cool script without TORCH movement. Adding a little ambience to the party's campfire in the woods or the flickering wall sconce around the next corner, priceless. Thanks Jack.
November 27 (10 years ago)
I used it on the torches in a dungeon and one player wrote he was relogging in since there were "problems with his screen" before I could tell him it was intentional. Worked great I'd say.
November 28 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Jack, I hope you won't be offended if I roll your idea into my Torch script.
November 28 (10 years ago)
No not at all feel free to modify the script or make a new better script. If I do something good it is always nice to share it with the community and put something back in.
Ironically I can't use the torch script in my group as it seems to upset the computer of one of my players.
November 28 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Great! It's an extremely clever idea you've come up with and I'm looking forward to playing with it!

Sorry your group has problems with my script. I'm happy to help debug it.
November 28 (10 years ago)
One of my players is running on an older laptop; I can't use dynamic lighting with him as he gets nothing but a black screen. He says he has changed browsers but still no go.
While playing with the Flickering script and the Torch script on the same sheet I found I could do one or the other to a token but not both. Our resident scripting expert may resolve that issue by combing them. One day what started as a simple request to turn lights on or off from the api will be a monster with twenty or more possible arguments behind it.

November 28 (10 years ago)

Edited November 28 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Erich, both scripts adjust the light settings on the token, that's why they don't work well together. I'll have a new torch version for you that allows both later today. =D
November 28 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
Ok. New version of Torch is up!
December 31 (10 years ago)

Edited December 31 (10 years ago)
This looks awesome if you set the dim light to 0 instead of 20 and add both orange and yellow auras to the token. The only issue is that the aura are not blocked by dynamic lighting and overlap in areas where they're not supposed to.

Oh wow. That is amazing!!!!! Must have scripttt
Very nice little script and easily configurable. Workign perfect for the ghost riddled dungeon I just sent my players on :]
January 09 (10 years ago)

Edited January 09 (10 years ago)
@Honeybadger: Do you use 10 feet orange and yellow? Whats the range? :) Looks amazing.