introduce talkaction to query house tile items by id

This commit is contained in:
ErikasKontenis 2020-03-31 12:30:50 +03:00
parent 693a9120ee
commit a53e79d628
3 changed files with 57 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -41,6 +41,7 @@
<talkaction words="/globalboost" separator=" " script="global_rate_boost.lua" />
<talkaction words="/loottest" script="loot_test.lua" />
<talkaction words="/event" script="serpentine_tower_event.lua" />
<talkaction words="/queryhouses" separator=" " script="query_houses.lua" />
<!-- player talkactions -->
<talkaction words="!buypremium" script="buyprem.lua"/>