local allow = {
[NORTH] = {106, 109}, -- allow walking from north
[EAST] = {106, 109}, -- allow walking from east
[SOUTH] = {}, -- allow walking from south
[WEST] = {106, 109}, -- allow walking from west
[SOUTHEAST] = {}, -- allow walking from southeast
[NORTHEAST] = {106, 109}, -- allow walking from northeast
[SOUTHWEST] = {}, -- allow walking from southwest
[NORTHWEST] = {106, 109}, -- allow walking from northwest
}
local allowOut = {
[106] = {EAST, WEST, SOUTH, SOUTHEAST, SOUTHWEST}, -- allow walkout to
[109] = {EAST, WEST, SOUTH, SOUTHEAST, SOUTHWEST}, -- allow walkout to
}
function getDirection(pos, posEx)
if pos.x < posEx.x then
if pos.y < posEx.y then
return SOUTHEAST
elseif pos.y > posEx.y then
return NORTHEAST
else
return EAST
end
elseif pos.x > posEx.x then
if pos.y < posEx.y then
return SOUTHWEST
elseif pos.y > posEx.y then
return NORTHWEST
else
return WEST
end
elseif pos.y > posEx.y then
if pos.x < posEx.x then
return NORTHEAST
elseif pos.x > posEx.x then
return NORTHWEST
else
return NORTH
end
elseif pos.y < posEx.y then
if pos.x > posEx.x then
return SOUTHWEST
elseif pos.x < posEx.x then
return SOUTHEAST
else
return SOUTH
end
end
end
function onStepIn(creature, item, position, fromPosition)
if position.x == fromPosition.x and position.y == fromPosition.y then
return true
end
local dir = getDirection(position, fromPosition)
if not table.find(allow[dir], item.itemid) then
creature:teleportTo(fromPosition, false)
creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
end
return true
end
function onStepOut(creature, item, position, fromPosition)
position = creature:getPosition()
if position.x == fromPosition.x and position.y == fromPosition.y then
return true
end
local dir = getDirection(position, fromPosition)
if not table.find(allowOut[item.itemid], dir) then
creature:teleportTo(fromPosition, false)
creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
end
return true
end