local storage = 45001
local area_top_left = {x = 900, y = 900, z = 6}
local area_bot_right = {x = 1100, y = 1100, z = 8}
local function convert_seconds_into_readable_text(value)
local difference_in_seconds = value
local days, hours, minutes, seconds = 0, 0, 0, 0
while difference_in_seconds ~= 0 do
if difference_in_seconds >= 86400 then
difference_in_seconds = difference_in_seconds - 86400
days = days + 1
elseif difference_in_seconds >= 3600 then
difference_in_seconds = difference_in_seconds - 3600
hours = hours + 1
elseif difference_in_seconds >= 60 then
difference_in_seconds = difference_in_seconds - 60
minutes = minutes + 1
else
seconds = difference_in_seconds
difference_in_seconds = 0
end
end
local text = ""
if days > 0 then
text = text .. days .. (days == 1 and " day " or " days ") .. hours .. " hours " .. minutes .. " minutes and " .. seconds .. " seconds"
elseif hours > 0 then
text = text .. hours .. " hours " .. minutes .. " minutes and " .. seconds .. " seconds"
elseif minutes > 0 then
text = text .. minutes .. " minutes and " .. seconds .. " seconds"
else
text = text .. seconds .. " seconds"
end
return text
end
function onSay(cid, words, param, channel)
local position = getThingPosition(cid)
if position.x >= area_top_left.x and position.x <= area_bot_right.x and position.y >= area_top_left.y and position.y <= area_bot_right.y and position.z <= area_top_left.z and position.z >= area_bot_right.z then
local current_time, temp_storage = os.time(), getPlayerStorageValue(cid, storage)
if temp_storage < 0 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "This is your first time using this talkaction in this area!")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were last here " .. convert_seconds_into_readable_text(current_time - temp_storage) .. " ago!")
end
setPlayerStorageValue(cid, storage, current_time)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sorry, this command cannot be used here.")
end
return true
end