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