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

Lua Need help with calculation

Sortdcz

New Member
Joined
Sep 2, 2013
Messages
14
Reaction score
0
hello

I have a problem with a calculation, I'm using
Code:
function timeString(timeDiff)
local dateFormat = {
{"day", timeDiff / 60 / 60 / 24},
{"hour", timeDiff / 60 / 60 % 24},
{"minute", timeDiff / 60 % 60},
{"second", timeDiff % 60}
}

local out = {}
for k, t in ipairs(dateFormat) do
local v = math.floor(t[2])
if(v > 0) then
table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
end
end
local ret = table.concat(out)
if ret:len() < 16 and ret:find("second") then
local a, b = ret:find(" and ")
ret = ret:sub(b+1)
end

return ret
end
to get remaining seconds after i get a storagevalue.

So, my problem here is following: i want to use this like 'There's still ' .. timeString(time) .. ' 'left until you can use this again.'

my calculation is: local time = os.time() - player:getStorageValue(14092) but it don't give me right calculation. I do this to get some time between usage of item like player:setStorageValue(14092, os.time() + 100 but it don't say this after, just random like 8 h left...
help please :))
 
This function is perfectly fine, you have to provide the script that you are using it or we cannot help you.
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if(msgcontains(msg, "fish")) then
            if player:getStorageValue(85091) >= os.time() then
                local time = 6 * 10 * 1 - os.time() - player:getStorageValue(85091) -- this calculation i need help with
                npcHandler:say('You can get a new fish in ' .. timeString(time) .. '.', cid) -- i want it to say remaining time here
                npcHandler.topic[cid] = 0
            else
                npcHandler:say('take this fish.', cid)
                player:setStorageValue(85091, os.time() + 6 * 10 * 1)
                player:addItem(2667, 10)
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

need help with calculation local time
 
Back
Top