Thread Tools Display Modes
06/22/15, 08:34 AM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Item exists in inventory or bank best practice

Hello, I was wondering if there is a best practice or efficient way to check the existence of an item in someone's bank or in their inventory bag. I haven't done this before. I would have the item link for the item I'm looking for, I'm just not sure how to check for existence.
  Reply With Quote
06/22/15, 09:39 AM   #2
ahmetertem
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 7
I can't tell "best practice" but any function will do same thing in background. Will reach to bag, bank etc and search item in your conditions...

Code:
local bagId = BAG_BACKPACK
-- check: http://wiki.esoui.com/Constant_Values#BAG_BACKPACK
local bagSlots = GetBagSize(bagId) -1
for slotIndex = 0, bagSlots do
    local itemType = GetItemType(bagId, slotIndex)
    local link = GetItemLink(bagId, slotId)
    local itemID = select(4,ZO_LinkHandler_ParseLink(link))
    if itemID == xxxx and itemType == blabla then
    -- code goes here
    end
end
Sorry for bad English, but basically any function will do this in background like i said.

Regards
  Reply With Quote
06/22/15, 10:50 AM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Great, thank you!

Originally Posted by ahmetertem View Post
I can't tell "best practice" but any function will do same thing in background. Will reach to bag, bank etc and search item in your conditions...

Code:
local bagId = BAG_BACKPACK
-- check: http://wiki.esoui.com/Constant_Values#BAG_BACKPACK
local bagSlots = GetBagSize(bagId) -1
for slotIndex = 0, bagSlots do
    local itemType = GetItemType(bagId, slotIndex)
    local link = GetItemLink(bagId, slotId)
    local itemID = select(4,ZO_LinkHandler_ParseLink(link))
    if itemID == xxxx and itemType == blabla then
    -- code goes here
    end
end
Sorry for bad English, but basically any function will do this in background like i said.

Regards
  Reply With Quote
06/22/15, 11:29 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Please avoid

Lua Code:
  1. local bagSlots = GetBagSize(bagId) -1
  2. for slotIndex = 0, bagSlots do
  3.     local itemType = GetItemType(bagId, slotIndex)

to itarate bags.

Use :

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BACKPACK)
  2. for slotId, data in pairs(bagCache) do

instead.

1st, the first snipped don't really work work Guild Bank.
2nd, sometimes , it don't work neither in bag. (even it's more rare).

And most of all, please consider that slotIndex is data.slotIndex and not in the key.
  Reply With Quote
06/22/15, 11:44 AM   #5
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Excellent! Thanks for the information. I will work on this this evening. I really appreciate it.

Originally Posted by Ayantir View Post
Please avoid

Lua Code:
  1. local bagSlots = GetBagSize(bagId) -1
  2. for slotIndex = 0, bagSlots do
  3.     local itemType = GetItemType(bagId, slotIndex)

to itarate bags.

Use :

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BACKPACK)
  2. for slotId, data in pairs(bagCache) do

instead.

1st, the first snipped don't really work work Guild Bank.
2nd, sometimes , it don't work neither in bag. (even it's more rare).

And most of all, please consider that slotIndex is data.slotIndex and not in the key.
  Reply With Quote
06/22/15, 01:06 PM   #6
ahmetertem
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 7
Originally Posted by Ayantir View Post
Please avoid

Lua Code:
  1. local bagSlots = GetBagSize(bagId) -1
  2. for slotIndex = 0, bagSlots do
  3.     local itemType = GetItemType(bagId, slotIndex)

to itarate bags.

Use :

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BACKPACK)
  2. for slotId, data in pairs(bagCache) do

instead.

1st, the first snipped don't really work work Guild Bank.
2nd, sometimes , it don't work neither in bag. (even it's more rare).

And most of all, please consider that slotIndex is data.slotIndex and not in the key.

Great informations. Thank you very much explanation as well.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Item exists in inventory or bank best practice


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off