Log in

View Full Version : Improved Items Mover ( multi items )



kamilqq
03-25-2016, 09:30 PM
Hello, now ive just had a need to make better item mover, so i'd like to share with community :)

I did not made optional backpack where pots firstly are because usually people want to sort items after magic shop. So thats why it sorting from first backpack( usually main ).

Also you don't have to loop this function:
reason of looping such function is that when you move item, the next indexes are lowered by 1 and for loop just goes ahead.
There is no such problem cause this is recursive function so if it will move item its looping itself.

I hope You enjoy :)



toSort = {
{id = Item.GetID('mana potion'), bp = 'brocade backpack'},
{id = Item.GetID('health potion'), bp = 'demon backpack'}
}
function moveItems(table)
local fromBP = Container.GetFirst()
for spot, item in fromBP:iItems() do
for _, data in pairs(table) do
if item.id == data.id then
local toBP = Container.New(data.bp)
fromBP:MoveItemToContainer(spot, toBP:Index(), 0)
wait(Self.Ping() + 100, Self.Ping() + 300)
return moveItems(table)
end
end
end
end
Module.New('ImprovedItemMover', function(this)
moveItems(toSort)
this:Stop()
end)

Mvm1
03-27-2016, 01:37 PM
Awesome man! Thanks for sharing it.

Works 100%

kamilqq
03-27-2016, 04:18 PM
Awesome man! Thanks for sharing it.

Works 100%

Thanks :)

maroxy
03-27-2016, 08:56 PM
return moveItems(table)

Why?

kamilqq
03-27-2016, 09:05 PM
return moveItems(table)

Why?

Read my post once more, it's recursive function. Read about that. I said about index changing in function.
If bot took one item, the rest items are index - 1, so it missing some items. Now when i did recursive function, ill give u definition:
You move one item > rest item indexes are -1 so next item is ignored, when i did recursive function the function is executed once more from 0. So its looping from 0 ( after one item moved ) until no item is moved.

maroxy
03-28-2016, 10:23 AM
Read my post once more, it's recursive function. Read about that. I said about index changing in function.
If bot took one item, the rest items are index - 1, so it missing some items. Now when i did recursive function, ill give u definition:
You move one item > rest item indexes are -1 so next item is ignored, when i did recursive function the function is executed once more from 0. So its looping from 0 ( after one item moved ) until no item is moved.

That makes sense.

Anyways if you are thinking of that use just a "break", cause you are executing function over function and maybe it can cause a memory leak. (Not sure about this :p)

kamilqq
03-28-2016, 12:25 PM
That makes sense.

Anyways if you are thinking of that use just a "break", cause you are executing function over function and maybe it can cause a memory leak. (Not sure about this :p)

Read about functions. ( im not aggressive saying that :D )
Explain :
1. return statement is breaking loop. Here it breaks the function and executes once more itself(if moved any item).
2. it only return new loop ( self ) if found and moved item. So if it will not find any item then it wont loop itself.
Also the module there is just useless ( better to just execute function at label or something like that ), i used here Module to show how it works.

maroxy
03-28-2016, 03:44 PM
Read about functions. ( im not aggressive saying that :D )
Explain :
1. return statement is breaking loop. Here it breaks the function and executes once more itself(if moved any item).
2. it only return new loop ( self ) if found and moved item. So if it will not find any item then it wont loop itself.
Also the module there is just useless ( better to just execute function at label or something like that ), i used here Module to show how it works.

You are right!

Keep the good work.

Jontor
03-28-2016, 10:02 PM
You might want to add a delay to the code

kamilqq
03-28-2016, 10:13 PM
You might want to add a delay to the code



Also the module there is just useless ( better to just execute function at label or something like that ), i used here Module to show how it works.

Read it.

Jontor
03-28-2016, 10:18 PM
Read it.

Message me if you learn how to code

kamilqq
03-28-2016, 10:22 PM
Message me if you learn how to code

