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

Player.setExhaustion, Player.getExhaustion [TFS 1.0]

transform the number to a string
i believe he refers to function provide in this thread, so he can't do that, because tfs 1.x doesn't support strings as storage value.
Hello sir I replaced os.time() with os.mtime() and as you said the number gets way too so that the function stops working. What would be the best way to make the number smaller so that we can use it? Since I need to check the milliseconds.
split half of bits into two storage keys, before you use them get them together again.
 
I have never understood why add junk storage in the database,
why are tables not used in lua?
something like this


Lua:
local exhaustionTable = {}

function Player:clearExhaustion(key)
    if exhaustionTable[self:getId()] then
        exhaustionTable[self:getId()][key] = nil
      
      
        if next(exhaustionTable[self:getId()]) == nil then
            exhaustionTable[self:getId()] = nil
        end
    end
end


function Player:setExhaustion2(key, seconds)
    if not exhaustionTable[self:getId()] then
        exhaustionTable[self:getId()] = {}
    end
    exhaustionTable[self:getId()][key] = os.time() + seconds

 
    safeAddEvent(function() self:clearExhaustion(key) end, seconds * 1000)

function Player:getExhaustion2(key)
    if not exhaustionTable[self:getId()] then
        return 0
    end
    local expirationTime = exhaustionTable[self:getId()][key]
    if not expirationTime or expirationTime < os.time() then
        exhaustionTable[self:getId()][key] = nil
        return 0
    end
    return expirationTime - os.time()
end



Code:
{
    [268435457 --getId() ] = {
        [31535 --particular id of the timer ] = 1694547780 -- seconds remaining
    },
    [268435456] = {
        [31535] = 1694547792
    }
}

60 seg later



{

}
 
Last edited:
I have never understood why add junk storage in the database,
why are tables not used in lua?
something like this


Lua:
local exhaustionTable = {}

function Player:clearExhaustion(key)
    if exhaustionTable[self:getId()] then
        exhaustionTable[self:getId()][key] = nil
   
   
        if next(exhaustionTable[self:getId()]) == nil then
            exhaustionTable[self:getId()] = nil
        end
    end
end


function Player:setExhaustion2(key, seconds)
    if not exhaustionTable[self:getId()] then
        exhaustionTable[self:getId()] = {}
    end
    exhaustionTable[self:getId()][key] = os.time() + seconds

 
    safeAddEvent(function() self:clearExhaustion(key) end, seconds * 1000)

function Player:getExhaustion2(key)
    if not exhaustionTable[self:getId()] then
        return 0
    end
    local expirationTime = exhaustionTable[self:getId()][key]
    if not expirationTime or expirationTime < os.time() then
        exhaustionTable[self:getId()][key] = nil
        return 0
    end
    return expirationTime - os.time()
end



Code:
{
    [268435457 --getId() ] = {
        [31535 --particular id of the timer ] = 1694547780 -- seconds remaining
    },
    [268435456] = {
        [31535] = 1694547792
    }
}

60 seg later



{

}
Most good existing systems use tables like this to store things in memory. However....what happens when the server restarts? This is why databases are used.

But yes, you are correct, too many things in OT servers are stored in the database when they dont necessarily need to be. Only persisting values should be stored in the database. Anything that's momentary and doesn't need to persist should just be stored in memory.
 
Back
Top