everything looks like it should be working but I dont see how you could run complex functions on a /script. Heres everything related as it is at this moment.. ill leave it this way and give up later if i cant get it working. im getting a headache.
Code:
function RidinDirty.PlayerActivated()
if autoRechargeToggle == "enabled" then
EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, RidinDirty.InventoryUpdate)
end
end
-- Auto recharge weapons with soulgems
function RidinDirty.InventoryUpdate(eventCode, bagId, slotId, isNewItem, itemSoundCategory, inventoryUpdateReason, stackCountChange)
if bagId ~= BAG_WORN then return end
if inventoryUpdateReason == 3 and not IsUnitDead(PLAYER) then
RidinDirty.GetGems()
end
end
function RidinDirty.GetGems()
for slotId = 0, GetBagSize(BAG_BACKPACK) do
if IsItemSoulGem(SOUL_GEM_TYPE_FILLED, BAG_BACKPACK, slotId) then
local gemSlot = slotId
RidinDirty.Recharge()
end
end
end
function RidinDirty.Recharge()
local minimumWeaponCharge = 97
local weapons = {
EQUIP_SLOT_MAIN_HAND,
EQUIP_SLOT_OFF_HAND,
EQUIP_SLOT_BACKUP_MAIN,
EQUIP_SLOT_BACKUP_OFF
}
for _, weapon in ipairs(weapons) do
df("found weapon %s", weapon)
local charge, maxCharge = GetChargeInfoForItem(BAG_WORN, weapon)
if charge <= minimumWeaponCharge then --and IsItemChargeable(BAG_WORN, weapon) then --and not maxCharge == 0 then
ChargeItemWithSoulGem(BAG_WORN, weapon, BAG_BACKPACK, gemSlot)
end
local charged, maxCharged = GetChargeInfoForItem(BAG_WORN, weapon)
if charged > charge then
df("should have been charged")
end
end
end
function RidinDirty.RechargeToggle()
local autoRechargeToggle = RidinDirty.savedVariables.autoRecharge
if autoRechargeToggle == nil or autoRechargeToggle == "" or autoRechargeToggle == "disabled" then
autoRechargeToggle = "enabled"
RidinDirty.savedVariables.autoRecharge = autoRechargeToggle
EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, RidinDirty.InventoryUpdate)
df("|c9900FF[RidinDirty]|r Auto Recharge: %s", autoRechargeToggle)
else
autoRechargeToggle = "disabled"
RidinDirty.savedVariables.autoRecharge = autoRechargeToggle
EVENT_MANAGER:UnregisterForEvent("RidinDirty", EVENT_INVENTORY_SINGLE_SLOT_UPDATE)
df("|c9900FF[RidinDirty]|r Auto Recharge: %s", autoRechargeToggle)
end
end
SLASH_COMMANDS["/ridindirty_recharge"] = RidinDirty.RechargeToggle