![]() |
Countdown Timer
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:
PHP Code:
-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.. |
I've told you before that you shouldn't be putting numbers in quotes if you intend to manipulate them like numbers. Also, you should really be keeping one count (seconds left) and calculating number of days, hours, minutes, and seconds from it.
|
Hmm, I probably could just keep one count and divide it.
And the reason I put them in quotation marks is because when assigning variables values if it's not a number you have to encase it in them, and it's just a habit now. And it's not like it's going to affect the scripts processing time too dramaticly.. |
Quote:
This isn't code gallery material with an error like that in it. It teaches others very bad practices. |
Well I'm going to have to disagree with you there.
"Does not make it harder to read". If anything it defines what you are assigning the variable to clearer. And it does not change the way the script functions at all. |
Quote:
Quotes are for strings, not numbers. You can't keep ignoring the advice people give you and expect them to keep giving you advice. |
Quote:
I'm going to move this thread out of the Code Gallery for now, not just because of this, but also because I don't really feel like the code is particularly elegant, robust or educationally useful either. |
Yay now I can't read the replies. thanks! -.-
And "one day if I become good at scripting". I'm not as good as you at it but I'm not as bad as your making me sound. |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
He's just trying to cover some factors you didn't pay attention to while coding this. He's also trying to say that, at the moment, it's not really that much use to anybody. Maybe if you go back and clean it up, add some features that could be some use to the code gallery and come back with it. That's all he's trying to say. Thanks for making the effort though. |
Quote:
The main reason that I moved the thread out of the code gallery is because I feel that is not a good solution; you are dealing with four variables for a single timestamp, which I don't think is elegant, and not seemingly handling what happens when you start going into negative days. Maybe that introduces potential race conditions later on. You can make this much more reliable by using a single variable - the number of seconds - and printing the output format using some time formatting functions. |
Fine, if it's what everyone wants il stop using quotation marks for numbers..
I will make a GUI for setting the countdown and make it a single number and then re post in code gallery. |
All times are GMT +2. The time now is 01:02 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.