09/16/15, 11:31 PM | #1 | |
Join Date: Sep 2015
Posts: 6
|
move item from bag to bank
Hi!
I a new to this forum here, i hope i got the right tread to ask a question. I am from Germany so sorry for any wrong English sentences/words. I wanna make some Addons for TESO. On the first hand to get better in coding on the other hand to have some to fit my needs. I learn java at university and I am new to lua. I tried to move an item from the bagpack to the bank but it do not work. I used the "my first addon" help out of the wiki from esoui. And looked into other persons code. But still not working. I want to move all items of a special kind to the bank, for example all food. I also wanted to use the "y" key function to stack if you can use it. ATM i do not find that function. Hope someone can give me an example or some tipps. Also some webseites with more tutorials or code explanation would be helpful. AT my programming its always a little problem /wrong thinking that stops all. >.<""! My code atm: move 1 item and then crash game >.< function FooAddon.OnOpenBank(eventcode) for num = 1, GetBagSize(1), 1 do firstFreeSlot = FindFirstEmptySlotInBag(2) icon, istack, sellPrice, meetsUsageRequirement, locked, equipType, itemStyle, quality = GetItemInfo(1, num) if 0 ~= GetNumBagFreeSlots(2) then if IsProtectedFunction("RequestMoveItem") then CallSecureProtected("RequestMoveItem", 1, num, 2, firstFreeSlot, istack) else RequestMoveItem(1, num, 2, firstFreeSlot, istack) end end end end Last edited by Motokosworld : 09/17/15 at 01:23 AM. |
|
09/17/15, 01:27 AM | #2 |
Hello and welcome to EsoUI, Motokosworld!
You found the right place for asking this kind of question. What you want to do can be broken down into four parts: 1, Offer a way to trigger your function 2. Detect when you are at a bank 3. Find all instances of the item in your inventory and move them to the bank 4. Use the 'y' stack function to stack them I will offer you a basic example that you can use as a starting point. ad 1) There are many ways how this can happen. You can offer a chat command, automatically trigger it whenever the user visits a bank, add a keybind or show some GUI elements that can be clicked. The first two are comparatively simple while the others require quite some code, so we will stick to a chat command for now. Lua Code:
ad 2) This is necessary because you cannot access BAG_BANK unless you are at a banker and chose the bank dialog. For now we will add a function to prevent DumpItemsToBank from doing anything while we are not at a bank. Lua Code:
ad 3) Now we get to the interesting part. First we have to iterate over all our items and test if they are of the type we want to dump. You mentioned that you want to move all food to bank, so we stick to that for now. You already found the necessary methods so everything we need to do is combine it like this: Lua Code:
GetFirstFreeValidSlotForItem seems to work on the same bag only as it requires a slotIndex to specify an item. FindFirstEmptySlotInBag(integer Bag bagId) is more likely to do what we want so we will try it. We also need to get the stack size in order to move the correct amount. This can be done with GetSlotStackSize(integer bagId, integer slotIndex). Once we have the slot we can move request to move it there with the function you already have found. Lua Code:
ad 4) All that is left now is to find out how the key bind to stack items is working. For this we need to have a look at the UI source code which can be found here. The bank is simply another inventory so we take a look at ingame/inventory/inventory.lua and by looking for the keyword "stack" we find StackBag(BAG_BANK). So after we put everything together in DumpItemsToBank we arrive at: Lua Code:
This is completely untested so it might not work right away, but it should give you a general idea how it can be done. EDIT: Just saw that you updated your post. Instead of adding a chat command you can just call MyAddon.DumpItemsToBank() from your event handler too and of course it will be necessary to check if the bank has enough space left before trying to move the item. EDIT2: corrected code in response to votan Last edited by sirinsidiator : 09/17/15 at 02:59 AM. |
|
09/17/15, 01:49 AM | #3 | |
Join Date: Sep 2015
Posts: 6
|
Thank you very much for your answer!
I will work now with the things you wrote and will write later how far i came with it! |
|
09/17/15, 01:56 AM | #4 |
slot-indexes are (the only) zero-based indexes.
Lua Code:
Und Willkommen, Motokosworld. |
|
09/17/15, 02:30 AM | #5 | |
Join Date: Sep 2015
Posts: 6
|
Thx votan for your advice. About that i was also thinking, because out of java i know that everything start at 0 and then max-1 so i correct that now.
The problem is, it work 1 time if i open the bank and then again if i open the bank again. SO i think the loop do not work, but why? If i try out some thinks like quote out the if that i only move food, it works once and then if i talk to the banker the second time my game crash. Maybe there is a problem with that function(RequestMoveItem) or the inventory do not update correctly? i will try out... My code now much more clean and nice written code with a lot of comments^^, some are still from the tutorial, but i leave them there to learn the functions of all the lua code parts: Lua Code:
Last edited by Motokosworld : 09/17/15 at 03:00 AM. |
|
09/17/15, 02:57 AM | #6 | |
If you want it to run again while you are still at the bank you need to provide a different way to trigger the function. |
||
09/17/15, 08:23 AM | #7 | |
Join Date: Sep 2015
Posts: 6
|
But I wrote a loop around that all, why it do not go through the loop? Normaly a loop means go through it until you checked all values inside the loop...
Or do I only need to write the loop into another subfunction? Last edited by Motokosworld : 09/17/15 at 08:36 AM. |
|
09/17/15, 08:57 AM | #8 |
|
Because items are not moved immediately, the actual transfer is done later, not from Lua code. GetNumBagFreeSlots, FindFirstEmptySlotInBag will keep returning the same value during the whole frame. We've had the exact same issue some time ago http://www.esoui.com/forums/showthre...EmptySlotInBag
|
09/17/15, 09:58 AM | #9 |
Oh. I didn't know that. I have never used these functions myself to move items around but it sounds reasonable. I guess you could listen to EVENT_INVENTORY_SINGLE_SLOT_UPDATE and wait until the move happened before doing the next one.
Just make sure to only register to it when you start the movement process and unregister again afterwards, because there are already some performance problems with that event. |
|
09/17/15, 10:14 AM | #10 | |
Join Date: Sep 2015
Posts: 6
|
So if i understand it correctly you move the item in imaging and if all your addon on progresses are run through the moving task will be sent to server and then the server will do it?
A bit difficult to understand, but i think its some of the problems you have with addons, because its not real coding. But implementing in an already running progress. Now i rewrote a lot of my code, but my game freeze. I looked through the link you gave me and made these changes because of that. But i guess ther is still something wrong. So i will post my code here and also will work later or tomorrow on it. I know that i can still improve a lot on my code, but i want at first a really working programm after that i optimize it. I use Notepad++ maybe you have another codeeditor where i an jump to functions? And test for code errors. ATM i only test at teso. So i am happy for some hints where the problem is. Lua Code:
Last edited by Motokosworld : 09/17/15 at 10:33 AM. |
|
09/17/15, 10:58 AM | #11 | |
|
|
|
09/17/15, 11:21 AM | #12 |
|
You have a couple typos in that code.
slotinBag ~= GetBagSize(BAG_BACKPACK) -- always true => freeze GetItemType(bagId, slotIndex) -- undefined vars Also don't make the function findEmptySlotInBag global. Define it local before use, or place it in your namespace. |
09/17/15, 04:34 PM | #13 | |
Join Date: Sep 2015
Posts: 6
|
I do not now how to make the change you wrote.
if i write local in front of the function the other do not find it. I corrected the 2 wrong variables. Now its working! THX!!!!!!! my code look now like this: Lua Code:
Last edited by Motokosworld : 09/17/15 at 04:41 PM. |
|
09/17/15, 04:40 PM | #14 |
|
If it's local, it must be defined (lexically) before use, i.e. move the definition above BankService.moveMyItems. Or make it BankService.findEmptySlotInBag. Global namespace is shared among all ZOS and add-on code, it's best to put as few things in there as possible.
Btw you're skipping slots with findEmptySlotInBag(BAG_BANK, emptyIndex+1, ...); drop the +1, it's added in the function. Last edited by merlight : 09/17/15 at 04:44 PM. |
09/18/15, 05:45 AM | #15 |
Or just take a peek in http://www.esoui.com/downloads/info4...nkStacker.html which does most of the stuff you want allready
|
|
ESOUI » Developer Discussions » Lua/XML Help » move item from bag to bank |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|