- Joined
- Sep 7, 2015
- Messages
- 2,677
- Solutions
- 126
- Reaction score
- 2,112
This script will teleport player to the other side of the door depending on where he currently is to the door (left, right etc.). Additionaly I have added vocation and level check, that's it, very simple script.
Code:
-- written by Nekiro#5727
local config = {
checkVocation = false,
vocations = {1, 2, 3, 4, 5}, -- if check vocation
checkLevel = false,
level = 100, -- if check level
doors = { -- list of all doors that will work with this script
vertical = {1210, 1219},
horizontal = {1213, 1221},
},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local itemId, destination = item:getId()
if table.contains(config.doors.vertical, itemId) then
local playerPos, doorPos = player:getPosition(), item:getPosition()
if table.contains({Position(doorPos.x - 1, doorPos.y, doorPos.z), Position(doorPos.x - 1, doorPos.y - 1, doorPos.z), Position(doorPos.x - 1, doorPos.y + 1, doorPos.z)}, playerPos) then -- player stands left of the door
destination = Position(doorPos.x + 1, doorPos.y, doorPos.z)
elseif table.contains({Position(doorPos.x + 1, doorPos.y, doorPos.z), Position(doorPos.x + 1, doorPos.y + 1, doorPos.z), Position(doorPos.x + 1, doorPos.y - 1, doorPos.z)}, playerPos) then -- player stands right of the door
destination = Position(doorPos.x - 1, doorPos.y, doorPos.z)
end
elseif table.contains(config.doors.horizontal, itemId) then
local playerPos, doorPos = player:getPosition(), item:getPosition()
if table.contains({Position(doorPos.x, doorPos.y - 1, doorPos.z), Position(doorPos.x - 1, doorPos.y - 1, doorPos.z), Position(doorPos.x + 1, doorPos.y - 1, doorPos.z)}, playerPos) then -- player stands north of the door
destination = Position(doorPos.x, doorPos.y + 1, doorPos.z)
elseif table.contains({Position(doorPos.x, doorPos.y + 1, doorPos.z), Position(doorPos.x - 1, doorPos.y + 1, doorPos.z), Position(doorPos.x + 1, doorPos.y + 1, doorPos.z)}, playerPos) then -- player stands south of the door
destination = Position(doorPos.x, doorPos.y - 1, doorPos.z)
end
end
if not destination then
return true
end
if config.checkVocation and not table.contains(config.vocations, player:getVocation():getId()) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vocation cannot enter this door.")
return true
end
if config.checkLevel and player:getLevel() < config.level then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your level is too low.")
return true
end
player:teleportTo(destination, true)
destination:sendMagicEffect(CONST_ME_TELEPORT)
return true
end