I was writing a bot which goes to my guild hall and collects crafting mats at night. so I run into the problem that the mats I harvest have different names and ids according to the level of the building. In the german client this are f.e. "Unbekanntes Erz I", "Unbekanntes Erz II", "Unbekanntes Erz VIII" etc.
I dont know all the ids and dont want to edit my file again after every levelup of the buildings. I also dont want to go through a list of ids using findItem (). so I added the following function to the inventory class, which based on the original CInventory:findItem ()
Code: Select all
function CInventory:findItems (pattern, range)
local first, last, location = getInventoryRange (range) -- get bag slot range
if location ~= "inventory" and location ~= nil then
printf ("You can only use inventory ranges with 'inventory:findItems'. You cannot use '%s' which is in %s\n", range, location)
end
if first == nil then
first, last = 1, 240 -- default, search all
end
local itemList = {}
local item
for slot = first, last do
item = self.BagSlot[slot]
item:update ()
if item.Available and (not item.InUse) and string.find (item.Name, pattern) then
if (os.clock () - item.LastMovedTime) > ITEM_REUSE_DELAY then
table.insert (itemList, item)
end
end
end
return (#itemList>0 and itemList or nil)
end
Code: Select all
local listOfItems = inventory:findItems ("^Unbekanntes Erz [IVX]$")
any ideas would be fine
greetings
Celesteria