• 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!

os.time

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello
i use 0.4
need script when player enter x place and say !time get msg u here from x time ago
movemnts
 
Solution
Omg... there has to be better way then this.

Here's some lua scratch code I just made..
Does anyone have a better way to do this?

I'll update this post in 10 minutes or so with the code @ConAn Edujawa wants using the above.. but I'd really like to know if someone has a better approach to getting this information.

Lua:
local old_time = 1590686611
local current_time = os.time()
local difference_in_seconds = current_time - old_time
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...
I think this will work.. untested, sorry.

XML:
<movevent type="StepIn" actionid="45001" event="script" value="time_tile.lua" />
Lua:
local storage = 45001

function onStepIn(cid, item, position, fromPosition)
    if not isPlayer(cid) then
        return true
    end
    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 on this tile!")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were last on this tile ".. os.date("!%Hh %Mm %Ss", current_time - temp_storage) .." ago!")
    end
    setPlayerStorageValue(cid, storage, current_time)
    return true
end
 
I think this will work.. untested, sorry.

XML:
<movevent type="StepIn" actionid="45001" event="script" value="time_tile.lua" />
Lua:
local storage = 45001

function onStepIn(cid, item, position, fromPosition)
    if not isPlayer(cid) then
        return true
    end
    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 on this tile!")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were last on this tile ".. os.date("!%Hh %Mm %Ss", current_time - temp_storage) .." ago!")
    end
    setPlayerStorageValue(cid, storage, current_time)
    return true
end
23:51 You were last on this tile 00h 00m 24s ago!
u can make if just seconds be like this
23:51 You were last on this tile 24s ago!
if minute
23:51 You were last on this tile xm and 24s ago!

and need this talkaction when player enter x place and say !time
 
Omg... there has to be better way then this.

Here's some lua scratch code I just made..
Does anyone have a better way to do this?

I'll update this post in 10 minutes or so with the code @ConAn Edujawa wants using the above.. but I'd really like to know if someone has a better approach to getting this information.

Lua:
local old_time = 1590686611
local current_time = os.time()
local difference_in_seconds = current_time - old_time
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

print(old_time)
print(current_time)
print(difference_in_seconds)
print(days, hours, minutes, seconds)

----------------
Edit

Okay, here is the talkaction.
Lua:
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
 
Last edited:
Solution
Back
Top