local questStorage = 12345
function getTime(time_)
return os.date("*t", time_ or os.time())
end
function setTime(y, m, d, h, mi, s)
local t = {
year = getTime().year + (y or 0),
month = getTime().month + (m or 0),
day = getTime().day + (d or 0),
hour = getTime().hour + (h or 0),
min = getTime().min + (mi or 0),
sec = getTime().sec + (s or 0)
}
return t
end
function setQuestStorage(player, storage, value)
if player:isPlayer() then
player:setStorageValue( storage, os.time( setTime(nil, nil, nil, value, nil, nil) ) )
end
end
local avoid = {'year', 'month', 'wday', 'yday', 'day', 'isdst' }
function getQuestData(player, storage)
if not player:isPlayer() then
return false
end
local questTime = {}
local temp = getTime( player:getStorageValue(storage) )
for prop, value in pairs( temp ) do
if not isInArray(avoid, prop) then
questTime[prop] = value
end
end
return questTime, os.time(temp)
end
function onSay(player, words, param)
local data, time_ = getQuestData(player, questStorage)
if data then
local msg = ""..(data.hour > 0 and data.hour .." hour(s)," or '').." "..(data.min > 0 and data.min.." minutes(s)," or '').." "..(data.sec > 0 and data.sec.." second(s)," or '')
if time_ > os.time() then
player:sendTextMessage(TALKTYPE_ORANGE_2, "You have ".. msg .. " of time remainning.")
else
player:sendTextMessage(TALKTYPE_ORANGE_2, "You don't have any quest activated.")
end
end
return false
end