PHP Code:
//#CLIENTSIDE
function onCreated() {
// I'd be wary of using a variable named this.timer. This.timer might be reserved for actual timeouts
// Initiate a new variable that logs the current time
// We will later use this to keep track of the countdown
// via offsetting it. If this.countdowntime > timevar2, then assume it is counting down
this.countdowntime = timevar2;
}
function onPlayerChats() {
// Call the function to start the countdown, let it know you want it to be 15 seconds
if (player.chat == "/count") Countdown(15);
}
function Countdown(t) {
// Take timevar2 as a reference point and add the time(t) provided to it. This will let
// the script know there is now time + t amount of time for the countdown
this.countdowntime = timevar2 + t;
// As long as timevar2 is less than this.countdowntime, then there is a countdown occuring
// Use while to create a loop(for updating). This is similar to a timeout, as it will
// continue to execute the script as long as the statement is true
while (timevar2 < this.countdowntime) {
// Do some basic math to find the difference in time(the countdown)
// Also round it with int(x + .5) or else you'll get large floating values like 12.23463452342345356463
this.chat = int(this.countdowntime - timevar2 + .5);
sleep(.5); // No need to update the loop more frequently than this since we're providing decrements in seconds
}
this.chat = "Countdown complete!";
}