ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   auto weapon recharge function help (https://www.esoui.com/forums/showthread.php?t=10466)

Baertram 02/27/23 03:44 AM

You should maybe check, before charging, if the slot you want to charge is actually "slotted".
Lua Code:
  1. if HasItemInSlot(BAG_WORN, slotId) then

And doing the recharge in the GetGems function does not make sense, but it's your code and addon.
I'd rename that to TryRecharge instead as it will recharg in the end, and not get the soulgem info ;-)

And as these kind of addons often heppn to get you disconnected due to death
https://www.esoui.com/forums/showthread.php?t=10464
I'd check if the player is dead more than once here before calling the charge API function!
Once before your GetGems func is called and once before ChargeItemWithSoulGem is executed then maybe, until this ZOs bug is fixed.

sinnereso 02/27/23 04:14 AM

Quote:

Originally Posted by Baertram (Post 47295)
You should maybe check, before charging, if the slot you want to charge is actually "slotted".
Lua Code:
  1. if HasItemInSlot(BAG_WORN, slotId) then

And doing the recharge in the GetGems function does not make sense, but it's your code and addon.
I'd rename that to TryRecharge instead as it will recharg in the end, and not get the soulgem info ;-)

And as these kind of addons often heppn to get you disconnected due to death
https://www.esoui.com/forums/showthread.php?t=10464
I'd check if the player is dead more than once here before calling the charge API function!
Once before your GetGems func is called and once before ChargeItemWithSoulGem is executed then maybe, until this ZOs bug is fixed.

Ya death was a bit of a concern but i left it at once because im only running it on using charges so it will only fire once i think without a repeating loop during death. if thats still a risk of disconnect ill add more checks.

re: the actually slotted weap comment... i believe I am with the isitemchargeable which is in live version. It was commented out for testing purposes. I assume an empty slot isnt chargeable?

Baertram 02/27/23 04:30 AM

Could be, or it throws an error or it will behave undefined :p So better do the check before, if there is an easy way like this, so it's not even trying to charge that slot.

sinnereso 02/27/23 02:07 PM

missed this but got it added now.. it'll make the next update.

sinnereso 03/07/23 02:00 PM

SO... its working great but im noticing its trying to charge twice.. 1st time recharges and 2nd kicks back a "item is already fully charged in top right of screen. In testing with msgs it is applying a recharge twice but no matter what I do I cant get it not to.. any suggestions? Its my last bug I can find in my addon. This is wearing a 2h lightning staff oaken build as well if it matters.

Ive been studying and trying diff ways using ipair/ipairs and indexing etc which is where i feel in my gut the issue is but no changes.

Also additional question for the pros.. do or can the "for slotId........." and the "for _, weapon ipairs........" be local? Or they good as is? Ive localized everything in my addon except those types of functions.

Code:

function xxx.Initialize()
        if autoRechargeToggle == "enabled" then
                EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, xxx.GetGemsAndRecharge)
        end
end

function xxx.GetGemsAndRecharge(_, bagId, _, _, _, inventoryUpdateReason)
        if bagId ~= BAG_WORN then return end
        if inventoryUpdateReason == INVENTORY_UPDATE_REASON_ITEM_CHARGE and not IsUnitDead("player") then
                local minimumWeaponCharge = 50 -- <<<<<<<  0-500 charges
                local weapons = {
                        EQUIP_SLOT_MAIN_HAND,
                        EQUIP_SLOT_OFF_HAND,
                        EQUIP_SLOT_BACKUP_MAIN,
                        EQUIP_SLOT_BACKUP_OFF
                }
                for slotId = 0, GetBagSize(BAG_BACKPACK) do
                        local gemSlot = slotId
                        if IsItemSoulGem(SOUL_GEM_TYPE_FILLED, BAG_BACKPACK, gemSlot) then
                                for _, weapon in ipairs(weapons) do
                                        local charge, maxCharge = GetChargeInfoForItem(BAG_WORN, weapon)
                                        if charge <= minimumWeaponCharge and HasItemInSlot(BAG_WORN, weapon) and maxCharge ~= 0 and not IsUnitDead("player") then
                                                PlaySound(SOUNDS.INVENTORY_ITEM_APPLY_CHARGE)
                                                ChargeItemWithSoulGem(BAG_WORN, weapon, BAG_BACKPACK, gemSlot)

                                        end
                                end
                        end
                end
        else
                return
        end
end


sinnereso 03/08/23 03:57 AM

OK got it fixed... I had to seperate the get gems function and call to it as previously suggested so it wasn't trying to recharge for each stack of gems i had on me.


All times are GMT -6. The time now is 09:55 AM.

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