ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Problem with reading guild bank content (https://www.esoui.com/forums/showthread.php?t=4336)

xTG 02/25/15 12:14 PM

Problem with reading guild bank content
 
Hello there,

i'm having issue with reading the guild bank content.
Sometimes it works... Sometimes not... And i don't understand why ! That's make me crazy...

I actually launch my code on two events.
EVENT_GUILD_BANK_SELECTED
This simply set a global variable to get the bankID.
Code:

function LGBE:selectGuildBank(eventCode, guildBankId)
        LGBEStack.guildBankId = guildBankId
        logActionToChat(string.format("Banque de guilde active : (%d) %s", LGBEStack.guildBankId, GetGuildName(LGBEStack.guildBankId)))
end

EVENT_GUILD_BANK_ITEMS_READY
Here is the main point.
In my trace i see the bankID is correct.
But it seems the GetItemName, GetItemType only return something the first time i launch this function...
Code:

function LGBE:update()
        if LGBEStack.debugInfo ~= false then
                logActionToChat("LGBE:update")
        end
        if LGBEStack.exporting ~= true then
                LGBEStack.debugInfo = true
                local bankSlots = GetBagSize(BAG_GUILDBANK)
                local nbItems = 0
                local nbNonStackedSlot = 0

                if LGBEStack.debugInfo ~= false then
                        logActionToChat(string.format("bankSlots=(%d)", bankSlots))
                end
                logActionToChat("LegionGuildBankExtract : Extraction en cours...")
                logActionToChat(string.format("Banque de guilde active : (%d) %s", LGBEStack.guildBankId, GetGuildName(LGBEStack.guildBankId)))
               
                -- réinitialisation des variables sauvegardées
                savedVars['bank'] = {}
               
                --
                -- Boucler sur les slots de la banque
                --
                for bankSlot = 0, bankSlots do
                        local bankItemName = GetItemName(BAG_GUILDBANK, bankSlot)
                        local bankStack,bankMaxStack = GetSlotStackSize(BAG_GUILDBANK, bankSlot)
                        local bankItemType = GetItemType(BAG_GUILDBANK, bankSlot)
                        if bankSlot < 50 then
                                logActionToChat(string.format("Slot %d %s %d %d %d", bankSlot, bankItemName, bankStack, bankMaxStack, bankItemType))
                        end
                        if bankItemName ~= "" then
                                -- Slot non vide, on sauvegarde donc l'information
                                local itemType = GetItemType(BAG_GUILDBANK, bankSlot)
                                if isSavedItem[itemType + 1] ~= false then -- /!\ les types commencent à 0 mais les index d'array à 1
                                        if savedVars['bank'][bankItemName] ~= nil then
                                                -- L'objet a déjà été inséré via une autre pile, on remet juste à jour le nombre
                                                savedVars['bank'][bankItemName]['bankStack'] = savedVars['bank'][bankItemName]['bankStack'] + bankStack
                                                if LGBEStack.debugInfo ~= false then
                                                        logActionToChat(string.format("Slot(%s) %s/%s %s additionnés", bankSlot, bankStack, bankMaxStack, bankItemName))
                                                end
                                                if bankStack < bankMaxStack and savedVars['bank'][bankItemName]['bankStack'] < bankMaxStack then
                                                        nbNonStackedSlot = nbNonStackedSlot + 1
                                                end
                                        else
                                                local tmpArray = {}
                                                tmpArray['bankSlot'] = bankSlot
                                                tmpArray['bankStack'] = bankStack
                                                tmpArray['bankItemName'] = bankItemName
                                                savedVars['bank'][bankItemName] = tmpArray
                                                if LGBEStack.debugInfo ~= false then
                                                        logActionToChat(string.format("Slot(%s) %s %s ajoutés", bankSlot, bankStack, bankItemName))
                                                end
                                        end
                                        nbItems = nbItems + 1
                                end
                        end
                end
                logActionToChat(string.format("LegionGuildBankExtract : Fin [%d objets extraits][%d piles séparées]", nbItems, nbNonStackedSlot))
                -- Mise a jour de la banque sauvegardée pour ne pas exécuter le script plusieurs fois
                if nbItems ~= 0 then
                        LGBEStack.lastGuildBankIdExport = LGBEStack.guildBankId
                end
                LGBEStack.debugInfo = false
        else
                if LGBEStack.debugInfo ~= false then
                        logActionToChat("Export deja en cours")
                end
        end
end

If i try to launch this function on the second or third guild bank it returns 0 items and i can see the 50 first slots empty. Which are not...

Anyone have a clue about this ? What i am doing wrong ? :confused:

Best Regards.

Ayantir 02/25/15 01:35 PM

Coucou / Hello,

First, when EVENT_GUILD_BANK_SELECTED triggers, you don't have item list, this one can never be available (especially on large banks),

For guild banks, EVENT_GUILD_BANK_ITEMS_READY triggers generally 3-4 times (depends on bank). you should make a flag to do not run your code multiple times. (add a little flag & delay).


Lua Code:
  1. local bankSlots = GetBagSize(BAG_GUILDBANK)
  2.         for bankSlot = 0, bankSlots do
  3.             local bankItemName = GetItemName(BAG_GUILDBANK, bankSlot)

Is not correct

If slots are well ordered in bags, for banks et especially guild banks, the slots can be very different (consider always).

If you want to iterate bank, I recommend you :

Lua Code:
  1. local myguildbank = ZO_GuildBankBackpack.data
  2.  
  3.     for index, slot in ipairs(myguildbank) do
  4.        
  5.         -- slot.data.slotIndex is the real slotindex
  6.         GetItemName(BAG_GUILDBANK, slot.data.slotIndex)
  7.        
  8.         -- some stuff
  9.        
  10.     end

You can look at my updated roomba code if needed, I always comment a lot.
https://www.dropbox.com/s/bmy3c7rtx0...stice.zip?dl=0

Garkin 02/25/15 05:02 PM

SHARED_INVENTORY does not work for you? In my opinion it is better way then using ZO_GuildBankBackpack.data.

You have to select guild bank first:
Lua Code:
  1. SelectGuildBank(guildId)

And then you can get cached guild bank items:
Lua Code:
  1. local bankCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_GUILDBANK)

Item name is already in there, so you don't need to call GetItemName again.

Lua Code:
  1. for slotIndex, slotData in pairs(bankCache) do --using pairs instead of ipairs, because there could be missing slotIndexes (empty slots)
  2.     d(slotData.rawName) --raw name: "rice mash"
  3.     d(slotData.name)  --formated name: "Rice Mash"
  4.     d(slotData.nameWithQuantity) --formated name with quantity: "Rice Mash (60)"
  5. end

xTG 02/26/15 01:35 AM

Thanks for the infos.

@Ayantir
About EVENT_GUILD_BANK_SELECTED i'm aware of it, i just use it to get the GuildID.
I will get a test with the code you propose. :)

@Garkin
Thanks, i will look about this !

xTG 02/28/15 10:57 AM

It seems to work now, have some to debug but it works now on second and third guild bank !


All times are GMT -6. The time now is 04:14 PM.

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