local ladders = {1386} -- add ladder id's here
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local tile = Tile(toPosition)
if not tile then return true end
local tile_items, player_pos = tile:getItems(), player:getPosition()
for key, tile_item in pairs(tile_items) do
if player_pos ~= toPosition and isInArray(levelDoors, tile_item.itemid) then
if tile_item.actionid > 0 and player:getLevel() >= tile_item.actionid - 1000 then
item:transform(tile_item.itemid + 1)
player:teleportTo(toPosition, true)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
end
break
elseif isInArray(verticalOpenDoors, tile_item.itemid) or isInArray(horizontalOpenDoors, tile_item.itemid) then
local doorCreature, original_id = Tile(toPosition):getTopCreature(), tile_item.itemid
if doorCreature then
toPosition.x = toPosition.x + 1
local query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
if query ~= RETURNVALUE_NOERROR then
toPosition.x = toPosition.x - 1
toPosition.y = toPosition.y + 1
query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
end
if query ~= RETURNVALUE_NOERROR then
player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(query))
return true
end
doorCreature:teleportTo(toPosition, true)
end
item:remove()
if original_id == tile_item.itemid then
tile_item:transform(tile_item.itemid - 1)
end
break
elseif isInArray(ladders, tile_item.itemid) then
player:teleportTo(toPosition:moveUpstairs())
break
end
end
return true
end