Last active
November 7, 2017 01:43
-
-
Save Bastlifa/163e0e7a68d38d6eded53f0c546a1e20 to your computer and use it in GitHub Desktop.
Fire Trap Script for Roll20. Time update help from Aaron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A little trap | |
on("ready", function() { | |
"use strict"; | |
var i = 0; | |
const millisecondsPerSecond = 1000; // handy conversion | |
let timeForFullSpin = 15 * millisecondsPerSecond; // rotate fully in 15 seconds | |
var ShortFire = findObjs({_type: "custfx", name: "ShortFire"})[0].id | |
function FireSpin(msg, pageid) | |
{ | |
i = 0; | |
// !start | |
let startOffset = (Date.now() % timeForFullSpin); | |
var tokenObj = getObj(msg.selected[0]._type, msg.selected[0]._id); | |
var oInterval = setInterval(function() { | |
if (i == 0) | |
{ | |
let rotation = (( ( (Date.now()+startOffset) % timeForFullSpin ) / timeForFullSpin) * 360 ); | |
tokenObj.set("rotation", rotation); | |
setRotate(); | |
} | |
else clearInterval(oInterval) | |
}, 150); | |
function setRotate() | |
{ | |
spawnFxBetweenPoints({x: tokenObj.get('left') + (tokenObj.get('height')/2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation')), | |
y: tokenObj.get('top') + (tokenObj.get('height')/2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation'))}, | |
{x: tokenObj.get('left') + (tokenObj.get('height')*2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation')), | |
y: tokenObj.get('top') + (tokenObj.get('height')*2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation'))}, | |
ShortFire, | |
pageid); | |
spawnFxBetweenPoints({x: tokenObj.get('left') + (tokenObj.get('height')/2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * .5), | |
y: tokenObj.get('top') + (tokenObj.get('height')/2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * .5)}, | |
{x: tokenObj.get('left') + (tokenObj.get('height')*2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * .5), | |
y: tokenObj.get('top') + (tokenObj.get('height')*2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * .5)}, | |
ShortFire, | |
pageid); | |
spawnFxBetweenPoints({x: tokenObj.get('left') + (tokenObj.get('height')/2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1), | |
y: tokenObj.get('top') + (tokenObj.get('height')/2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1)}, | |
{x: tokenObj.get('left') + (tokenObj.get('height')*2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1), | |
y: tokenObj.get('top') + (tokenObj.get('height')*2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1)}, | |
ShortFire, | |
pageid); | |
spawnFxBetweenPoints({x: tokenObj.get('left') + (tokenObj.get('height')/2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1.5), | |
y: tokenObj.get('top') + (tokenObj.get('height')/2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1.5)}, | |
{x: tokenObj.get('left') + (tokenObj.get('height')*2)*Math.sin(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1.5), | |
y: tokenObj.get('top') + (tokenObj.get('height')*2)*Math.cos(-(Math.PI/180)*tokenObj.get('rotation') + Math.PI * 1.5)}, | |
ShortFire, | |
pageid); | |
} | |
} | |
// receive message to make the thing happen. | |
on("chat:message", function (msg) { | |
if ('api'===msg.type && playerIsGM(msg.playerid)){ | |
let player = getObj('player',msg.playerid); | |
if (msg.content === "!FireSpinTrap") | |
{ | |
FireSpin(msg, player.get('lastpage')); | |
} | |
if (msg.content === "!FireSpinStop") | |
{ | |
i = 1; | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment