Thread Tools Display Modes
02/27/23, 03:44 AM   #21
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,979
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.

Last edited by Baertram : 02/27/23 at 03:46 AM.
  Reply With Quote
02/27/23, 04:14 AM   #22
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
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?
  Reply With Quote
02/27/23, 04:30 AM   #23
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,979
Could be, or it throws an error or it will behave undefined So better do the check before, if there is an easy way like this, so it's not even trying to charge that slot.
  Reply With Quote
02/27/23, 02:07 PM   #24
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
missed this but got it added now.. it'll make the next update.
  Reply With Quote
03/07/23, 02:00 PM   #25
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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

Last edited by sinnereso : 03/08/23 at 03:51 AM.
  Reply With Quote
03/08/23, 03:57 AM   #26
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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.

Last edited by sinnereso : 03/08/23 at 08:43 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » auto weapon recharge function help


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