Heres the situation, I have a timer hooked up to the lemons, every 25 seconds, you gain a profit from how many lemons you have. Now, Im having a problem that Ive been trying to solve for like 3hours, so my last resort is facepunch; if you see in the picture there’s a green bar; how would I make the green bar scale downward(like when you take damage and your health bar goes done) but, the thing that is making it scale down would be the 25 second timer, from the lemons?
If you’re not using timer, there are several basic time calculations: Time Elapsed and Time Remaining.
I’d suggest turning your time elapsed into a float ( 0-1 modifier ) by taking time-elapsed / duration; which will cause the bar to fill from empty. To have it count backwards you simple use 1 - modifier;
Then, you multiply that by the max-width of the bar… IF you use the DProgressBar vgui element, just SetFraction to the 1 - modifier; value and it’ll handle the rest…
If I use SetNWInt:(“timerleft”, timer.TimeLeft(“lemontimer”)), would I have to set the NWInt in a think hook, since I would have to update the value every-time the timer changes? or would it update automatically?
Dose the timer.TimeLeft(), even work. I’ve been trying to just even print timer.TimeLeft(“lemontimer”) in console, serverside and or clientside, but it wont even give me a value, even tho there is a timer created
I think that for the networking side of things you should just network 2 values: ‘start of countdown’ and ‘length of countdown’, and then do the countdown on the client, if you’re not already. It could reduce some of the networking overhead and would probably be better than continuously sending the timer.TimeLeft value which will be continuously changing.
Running timers for UI elements server-side then networking the timer seems like a very overkill way of going about something seemingly this simple.
If the server needs to track this 25 second period to pay you, keep running a repeating timer on the server that does so. But make sure that the first time the timer is initialised the client is told this and then start a repeating timer on the client for the UI elements that need it.
Though if there is a bit of latency the timers may not synchronise fully, you can handle that however if you know the real world time that the server-side timer starts and the real world time the client wants to start their timer. Just make sure these values are actually using the same time zone.
Yeah trying to sync up values like this with NWInt is just asking for needless traffic in a scenario where you’re only really interested in if the timer has started or not.
It should also be quite simple to implement a method to stop both timers if the client decides they don’t want to play the thing any more too. Just tell the server with a simple message “hey stop that” and kill the timers.