have you ever wanted an item to never leave players house?
now its possible!
^ improved code for table items original file has only 1 item
now its possible!
LUA:
local echangables = EventCallback
-- Define item IDs in a table
local itemIds = {
hangableLightId = 8580,
anotherItemId = 8581, -- Add more item IDs as needed
yetAnotherItemId = 8582,
}
local dustbinId = 1777
-- Function to check if the position is within a house
local function isHouseTile(pos)
local tile = Tile(pos)
return tile and tile:getHouse() ~= nil
end
-- Function to check if there is a dustbin at the position
local function isDustbinAtPosition(pos)
local tile = Tile(pos)
if tile then
local items = tile:getItems()
for _, item in ipairs(items) do
if item:getId() == dustbinId then
return true
end
end
end
return false
end
-- Event callback for item movement
echangables.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
-- Check if the item being moved is in the itemIds table
for _, itemId in pairs(itemIds) do
if item:getId() == itemId then
-- If moving the item to a container (backpack, etc.), allow the move
if toPosition.x == CONTAINER_POSITION then
return true
end
-- If the item is being moved to a position that is not part of a house or is not on top of a dustbin
if not isHouseTile(toPosition) and not isDustbinAtPosition(toPosition) then
-- If the player is attempting to move it, send a message and block the move
local player = self:getPlayer()
if player then
doSendAnimatedText("Impossible", player:getPosition(), 127)
end
return false
end
end
end
-- Allow the move to proceed
return true
end
echangables:register()
^ improved code for table items original file has only 1 item