Created
June 3, 2017 16:08
-
-
Save Bastlifa/2651519cd91276bb101bb983e2cd733a to your computer and use it in GitHub Desktop.
Turnclock for roll20, with help (rewrite really) from Aaron
This file contains 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
on("ready", function() { | |
"use strict"; | |
on("chat:message", function (msg) { | |
var args; | |
if (msg.type === "api"){ | |
args = msg.content.split(/\s+/); | |
if (args[0].match(/^!Clock/i)){ | |
let time = parseInt(args[1],10)||0; | |
if(time){ | |
let due = _.now()+time*1000, | |
tokens = _.chain(msg.selected) | |
.map((o)=>getObj('graphic',o._id)) | |
.reject(_.isUndefined) | |
.value(), | |
names = _.map(tokens,(t)=>t.get('name')), | |
numCheck, | |
updateClock = ()=>{ | |
let num=Math.ceil((due-_.now())/1000); | |
if(num>0){ | |
_.map(tokens,(t)=>t.set('status_stopwatch',num)); | |
if (numCheck !== num){ | |
sendChat("", "Turn Time Remaining: " + num); | |
numCheck = num; | |
} | |
_.delay(updateClock,200); | |
} else { | |
_.map(tokens,(t)=>t.set('status_stopwatch',false)); | |
sendChat("TurnClock", "!Sound: Buzzer"); | |
sendChat("", "Turn Over!"); | |
} | |
}; | |
sendChat("TurnClock", "!Sound: Ticking Clock"); | |
sendChat("", "TurnClock Started on: " + names.join(', ')); | |
updateClock(); | |
} | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment