• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TalkAction [TFS 1.x] Search House Items By ID

Erikas Kontenis

Board Moderator
Staff member
Board Moderator
Joined
Jul 3, 2009
Messages
1,863
Reaction score
564
Location
Lithuania
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
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" />
data\lib\core\container.lua (put this in the end of the file)
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
1586174580897.png
Type /queryhouses 3082 to query by an item id.
 
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
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" />
data\lib\core\container.lua (put this in the end of the file)
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
View attachment 43851
Type /queryhouses 3082 to query by an item id.

Very nice thx!
 
Back
Top