This is just a simple example of a countdown timer.
First off you will need to place this code into a database NPC on your server.
So go ahead and click add and name it whatever you wish and paste the code into the NPC's script.
PHP Code:
function onCreated() {
this.daysleft = "10";
this.hoursleft = "10";
this.minutesleft = "10";
this.secondsleft = "10";
onTimeout();
}
function onTimeout() {
this.secondsleft -= 1;
if (this.secondsleft == 0 || this.secondsleft < 0) {
this.minutesleft -= 1;
this.secondsleft = 60;
}
if (this.minutesleft == 0 || this.minutesleft < 0) {
this.hoursleft -= 1;
this.minutesleft = 60;
}
if (this.hoursleft == 0 || this.hoursleft < 0) {
this.daysleft -= 1;
this.hoursleft = 24;
}
settimer(1);
}
public function GetTimeLeft() {
return "Days: " @ this.daysleft @ " Hours: " @ this.hoursleft @ " Minutes: " @ this.minutesleft @ " Seconds: " @ this.secondsleft;
}
To get the time simple place this code into a level NPC.
PHP Code:
function onCreated() {
onTimeout();
}
function onTimeout() {
this.chat = NPCNAME.GetTimeLeft();
settimer(0.5);
}
But substiture NPCNAME for whatever you named the database NPC.
-Enjoy
Also for the smart ones out there, I am thinking of making a weapon where a player can set their own countdown.
The only problem so far is how would it countdown if the player is offline?
Of course you could just make a dozen or so server variables but that's a bad way.
Would making a timevar and setting it to a clientr variable work?
But even if it would that would only be good for counting down seconds..