// GitHub: https://github.com/JamesMowery/turn-timer
// By: James Mowery
// Contact: https://app.roll20.net/users/1001679/james-mowery
var seconds = 0;
var interval = null;
var TurnTimer = TurnTimer || (function() {
'use strict';
var version = "0.0.1";
});
function countDown() {
'use strict';
seconds = seconds - 1;
if (seconds == 121) {
sendChat("GM", "
\
\
2 Minutes Remaining
");
}
if (seconds == 61) {
sendChat("GM", " \
\
1 Minute Remaining
");
}
if (seconds == 16) {
sendChat("GM", " \
\
15 Seconds Remaining!
");
}
if (seconds <= 0) {
sendChat("GM", " \
\
Time\'s Up!
");
clearInterval(interval);
}
}
on("chat:message", function(msg) {
'use strict'
// When the GM types !t , start a timer for seconds
if(msg.type == "api" && msg.content.indexOf("!timer ") !== -1) {
// Clear the previous timer if running.
clearInterval(interval);
log("Detected Typing");
// Extracts the number of seconds in the command
seconds = Number(msg.content.replace("!timer ", ""));
log(seconds);
// Begin the countdown
interval = setInterval(countDown, 1000, seconds);
// Inform the players that the timer has started
sendChat("GM", " \
\
Timer Started
");
}
// When the GM types !t, start a timer for a default number of seconds
else if(msg.type == "api" && msg.content.indexOf("!timer") !== -1) {
clearInterval(interval); // Clear the previous timer if running.
seconds = 60; // Sets the default number of seconds
// Begins the countdown
interval = setInterval(countDown, 1000, seconds);
sendChat("GM", " \
\
Timer Started - 1 Minute
");
}
});
on("ready", function() {
'use strict';
});