• 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 Tfs 1.3 levers script

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
Hi, I need a simple full script for TFS 1.3 levers, if someone presses it, a fee will be charged and the person will get the item, I would like the script to work only once every 24 hours for the entire player's account and not for the character, thank you in advance
 
Solution
data/scripts/lever.lua
Lua:
local actionId = 7000
local storage = 7000
local fee = 10000
local item = 2152
local hours = 24

local function getTimeString(seconds)
    if seconds < 60 then
        return string.format("%d seconds", seconds)
    elseif seconds < 3600 then
        return string.format("%d minutes", math.floor(seconds / 60))
    end
    return string.format("%d hours", math.floor(seconds / 3600))
end

local action = Action()

function action.onUse(player, lever, fromPos, target, toPos, isHotkey)
    local now = os.time()
    local lastUse = player:getStorageValue(storage)
    if lastUse > now  then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have to wait %s before using this lever again."...
data/scripts/lever.lua
Lua:
local actionId = 7000
local storage = 7000
local fee = 10000
local item = 2152
local hours = 24

local function getTimeString(seconds)
    if seconds < 60 then
        return string.format("%d seconds", seconds)
    elseif seconds < 3600 then
        return string.format("%d minutes", math.floor(seconds / 60))
    end
    return string.format("%d hours", math.floor(seconds / 3600))
end

local action = Action()

function action.onUse(player, lever, fromPos, target, toPos, isHotkey)
    local now = os.time()
    local lastUse = player:getStorageValue(storage)
    if lastUse > now  then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have to wait %s before using this lever again.", getTimeString(lastUse - now)))
        return true
    end

    if player:getMoney() < fee then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have enough money.")
        return true
    end

    player:removeMoney(fee)
    local item = player:addItem(item, 30)
    player:setStorageValue(storage, now + hours * 3600)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have received %s", item:getDescription()))
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    lever:transform(lever:getId() == 1945 and 1946 or 1945)
    return true
end

action:aid(actionId)
action:register()
Post automatically merged:

Hi, I need a simple full script for TFS 1.3 levers, if someone presses it, a fee will be charged and the person will get the item, I would like the script to work only once every 24 hours for the entire player's account and not for the character, thank you in advance
If the script works for you or you have any problems, please let me know here.
 
Last edited:
Solution
Back
Top