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

A little fire trap script

1503664129

Edited 1503664283
Bast L.
Pro
API Scripter
I've just been playing around, and made a little script. Sometimes it lags and then does a lot at once. Anyways, this script will spout fire from a rotating token. For ease of use, set the token to represent a fire trap character with token action macros: activate, deactivate. The macros should have these bodies, respectively: !FireSpinTrap !FireSpinStop The custom fx (adjust as needed. Shorten the lifespan for a shorter beam, change color for.. etc), name it ShortFire, or adjust the script: { "angle": -1, "angleRandom": 0, "duration": 7, "emissionRate": 70, "endColour": [220, 35, 0, 0], "endColourRandom": [60, 60, 60, 0], "lifeSpan": 10, "lifeSpanRandom": 0, "maxParticles": 500, "size": 8, "sizeRandom": 0, "speed": 30, "speedRandom": 10, "startColour": [220, 35, 0, 1], "startColourRandom": [62, 0, 0, 0.25] } The script:&nbsp; <a href="https://gist.github.com/Bastlifa/163e0e7a68d38d6ed" rel="nofollow">https://gist.github.com/Bastlifa/163e0e7a68d38d6ed</a>... A screenshot:
1503665535
The Aaron
Pro
API Scripter
Cute!
1503666807

Edited 1503669247
The Aaron
Pro
API Scripter
One thing you can do to keep the rotation seeming vaguely steady is tie the current angle to the time, rather than a fixed adjustment on the current rotation. &nbsp; The reason you get the slingshotting is that setInterval() specifies the minimum amount of time before the event occurs, but it can be preempted by more important events causing it occur later. &nbsp;If that happens enough, 2-3 of your intervals might occur right on top of each other. &nbsp;I imagine spacing books evenly on a shelf. &nbsp;Each book is an execution of the interval. &nbsp;When things fall behind, it's like putting your hand in at the left and pushing a bunch of them together to the right. Instead if you grab the time whenever you get activated, you can set the rotation to what it should be at the current time. &nbsp;More like looking how far along the shelf the book is and rotating based on that. &nbsp;The basic formula for this is: const millisecondsPerSecond = 1000; // handy conversion let timeForFullSpin = 15 * millisecondsPerSecond; // rotate fully in 15 seconds let rotation = (( (Date.now() % timeForFullSpin ) / timeForFullSpin) * 360 ); Date.now() returns the time in milliseconds. % gives you the remainder after dividing by a number. (Date.now() % timeForFullSpin) will be between 0 and (timeForFullSpin-1), the "distance along the shelf". ((Date.now() % timeForFullSpin) / timeForFullSpin) normalizes that "distance along the shelf" to the mathematical interval [0,1). Multiplying that by 360 scales it to degrees of rotation. Doing that, you get an apparently constant rate of rotation, even though the amount rotated at each interval is varying. The only hiccup to be aware of is that when you begin the rotation, you might be in the middle of "the shelf" so the object will jump to a particular rotation. &nbsp;That doesn't bother me in the places I've done this, but if you want to account for that as well and get perfectly smooth transition from stopped to spinning, you can at activation grab the&nbsp;(Date.now() % timeForFullSpin) number and store it, then always add it to Date.now() when calculating the current rotation: const millisecondsPerSecond = 1000; // handy conversion let timeForFullSpin = 15 * millisecondsPerSecond; // rotate fully in 15 seconds // !start let startOffset = (Date.now() % timeForFullSpin); // on interval let rotation = (( ( (Date.now() +startOffset ) % timeForFullSpin ) / timeForFullSpin) * 360 );
1503668792
Bast L.
Pro
API Scripter
Thanks. That helped a lot, though it still seems to happen sometimes. To get this one, I paused and started a netflix stream while the thing was rotating:
1503668901
Bast L.
Pro
API Scripter
Er, nvm, I still have my interval going and spawning the lines. I'll have to read and think about this not on 2 hours sleep :)
1503669069
The Aaron
Pro
API Scripter
Hey, that's pretty cool though... as a PC, if I saw THAT when I opened the door, I'd give up the life of adventure then and there! =D
1503670870
Munky
Roll20 Production Team
Marketplace Creator
Compendium Curator
Spinning lamp of doom! That's pretty sweet!
Love this and my players will hate it &nbsp;: ) Thank you
1503982417
Bast L.
Pro
API Scripter
Thanks, I've been meaning to look at updating it with Aaron's suggestions, but I'm too lazy I think. Also, working on other projects :)
nice effect! Consider it stolen. :)