local bookId = 1950 -- book id
local bookPos = Position(1000, 1000, 7) -- book position
-- the item, such as a bookcase or whatever you want to move
local itemConfig = {
id = 1036, -- id
fromPos = Position(1000, 1000, 7), -- from position
toPos = Position(1000, 1000, 7) -- to position
}
local event = EventCallback
function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if item:getId() ~= bookId or (toPosition ~= bookPos and fromPosition ~= bookPos) then
return true
end
if toPosition ~= bookPos then
itemConfig.fromPos, itemConfig.toPos = itemConfig.toPos, itemConfig.fromPos
end
local tile = Tile(itemConfig.fromPos)
if not tile then
return true
end
local moveItem = tile:getItemById(itemConfig.id)
if not moveItem then
return true
end
local targetTile = Tile(itemConfig.toPos)
if targetTile:hasFlag(TILESTATE_BLOCKSOLID) then
return true
end
if moveItem:moveTo(itemConfig.toPos) ~= RETURNVALUE_NOERROR then
moveItem:remove()
Game.createItem(itemConfig.id, 1, itemConfig.toPos)
end
end
event:register()