ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   How to know if player has an item in his bag? (https://www.esoui.com/forums/showthread.php?t=938)

Mitsarugi 04/15/14 06:12 PM

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 )

Zerorez 04/15/14 08:21 PM

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.

Garkin 04/16/14 04:46 AM

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

Vicster0 04/16/14 06:16 AM

Garkin is correct. GetMaxBags() returns the number of bags, i.e. BankBag and InventoryBag.

Zerorez 04/16/14 12:14 PM

Ah, yeah I was not too sure about that myself without logging in.

Vuelhering 04/17/14 12:41 PM

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.


All times are GMT -6. The time now is 09:44 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI