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()