what's wrong then?
Why it should have delays? ( after moving an item? about 100 - 300 ms ? I dont really need that, not lagging me or anything like that or its not ignoring items, but its published and if some1 need the delay he can just add a line so i can't really see the problem. :)

Jontor
03-29-2016, 09:59 AM
what's wrong then?
Why it should have delays? ( after moving an item? about 100 - 300 ms ? I dont really need that, not lagging me or anything like that or its not ignoring items, but its published and if some1 need the delay he can just add a line so i can't really see the problem. :)

Make a while (true) do loop, it won't be any different from your code
You're simply spamming Tibia with packets that you wish to move the item, but there's a cooldown anyways

kamilqq
03-29-2016, 10:11 AM
Make a while (true) do loop, it won't be any different from your code
You're simply spamming Tibia with packets that you wish to move the item, but there's a cooldown anyways

I don't care how people will use this code, the module was just added to make it work if some1 copy-pasted that.
Also i can't see point of looping that like module/while true do, cause i would only use it on magic shop. So for me the looping that is useless so as i said people will use how they need to.

yoyoa1
03-29-2016, 02:24 PM
I don't care how people will use this code, the module was just added to make it work if some1 copy-pasted that.
Also i can't see point of looping that like module/while true do, cause i would only use it on magic shop. So for me the looping that is useless so as i said people will use how they need to.

I just pasted and maked a .lua with it. Working great but is this the right way to use it?

You guys are saying about loop, spamming Tibia with packets... Are these things detectable or something like that?

Jontor
03-29-2016, 02:38 PM
I just pasted and maked a .lua with it. Working great but is this the right way to use it?

You guys are saying about loop, spamming Tibia with packets... Are these things detectable or something like that?

What I tried to point out is that the script is trying to move items too fast
While its doing great job, imo it's a bit risky without any waits

kamilqq
03-29-2016, 06:51 PM
What I tried to point out is that the script is trying to move items too fast
While its doing great job, imo it's a bit risky without any waits

You are 100% right. Im not playing rl tibia so im not paying attention on such things. When im home ill make it more Human like.

yamucha
04-24-2016, 02:22 PM
its dsn't loop...?

have to refresh script every time i refill ...

ShanMaron
04-26-2016, 03:39 PM
Hello, now ive just had a need to make better item mover, so i'd like to share with community :)

I did not made optional backpack where pots firstly are because usually people want to sort items after magic shop. So thats why it sorting from first backpack( usually main ).

Also you don't have to loop this function:
reason of looping such function is that when you move item, the next indexes are lowered by 1 and for loop just goes ahead.
There is no such problem cause this is recursive function so if it will move item its looping itself.

I hope You enjoy :)



toSort = {
{id = Item.GetID('mana potion'), bp = 'brocade backpack'},
{id = Item.GetID('health potion'), bp = 'demon backpack'}
}
function moveItems(table)
local fromBP = Container.GetFirst()
for spot, item in fromBP:iItems() do
for _, data in pairs(table) do
if item.id == data.id then
local toBP = Container.New(data.bp)
fromBP:MoveItemToContainer(spot, toBP:Index(), 0)
wait(Self.Ping() + 100, Self.Ping() + 300)
return moveItems(table)
end
end
end
end
Module.New('ImprovedItemMover', function(this)
moveItems(toSort)
this:Stop()
end)

Anyway Possible to change this for item ID. A lot of open tibia servers have custom names.

Help on this would be awesome. I'm sure its an easy edit.

kamilqq
04-26-2016, 06:05 PM
Anyway Possible to change this for item ID. A lot of open tibia servers have custom names.

Help on this would be awesome. I'm sure its an easy edit.

{id = Item.GetID('mana potion'), bp = 'brocade backpack'}, INSTEAD OF THAT LINE USE THIS :
{id = 50252, bp = 'yourbp'}.

lol :D

ShanMaron
05-11-2016, 08:35 PM
{id = Item.GetID('mana potion'), bp = 'brocade backpack'}, INSTEAD OF THAT LINE USE THIS :
{id = 50252, bp = 'yourbp'}.

lol :D


Works great. Up until the point I move any of the listed items, after that the script will not continue to move items.

kamilqq
05-11-2016, 08:58 PM
Works great. Up until the point I move any of the listed items, after that the script will not continue to move items.

Don't really understand, If You have moved manually item then bot didn't move any?
Also thanks for feedback :)

mrok89
11-09-2016, 04:42 PM
It doesn't work for me. How to make that script will move items from my depot I to my backpacks? I opened my backpack, and depot with my loot, it' didn't move.

Chiitus
11-21-2016, 06:06 PM
It doesn't work for me. How to make that script will move items from my depot I to my backpacks? I opened my backpack, and depot with my loot, it' didn't move.

Attention in "container get first".

@TOPIC:
I didn't know the trick about indexes getting -1 after item move, thanks for the tip!