auto weapon recharge function help
Hey guys im adding my last feature to my addon auto weapon recharge but run into an issue and cant seem to get the "ChargeItemWithSoulGem" function to actually recharge the weaps but is executing past that line. Its likly a formatting issue as that my biggest headache otherwise everything else is working perfectly.
heres some of the code im working with atm and where i believe the problem lies: Code:
function RidinDirty.Recharge() |
Quote:
Based on the Code snipped you provided this will always be nil, wouldnt it? |
Quote:
|
Quote:
So I dont know what you mean with that comment. Also looks like you forgot to define the gemIndex locally. This can cause issues. Also for troubleshooting, just use the function in quesiton (here: ChargeItemWithSoulGem) manually with script lines in chat. That makes it easier to pin point the problem |
Quote:
|
Quote:
Code:
function RidinDirty.GetGems() |
Quote:
(Doesnt differentiate between crown and normal though) Anyhow. Firstly, you again have a global variable leakage with gemId, which is not good practise. Try to always remember to make those variables local. Secondly, if something isnt working, I dont recommend just putting debug messages anywhere. Properly pin point the problem by testing each function in its most simplest way, e.g. with chat script to make sure you use them correctly etc.... |
ExoY is right. Especially about the missing local, leaking global variables.
Hint about scripts testing ingame: MerTorchbug provides a script history and ways to run multiline scripts ingame. Just type /tbs to open it. All /script entries will be added to that history. It's easier to test things ingame that way. |
Quote:
Code:
function RidinDirty.GetGems(slotId) |
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() |
I changed the structure a bit there just messin but my primary issue is the chargeitemwithsoulgem line.. it just wont charge unless i manually enter the weapon slot and gem slot. i cant seem to get the weapon slot and gem slot to pass to make it to that line.
|
I had read that others notified you about that already so here, once again:
Code:
inventoryUpdateReason == 3 Code:
INVENTORY_UPDATE_REASON_DEFAULT = 0 Then search for that type in the same API documentation txt file and you'll see the constants that are available. It's also possible to use merTorchbug ingame and type /tb to show the global inspector, then change to tab "Constants". It provides a search too. |
Quote:
The function ChargeItemWithSoulGem uses the bagId and slotIndex of BAG_WORN that you want to charge, and the bagId and slotIndex of the soulgem in your bags. Lua Code:
Your code should work fine if the function is called properly and the soulgem bagId and slotIndex are correct! I'd check the soulgems tuff to be the correct ones, via debug messages! In your function RidinDirty.Recharge() gemSlot is not known! Ths cannot work. You specify it in your function RidinDirty.GetGems() as local so it's ONLY known inside that function. You should do it like this instead: Pass in the slotId as "gemSlot" to your function RidinDirty.Recharge or define 1 local gemslot at the top of your lua file and then set it at function RidinDirty.GetGems() and use it at RidinDirty.Recharge local variables are only available in their closure, means inside the if ... end or inside the function ... end or inside a for ... do end loop etc. If you want it to be avaialable in all functions of a file you need to define it at the top of the file, outside of all functions etc. Or use it as RidinDirty.gemSlot, added to your global variable! Lua Code:
I personally would NOT combine GetGems and Recharge so they always will be run together. Just run GetGems once before usage, from e.g. function RidinDirty.Recharge, and then recharge the items that you want to. Not the other way around: Call Recharge from GetGems. |
had a quick nap.. thank you bro ill give that stuff a whirl.. ill liklly have issues with the bag_worn,bag part and how to achieve it but ill see what i can figure out.
|
i also did try it this way initially cuz i wanted to be sure it was checking and found a gem for each repair to be sure.. ill restructure it that way again and see.
Code:
function RidinDirty.GetGems() |
ok I readjusted it and and reaplced the 3 with INVENTORY_UPDATE_REASON_ITEM_CHARGE as well.. not gonna use the return true stuff yet as im trying to keep it basic untill i see recharge actually happening. heres the brint of it and if your correct then I just need to work on the "ChargeItemWithSoulGem(BAG_WORN, weapon, BAG_BACKPACK, gemSlot)" line again which is pretty much all ive been doing.
Code:
function RidinDirty.GetGems() |
do you think i can merge the "for _, weapon in ipairs(weapons) do" code into the "if isitemsoulgem...." in the getgems() function? it might work there cuz so far thats the only place I can get the soul gem slotID to actually work.
or merge the getgems code into the recharge function? either way? So like I dont have 2 functions? |
what im seeing right now is the text output after "chargeitemwithsoulgem" for ONLY off_hand, backup_main and backup_off and NOT the MAIN_HAND which is the one that needs charging.. Suggesting its not even trying to charge the main hand but trying all others which are empty slots.. im ok with that for the moment untill i can get MAIN_HAND charging but why not MAIN_HAND?
|
i appreciate all the help but nothing has helped at all and its still doing the exactly the same thing.. recharging everything but main hand that needs it. Ive even resorted to try this and not charging it..
Code:
function RidinDirty.GetGems() |
ok i think i got it and as expected was something soo stupid.. my minimumweaponcharge i set to 97 assuming that was like a % for some reason when weaps have 500max charges.. my main wasnt down that far to be charged!!! omg but the rest of all your help was great and managed to get it all working under getgems... out testing it now in the real world.. thank you guys!
|
You should maybe check, before charging, if the slot you want to charge is actually "slotted".
Lua Code:
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. |
Quote:
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? |
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.
|
missed this but got it added now.. it'll make the next update.
|
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() |
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 10:06 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI