Thread Tools Display Modes
01/08/15, 03:42 AM   #1
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
Collectible_item_type_trophy ??

I thought I had posted this before but I didn't see it show up?

I am writing an addon that will need to scan the users backpack and get back the name and index of the trophy (and then eventually) it will do the same with costumes.

This is the code - it works - but it just gives me (what looks like) the first 20 items in the backpack.

What am I missing here - I know it's got to be something simple.

Lua Code:
  1. function RandomTrophy.trophies()
  2.  
  3.     local backpackItem
  4.     local backpackSlots = GetBagSize and GetBagSize(bag) or select(2, GetBagInfo(bag))
  5.    
  6.     for i=1, backpackSlots do
  7.         backpackItem = GetItemLink(BAG_BACKPACK, i, LINK_ITEM_TYPE)
  8.         if string.match(backpackItem, COLLECTIBLE_ITEM_TYPE_TROPHY) then
  9.             d(i)
  10.             d(backpackItem)
  11.         end
  12.     end
  13.    
  14. end

Any help greatly appreciated !

Thanks,

-d
  Reply With Quote
01/08/15, 07:53 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
  • Lua Code:
    1. local backpackSlots = GetBagSize and GetBagSize(bag) or select(2, GetBagInfo(bag))
    Is no longer needed. It was compatibility function to make addon work with both API 100007 and 100008 (because of PTS). Just use:
    Lua Code:
    1. local backpackSlots = GetBagSize(bag)
  • Lua Code:
    1. for i=1, backpackSlots do
    Inventory slots are the only index value in ESO which starts with zero. So the correct code is:
    Lua Code:
    1. for i = 0, backpackSlots - 1 do
  • Lua Code:
    1. backpackItem = GetItemLink(BAG_BACKPACK, i, LINK_ITEM_TYPE)
    I have no idea how you have defined LINK_ITEM_TYPE, but you should use LINK_STYLE_DEFAULT or LINK_STYLE_BRACKETS.
    Lua Code:
    1. backpackItem = GetItemLink(BAG_BACKPACK, i, LINK_STYLE_BRACKETS)
  • Lua Code:
    1. if string.match(backpackItem, COLLECTIBLE_ITEM_TYPE_TROPHY) then
    Global constant COLLECTIBLE_ITEM_TYPE_TROPHY is not what you are looking for. Value of COLLECTIBLE_ITEM_TYPE_TROPHY is number 2, so your function returns all itemlinks which contains number 2.
    You should use item type instead, something like:
    Lua Code:
    1. if GetItemLinkItemType(backpackItem) == ITEMTYPE_TROPHY then --if you want collectibles, use ITEMTYPE_COLLECTIBLE

Anyway, try this code:
Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BACKPACK)
  2. for slotIndex, slotData in pairs(bagCache) do
  3.     if slotData.itemType == ITEMTYPE_TROPHY then
  4.        d(zo_strformat("<<1>> (<<2>>)", slotData.name, slotIndex))
  5.     end
  6. end

Last edited by Garkin : 01/08/15 at 08:30 AM.
  Reply With Quote
01/08/15, 08:22 AM   #3
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
u really are the best

Thank you Garkin,

That was incredibly helpful!

I am now getting the information I need.



As always thank you for not only giving me the answer but helping me to understand why.

-d

Last edited by dopiate : 01/09/15 at 04:08 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Collectible_item_type_trophy ??


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