• 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 [Change OTX 0.3.7 to TFS 1.5] Script Global Exhausted

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi otlanders,

data/talkactions/lib/talkactions.lua
Lua:
-- Prevent spamm commands --
function checkExhausted(cid, storage, seconds)
    local v = exhaustion.get(cid, storage)
    if(not v) then
        exhaustion.set(cid, storage, seconds)
    else
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Please wait " .. v .. " seconds before trying this command again.")
        return false
    end

    return true
end

Below the onSay function

Lua:
    if(not checkExhausted(cid, 666, 10)) then
        return false
    end
 
data/lib/core/core.lua

at the end, add:

Lua:
dofile('data/lib/core/vocation.lua')

data/lib/core/exhaustion.lua

create

Lua:
exhaustion =
{
    check = function (player, storage)
        if(player:hasFlag(PlayerFlag_HasNoExhaustion)) then
            return false
        end

        return player:getStorageValue(storage) >= os.time()
    end,

    get = function (player, storage)
        if(player:hasFlag(PlayerFlag_HasNoExhaustion)) then
            return false
        end

        local exhaust = player:getStorageValue(storage)
        if(exhaust > 0) then
            local left = exhaust - os.time()
            if(left >= 0) then
                return left
            end
        end

        return false
    end,

    set = function (player, storage, time)
        player:setStorageValue(storage, os.time() + time)
    end,

    make = function (player, storage, time)
        local exhaust = exhaustion.get(player, storage)
        if(not exhaust) then
            exhaustion.set(player, storage, time)
            return true
        end

        return false
    end
}

Usage is almost the same, just instead of "cid" you write "player".

So your function could be:
Lua:
function checkExhausted(player, storage, seconds)
    local v = exhaustion.get(player, storage)
    if(not v) then
        exhaustion.set(player, storage, seconds)
    else
        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Please wait " .. v .. " seconds before trying this command again.")
        return false
    end

    return true
end
 
Back
Top