Thread Tools Display Modes
04/15/14, 06:12 PM   #1
Mitsarugi
 
Mitsarugi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 23
How to know if player has an item in his bag?

I'm trying to make a function for TreasureMaps that let's me check if the player has the item (treasuremap) in his bag so that i can display that Treasuremap's location on the map.
but i need help as i don't know how to do this...
It would also be nice to know once the item gets consumed (upon finding the Treasure itt gets deleted from inventory )
  Reply With Quote
04/15/14, 08:21 PM   #2
Zerorez
 
Zerorez's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 7
something like this possibly?

Code:
function DoesPlayerHaveItem(itemName)
    for slotIndex=1, GetMaxBags() do
        local itemInSlot = GetItemName(bagId, slotIndex)
        if itemInSlot == itemName then
            return true
        end
    end
end
I guess bagId would point to the id for player inventory (BAG_BACKPACK constant maybe)? Not entirely sure but it should be a start at least.
  Reply With Quote
04/16/14, 04:46 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
I'm not really sure what GetMaxBags() does, but it will probably return number of bags, not numbers of slots in bag. I think you can use (I didn't test it in game):
lua Code:
  1. local _, numSlots = GetBagInfo(BAG_BACKPACK)
or
lua Code:
  1. local numSlots = ZO_InventoryManager:GetNumSlots(INVENTORY_BACKPACK)
or
lua Code:
  1. local numSlots =  PLAYER_INVENTORY.inventories[INVENTORY_BACKPACK].numSlots

Last edited by Garkin : 04/16/14 at 06:09 AM.
  Reply With Quote
04/16/14, 06:16 AM   #4
Vicster0
 
Vicster0's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 82
Garkin is correct. GetMaxBags() returns the number of bags, i.e. BankBag and InventoryBag.
  Reply With Quote
04/16/14, 12:14 PM   #5
Zerorez
 
Zerorez's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 7
Ah, yeah I was not too sure about that myself without logging in.
  Reply With Quote
04/17/14, 12:41 PM   #6
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
To find when it's consumed, you need to register an event for inventory changes. Store the (bag,slot) of the Treasure Map, and when that location is set to "", it's been removed. Hint: the bag is BAG_BACKPACK, and happens to be set to 1. It will also be removed when dropping it in the bank or deleting it.

Last edited by Vuelhering : 04/19/14 at 11:51 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How to know if player has an item in his bag?

Thread Tools
Display Modes

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