RIPPER0NI
|
  |
| Joined: 14 Apr 2011 |
| Total Posts: 141 |
|
|
| 28 Nov 2017 08:01 AM |
Hello. I am making a game, and I want to have a counter which is going to say the days left until christmas.
The problem is that every new server the date will be what I set in studio.
Is there a way to make it so that I can have globally across all servers that will update across all servers at the same time and all the identical
|
|
|
| Report Abuse |
|
|
|
| 28 Nov 2017 09:42 AM |
function getTimeUntil(t) local reservoir = os.difftime(t, os.time()) local secs = reservoir % 60 reservoir = math.floor(reservoir/60) local mins = reservoir % 60 reservoir = math.floor(reservoir/60) local hours = reservoir % 24 reservoir = math.floor(reservoir/24) local days = reservoir % 365 return days, hours, mins, secs end
local christmas = os.time({year=2017, month=12, day=25, hour=1, min=0, sec=0}) print(string.format( "%d days, %d hours, %d minutes and %s seconds until Christmas!", getTimeUntil(christmas) )) --> 26 days, 9 hours, 20 minutes and 25 seconds until Christmas!
|
|
|
| Report Abuse |
|
|
|
| 28 Nov 2017 02:13 PM |
This version will repeat the countdown line every second, updating the output. You can use the loop in the same way to update a TextLabel or whatever you want instead of just printing to the output window.
function unpackTimeSpan(fromTime, toTime) local reservoir = os.difftime(toTime, fromTime) local secs = reservoir % 60 reservoir = math.floor(reservoir/60) local mins = reservoir % 60 reservoir = math.floor(reservoir/60) local hours = reservoir % 24 reservoir = math.floor(reservoir/24) local days = reservoir % 365 return days, hours, mins, secs end
local now = os.time() local christmas = os.time({year=os.date("*t", now).year, month=12, day=25, hour=1, min=0, sec=0}) while wait(1) do now = now + 1 print( string.format( "%d days, %d hours, %d minutes and %s seconds until Christmas!", unpackTimeSpan(now, christmas) ) ) end
|
|
|
| Report Abuse |
|
|