local keyId = 2086
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerItemCount(cid, keyId) < 1 then
doPlayerSendTextMessage(cid, 22, "This door requires a special key to enter.")
return true
end
local playerPosition = getThingPos(cid)
if playerPosition.x - toPosition.x ~= 0 and playerPosition.y - toPosition.y ~= 0 then
doPlayerSendTextMessage(cid, 22, "You must be standing in front of the door to see the keyhole.")
return true
end
local otherSide
if playerPosition.x < toPosition.x then
otherSide = {x = toPosition.x + 1, y = toPosition.y, z = toPosition.z}
elseif playerPosition.x > toPosition.x then
otherSide = {x = toPosition.x - 1, y = toPosition.y, z = toPosition.z}
elseif playerPosition.y < toPosition.y then
otherSide = {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z}
else
otherSide = {x = toPosition.x, y = toPosition.y - 1, z = toPosition.z}
end
doTeleportThing(cid, otherSide)
doPlayerSendTextMessage(cid, 22, "The key was destroyed.. But you passed through the door!")
doSendMagicEffect(getThingPos(cid), 12)
doPlayerRemoveItem(cid, keyId, 1)
return true
end