1function onStepOut(creature, item, position, fromPosition)
2 local tile = Tile(position)
3 if tile:getCreatureCount() > 0 then
4 return true
5 end
6
7 local newPosition = {x = position.x + 1, y = position.y, z = position.z}
8 local query = Tile(newPosition):queryAdd(creature)
9 if query ~= RETURNVALUE_NOERROR or query == RETURNVALUE_NOTENOUGHROOM then
10 newPosition.x = newPosition.x - 1
11 newPosition.y = newPosition.y + 1
12 query = Tile(newPosition):queryAdd(creature)
13 end
14
15 if query == RETURNVALUE_NOERROR or query ~= RETURNVALUE_NOTENOUGHROOM then
16 doRelocate(position, newPosition)
17 end
18
19 local i, tileItem, tileCount = 1, true, tile:getThingCount()
20 while tileItem and i < tileCount do
21 tileItem = tile:getThing(i)
22 if tileItem and tileItem:getUniqueId() ~= item.uid and tileItem:getType():isMovable() then
23 tileItem:remove()
24 else
25 i = i + 1
26 end
27 end
28
29 item:transform(item.itemid - 1)
30 return true
31end
32