• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

getNextTime(hour, minute)

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,800
Solutions
582
Reaction score
5,363
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.
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
 
Back
Top