Your code works, but has some problems. You need to check if there is another player in the door, move items, etc. Check the closingdoor.lua from the TFS repo:
Lua:
function onStepOut(creature, item, position, fromPosition)
local tile = Tile(position)
if tile:getCreatureCount() > 0 then
return true
end
local newPosition = {x = position.x + 1, y = position.y, z = position.z}
local query = Tile(newPosition):queryAdd(creature)
if query ~= RETURNVALUE_NOERROR or query == RETURNVALUE_NOTENOUGHROOM then
newPosition.x = newPosition.x - 1
newPosition.y = newPosition.y + 1
query = Tile(newPosition):queryAdd(creature)
end
if query == RETURNVALUE_NOERROR or query ~= RETURNVALUE_NOTENOUGHROOM then
doRelocate(position, newPosition)
end
local i, tileItem, tileCount = 1, true, tile:getThingCount()
while tileItem and i < tileCount do
tileItem = tile:getThing(i)
if tileItem and tileItem:getUniqueId() ~= item.uid and tileItem:getType():isMovable() then
tileItem:remove()
else
i = i + 1
end
end
item:transform(item.itemid - 1)
return true
end
This should work with StepOut using your open door id, the only difference would be the line "item:transform(item.itemid - 1)", replacing with your custom closed door id, supposing that its not the open door id - 1 (if it is, just use the original then).