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

Lever with duration

Calder

New Member
Joined
Jul 21, 2019
Messages
21
Reaction score
4
Location
Chile
TFS 1.3.10
Hello, to be honest I don't know how to add time to a lever
Lever ID 1945 1945.png

Lever ID 1946 1946.png

Magic field ID 1387tp.png

This lever starts as 1945 and when this 1946 appears the portal
Once in 1946, how do I add time limit for return to 1945?

lever.lua

Lua:
local t = {
    Position(10002, 9027, 11), -- TP location
    Position(9999, 9027, 12) -- Where the TP takes you
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then

        local teleport = Game.createItem(1387, 1, t[1])
        if teleport then
            teleport:setDestination(t[2])
            t[1]:sendMagicEffect(CONST_ME_TELEPORT)
        end
    elseif item.itemid == 1946 then
        local tile = t[1]:getTile()
        if tile then
            local teleport = tile:getItemById(1387)
            if teleport and teleport:isTeleport() then
                teleport:remove()
            end
        end
    end
    return item:transform(item.itemid == 1945 and 1946 or 1945)
end

sorry my bad english
 
Last edited:
Solution
Lua:
local t = {

    Position(999, 999, 7), -- TP location

    Position(1000, 1000, 7) -- Where the TP takes you

}



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    if item.itemid == 1945 then
        local teleport = Game.createItem(1387, 1, t[1])
        if teleport then
            teleport:setDestination(t[2])
            t[1]:sendMagicEffect(CONST_ME_TELEPORT)
        end
        item:transform(1946)
        local reset = function()
            local tile = Tile(t[1])
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if...
Lua:
local t = {

    Position(999, 999, 7), -- TP location

    Position(1000, 1000, 7) -- Where the TP takes you

}



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    if item.itemid == 1945 then
        local teleport = Game.createItem(1387, 1, t[1])
        if teleport then
            teleport:setDestination(t[2])
            t[1]:sendMagicEffect(CONST_ME_TELEPORT)
        end
        item:transform(1946)
        local reset = function()
            local tile = Tile(t[1])
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if item then
                item:transform(1945)
            end
        end
    addEvent(reset, 10000)
    end
    
    return true
end
 
Last edited:
Solution
Thanks kimokimo, a little doubt.


addEvent(reset, 10000) = 10s ?
15 minutes how would it be?
900000

Edited so it's easier for you to change time.
Lua:
local t = {
    Position(999, 999, 7), -- TP location
    Position(1000, 1000, 7), -- Where the TP takes you
}


local minutes = 15

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    if item.itemid == 1945 then
        local teleport = Game.createItem(1387, 1, t[1])
        if teleport then
            teleport:setDestination(t[2])
            t[1]:sendMagicEffect(CONST_ME_TELEPORT)
        end
        item:transform(1946)
        local reset = function()
            local tile = Tile(t[1])
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if item then
                item:transform(1945)
            end
        end
    addEvent(reset, minutes * 60 * 1000)
    end
    
    return true
end
 
Last edited:
I added a white message by pressing the lever but I could not add another message after passing the portal (crazy details).


Lua:
local t = {
    Position(10002, 9027, 11), -- TP location
    Position(9999, 9027, 12) -- Where the TP takes you
}

local minutes = 15

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    if item.itemid == 1945 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You have ' .. minutes .. ' minutes, hurry up!')
        local teleport = Game.createItem(1387, 1, t[1])
        if teleport then
            teleport:setDestination(t[2])
            t[1]:sendMagicEffect(CONST_ME_TELEPORT)
        end
        item:transform(1946)
        local reset = function()
            local tile = Tile(t[1])
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if item then
                item:transform(1945)
            end
        end
    addEvent(reset, minutes * 60 * 1000)
    end
    
    return true
end
 
@Calder @ralke
Add this to data/scripts
Lua:
local tpConfig = {
    tpLoc = Position(999, 999, 7), -- Where tp is created
    tpDest = Position(1000, 1000, 7), -- Where tp will take you
    minutes = 15,
    allowPz = false, -- True to allow people with pz to pull the lever
    enterMsg = "You have enetered the tp", -- Msg on tp enter
    tpActionId = 1212, -- Tp action id
    leverActionId = 1213 -- Lever action id
}

local lever = Action()

function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if not tpConfig.allowPz and player:isPzLocked() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You cannot activate the portal with blood on your hands, lose your pz first.')
        return true
    end
 
    if item.itemid == 1945 then
        local teleport = Game.createItem(1387, 1, tpConfig.tpLoc)
        if teleport then
            teleport:setAttribute(1, tpConfig.tpActionId)
            teleport:setDestination(tpConfig.tpDest)
            tpConfig.tpLoc:sendMagicEffect(CONST_ME_TELEPORT)
        end
        local reset = function()
            local tile = Tile(tpConfig.tpLoc)
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if item then
                item:transform(1945)
            end
        end
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You have ' .. tpConfig.minutes .. ' minutes, hurry up!')
        item:transform(1946)
        addEvent(reset, tpConfig.minutes * 60 * 1000)
    end
    return true
end
lever:aid(tpConfig.leverActionId)
lever:register()

local tp = MoveEvent()
function tp.onStepIn(creature, item, position, fromPosition)
    return creature:sendTextMessage(MESSAGE_EVENT_ADVANCE,''.. tpConfig.enterMsg ..'')
end
tp:aid(tpConfig.tpActionId)
tp:register()
 
show me your config

I only changed the portal locations

Lua:
local tpConfig = {
    tpLoc = Position(10002, 9027, 11), -- Where tp is created
    tpDest = Position(9999, 9027, 12), -- Where tp will take you
    minutes = 15,
    allowPz = false, -- True to allow people with pz to pull the lever
    enterMsg = "You have enetered the tp", -- Msg on tp enter
    tpActionId = 1212, -- Tp action id
    leverActionId = 1213 -- Lever action id
}

local lever = Action()

function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if not tpConfig.allowPz and player:isPzLocked() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You cannot activate the portal with blood on your hands, lose your pz first.')
        return true
    end
 
    if item.itemid == 1945 then
        local teleport = Game.createItem(1387, 1, tpConfig.tpLoc)
        if teleport then
            teleport:setAttribute(1, tpConfig.tpActionId)
            teleport:setDestination(tpConfig.tpDest)
            tpConfig.tpLoc:sendMagicEffect(CONST_ME_TELEPORT)
        end
        local reset = function()
            local tile = Tile(tpConfig.tpLoc)
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport and teleport:isTeleport() then
                    teleport:remove()
                end
            end
            if item then
                item:transform(1945)
            end
        end
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE,'You have ' .. tpConfig.minutes .. ' minutes, hurry up!')
        item:transform(1946)
        addEvent(reset, tpConfig.minutes * 60 * 1000)
    end
    return true
end
lever:aid(tpConfig.leverActionId)
lever:register()

local tp = MoveEvent()
function tp.onStepIn(creature, item, position, fromPosition)
    return creature:sendTextMessage(MESSAGE_EVENT_ADVANCE,''.. tpConfig.enterMsg ..'')
end
tp:aid(tpConfig.tpActionId)
tp:register()
 
Back
Top