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

darkangel1

New Member
Joined
Oct 31, 2023
Messages
53
Reaction score
4
Hello. I'm trying to make a teleport lever, similar to the annihilator quest. But nothing works for me.
A character stands on a certain plate z-y-z, press a lever and he will be teleported to another x-y-z location. Can anyone help?
 
Solution
data/scripts
Lua:
local config = {
    leverId = {1945, 1946}, -- {defaultId, pulledId}
    actionId = 1234, -- ActionID on lever
    leverPos = Position(959, 1082, 7),
    resetTime = 2, -- Seconds
    tilePos = Position(Position(959, 1081, 7)), -- Position player has to stand on to pull the lever
    newPos = Position(Position(963, 1081, 7)), -- Position player get teleported to
}

local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPosition() ~= config.tilePos then
        player:sendCancelMessage("You can't pull the lever from here.")
        return true
    end

    if item:getId() == config.leverId[2] then
        player:sendCancelMessage("Please wait for the...
Hello. I'm trying to make a teleport lever, similar to the annihilator quest. But nothing works for me.
A character stands on a certain plate z-y-z, press a lever and he will be teleported to another x-y-z location. Can anyone help?
Wich engine?
 
data/scripts
Lua:
local config = {
    leverId = {1945, 1946}, -- {defaultId, pulledId}
    actionId = 1234, -- ActionID on lever
    leverPos = Position(959, 1082, 7),
    resetTime = 2, -- Seconds
    tilePos = Position(Position(959, 1081, 7)), -- Position player has to stand on to pull the lever
    newPos = Position(Position(963, 1081, 7)), -- Position player get teleported to
}

local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPosition() ~= config.tilePos then
        player:sendCancelMessage("You can't pull the lever from here.")
        return true
    end

    if item:getId() == config.leverId[2] then
        player:sendCancelMessage("Please wait for the lever to reset.")
        return true
    end

    if item:getId() == config.leverId[1] then
        item:transform(config.leverId[2])
        player:teleportTo(config.newPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been teleported.")

        addEvent(function()
            local tile = Tile(config.leverPos)
            local lever = tile and tile:getItemById(config.leverId[2])
            if lever then
                lever:transform(config.leverId[1])
            end
        end, config.resetTime * 1000)
    end
    return true
end

action:aid(config.actionId)
action:register()
 
Solution
data/scripts
Lua:
local config = {
    leverId = {1945, 1946}, -- {defaultId, pulledId}
    actionId = 1234, -- ActionID on lever
    leverPos = Position(959, 1082, 7),
    resetTime = 2, -- Seconds
    tilePos = Position(Position(959, 1081, 7)), -- Position player has to stand on to pull the lever
    newPos = Position(Position(963, 1081, 7)), -- Position player get teleported to
}

local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPosition() ~= config.tilePos then
        player:sendCancelMessage("You can't pull the lever from here.")
        return true
    end

    if item:getId() == config.leverId[2] then
        player:sendCancelMessage("Please wait for the lever to reset.")
        return true
    end

    if item:getId() == config.leverId[1] then
        item:transform(config.leverId[2])
        player:teleportTo(config.newPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been teleported.")

        addEvent(function()
            local tile = Tile(config.leverPos)
            local lever = tile and tile:getItemById(config.leverId[2])
            if lever then
                lever:transform(config.leverId[1])
            end
        end, config.resetTime * 1000)
    end
    return true
end

action:aid(config.actionId)
action:register()
I pasted this script into the directory and created tiles and a lever, but for some reason it doesn't work
C:\Uforgottenserver-1.4.2\data\scripts
Post automatically merged:

data/scripts
Lua:
local config = {
    leverId = {1945, 1946}, -- {defaultId, pulledId}
    actionId = 1234, -- ActionID on lever
    leverPos = Position(959, 1082, 7),
    resetTime = 2, -- Seconds
    tilePos = Position(Position(959, 1081, 7)), -- Position player has to stand on to pull the lever
    newPos = Position(Position(963, 1081, 7)), -- Position player get teleported to
}

local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getPosition() ~= config.tilePos then
        player:sendCancelMessage("You can't pull the lever from here.")
        return true
    end

    if item:getId() == config.leverId[2] then
        player:sendCancelMessage("Please wait for the lever to reset.")
        return true
    end

    if item:getId() == config.leverId[1] then
        item:transform(config.leverId[2])
        player:teleportTo(config.newPos)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been teleported.")

        addEvent(function()
            local tile = Tile(config.leverPos)
            local lever = tile and tile:getItemById(config.leverId[2])
            if lever then
                lever:transform(config.leverId[1])
            end
        end, config.resetTime * 1000)
    end
    return true
end

action:aid(config.actionId)
action:register()
Sorry dude, I put the script in data/scripts/action and it worked. Thanks a lot
 
Back
Top