From a53e79d62886017aa595c42f8fe96389ad174778 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Tue, 31 Mar 2020 12:30:50 +0300 Subject: [PATCH] introduce talkaction to query house tile items by id --- data/lib/core/container.lua | 22 +++++++++++++++ data/talkactions/scripts/query_houses.lua | 34 +++++++++++++++++++++++ data/talkactions/talkactions.xml | 1 + 3 files changed, 57 insertions(+) create mode 100644 data/talkactions/scripts/query_houses.lua diff --git a/data/lib/core/container.lua b/data/lib/core/container.lua index 1898732..84e3ea1 100644 --- a/data/lib/core/container.lua +++ b/data/lib/core/container.lua @@ -25,3 +25,25 @@ end function Container.isTile(self) return false end + +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 \ No newline at end of file diff --git a/data/talkactions/scripts/query_houses.lua b/data/talkactions/scripts/query_houses.lua new file mode 100644 index 0000000..13de481 --- /dev/null +++ b/data/talkactions/scripts/query_houses.lua @@ -0,0 +1,34 @@ +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, "Your current position is: " .. position.x .. ", " .. position.y .. ", " .. position.z .. ".") + end + end + end + end + end + + return false +end \ No newline at end of file diff --git a/data/talkactions/talkactions.xml b/data/talkactions/talkactions.xml index ea39625..4dd0bd1 100644 --- a/data/talkactions/talkactions.xml +++ b/data/talkactions/talkactions.xml @@ -41,6 +41,7 @@ +