• 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 lever tfs 1.3

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
Hi I need a simple script for tfs 1.3 :

after pressing the lever we are moved from place "a" to place "b" after 5 minutes we are automatically moved back to place "c" (time countdown after pressing the lever)

"a" lever id1945
"b" position after clicking the lever
"c" temple position (return after 5 minutes)
 
Again, I copied the needed parts from here because it is very close to boss room just without boss summon.
Try it.
Lua:
local config = {
    actionId = 5901, -- ActionID to use in the lever
    bossArea = {
        fromPos = Position(3101, 1845, 7), -- Upper left corner of the room
        toPos = Position(3120, 1855, 7), -- Lower right corner of the room
        entrancePos = Position(3119, 1845, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(3118, 1842, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    participantsAllowAnyCount = true, -- allow any valid number of participants to enter. example: 1,2,3 or 4
    participantsPos = {
        Position(3117, 1842, 7), -- Player 1, this player should be the one to pull the lever
        Position(3118, 1842, 7), -- Player 2
        Position(3119, 1842, 7), -- Player 3
        Position(3120, 1842, 7) -- Player 4
    },
    attempts = {
        level = 200 -- Level required to enter
    },
    kickParticipantAfterSeconds = 60 * 5, -- 5 minutes
    leverIds = {1945, 1946} -- Lever animation, on/off
}

local function getSpectators()
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(
        config.centerPosition,
        false,
        false,
        config.diffX,
        config.diffX,
        config.diffY,
        config.diffY
    )
end

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then
            error("[Warning - Tile not found]")
        end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end
            if participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(
                    string.format("The player %s is not level %d.", participant:getName(), config.attempts.level)
                )
                return true
            end

            participants[#participants + 1] = participant
        elseif not participantsAllowAnyCount then
            player:sendCancelMessage("Participants are missing.")
            return true
        end
    end
    for index, participant in pairs(participants) do
        config.participantsPos[index]:sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        config.bossArea.entrancePos:sendMagicEffect(CONST_ME_TELEPORT)
    end

    config.kickEventId =
        addEvent(
        function()
            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.bossArea.exitPosition, false)
                    config.bossArea.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                    spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It's been a long time.")
                end
            end
        end,
        config.kickParticipantAfterSeconds * 1000
    )

    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.actionId)
action:register()
 
Again, I copied the needed parts from here because it is very close to boss room just without boss summon.
Try it.
Lua:
local config = {
    actionId = 5901, -- ActionID to use in the lever
    bossArea = {
        fromPos = Position(3101, 1845, 7), -- Upper left corner of the room
        toPos = Position(3120, 1855, 7), -- Lower right corner of the room
        entrancePos = Position(3119, 1845, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(3118, 1842, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    participantsAllowAnyCount = true, -- allow any valid number of participants to enter. example: 1,2,3 or 4
    participantsPos = {
        Position(3117, 1842, 7), -- Player 1, this player should be the one to pull the lever
        Position(3118, 1842, 7), -- Player 2
        Position(3119, 1842, 7), -- Player 3
        Position(3120, 1842, 7) -- Player 4
    },
    attempts = {
        level = 200 -- Level required to enter
    },
    kickParticipantAfterSeconds = 60 * 5, -- 5 minutes
    leverIds = {1945, 1946} -- Lever animation, on/off
}

local function getSpectators()
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(
        config.centerPosition,
        false,
        false,
        config.diffX,
        config.diffX,
        config.diffY,
        config.diffY
    )
end

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then
            error("[Warning - Tile not found]")
        end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end
            if participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(
                    string.format("The player %s is not level %d.", participant:getName(), config.attempts.level)
                )
                return true
            end

            participants[#participants + 1] = participant
        elseif not participantsAllowAnyCount then
            player:sendCancelMessage("Participants are missing.")
            return true
        end
    end
    for index, participant in pairs(participants) do
        config.participantsPos[index]:sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        config.bossArea.entrancePos:sendMagicEffect(CONST_ME_TELEPORT)
    end

    config.kickEventId =
        addEvent(
        function()
            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.bossArea.exitPosition, false)
                    config.bossArea.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                    spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It's been a long time.")
                end
            end
        end,
        config.kickParticipantAfterSeconds * 1000
    )

    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.actionId)
action:register()

M0ustafa

Could you please edit the script so that only one person can enter after pressing the lever? and the next one so that she can enter only after the previous one leaves after 5 minutes? thank you
 
This should work.
Lua:
local config = {
    actionId = 5901, -- ActionID to use in the lever
    bossArea = {
        fromPos = Position(3101, 1845, 7), -- Upper left corner of the room
        toPos = Position(3120, 1855, 7), -- Lower right corner of the room
        entrancePos = Position(3119, 1845, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(3118, 1842, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    participantPos = Position(3117, 1842, 7), -- Player, this player should be the one to pull the lever
    attempts = {
        level = 200 -- Level required to enter
    },
    kickParticipantAfterSeconds = 60 * 5, -- 5 minutes
    leverIds = {1945, 1946} -- Lever animation, on/off
}

local function getSpectators()
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(
        config.centerPosition,
        false,
        false,
        config.diffX,
        config.diffX,
        config.diffY,
        config.diffY
    )
end

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local tile = Tile(config.participantPos)
    if not tile then
        error("[Warning - Tile not found]")
    end
    local participant = tile:getTopVisibleCreature(player)
    if not participant then
        player:sendCancelMessage("You're not standing in the correct tile.")
        return true
    end
    if player:getLevel() < config.attempts.level then
        player:sendCancelMessage(
            string.format("The player %s is not level %d.", player:getName(), config.attempts.level)
        )
        return true
    end
    local spectators = getSpectators()
    for _, spectator in pairs(spectators) do
        if spectator:isPlayer() then
            player:sendCancelMessage("At this time the room is occupied, please try again later.")
            return true
        end
    end
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:teleportTo(config.bossArea.entrancePos, false)
    config.bossArea.entrancePos:sendMagicEffect(CONST_ME_TELEPORT)

    config.kickEventId =
        addEvent(
        function()
            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.bossArea.exitPosition, false)
                    config.bossArea.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                    spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It's been a long time.")
                end
            end
        end,
        config.kickParticipantAfterSeconds * 1000
    )

    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.actionId)
action:register()
 
Last edited:
Post the script after your changes, I just tested in-game a copy-paste and it works.
Based on your error, You mostly removed this local action = Action() by mistake.
 
Back
Top