- Joined
- Nov 17, 2010
- Messages
- 6,824
- Solutions
- 586
- Reaction score
- 5,403
Just had this sitting around.
Figured I might as well post it, someone will probably find it useful.
Mostly useful for storage values, so players know a daily task resets at a specific time, for example.
Figured I might as well post it, someone will probably find it useful.
Mostly useful for storage values, so players know a daily task resets at a specific time, for example.
Lua:
-- example with storage values
local next1PM = getNextTime(13)
player:setStorageValue(storageKey, next1PM)
if player:getStorageValue(storageKey) > os.time() then
-- next 1pm hasn't come around
return false
end
Lua:
-- To get the next 1 PM
local next1PM = getNextTime(13)
print("The next 6 PM is at timestamp: " .. next1PM)
-- To get the next 7:30 AM
local next730AM = getNextTime(7, 30)
print("The next 7:30 AM is at timestamp: " .. next730AM)
Lua:
function getNextTime(hour, minute)
local now = os.time()
local dateTable = os.date("*t", now)
dateTable.hour = hour
dateTable.min = minute or 0
dateTable.sec = 0
local targetTime = os.time(dateTable)
if now > targetTime then
targetTime = targetTime + (24 * 60 * 60)
end
return targetTime
end