Hello, Otland,
Recently I have found an issue with my server that I had to query all houses for a specific item. Sadly, it was pretty much impossible to do that through the SQL query. So I have developed a simple talkaction which can help you found a specific item by an item id. The script search in every house tile for an item and it doesn't matter if it is hidden in the backpack or somewhere else because it will find it.
data\talkactions\scripts\query_houses.lua
data\lib\core\container.lua (put this in the end of the file)
Type /queryhouses 3082 to query by an item id.
Recently I have found an issue with my server that I had to query all houses for a specific item. Sadly, it was pretty much impossible to do that through the SQL query. So I have developed a simple talkaction which can help you found a specific item by an item id. The script search in every house tile for an item and it doesn't matter if it is hidden in the backpack or somewhere else because it will find it.
data\talkactions\scripts\query_houses.lua
Lua:
function onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end
local searchItemId = tonumber(param)
for _, house in pairs(Game.getHouses()) do
for _, tile in pairs(house:getTiles()) do
for _, item in pairs(tile:getItems()) do
if item ~= nil then
local isFound = false
if item:isContainer() then
local items = item:getItemsById(searchItemId)
isFound = #items > 0
else
isFound = item:getId() == searchItemId
end
if isFound then
local position = item:getPosition()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Item position is: " .. position.x .. ", " .. position.y .. ", " .. position.z .. ".")
end
end
end
end
end
return false
end
XML:
<talkaction words="/queryhouses" separator=" " script="query_houses.lua" />
Lua:
function Container.getItemsById(self, itemId)
local list = {}
for index = 0, (self:getSize() - 1) do
local item = self:getItem(index)
if item then
if item:isContainer() then
local rlist = item:getItemsById(itemId)
if type(rlist) == 'table' then
for _, v in pairs(rlist) do
table.insert(list, v)
end
end
else
if item:getId() == itemId then
table.insert(list, item)
end
end
end
end
return list
end
Type /queryhouses 3082 to query by an item id.