XenoBot Forums - Powered by vBulletin

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Improved Items Mover ( multi items )

  1. #1

    Join Date
    Jan 2014
    Posts
    183
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Improved Items Mover ( multi items )

    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

    PHP Code:
     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 
    spotitem in fromBP:iItems() do
            for 
    _data in pairs(table) do
                if 
    item.id == data.id then
                    local toBP 
    Container.New(data.bp)
                    
    fromBP:MoveItemToContainer(spottoBP:Index(), 0)
                         
    wait(Self.Ping() + 100Self.Ping() + 300)
                    return 
    moveItems(table)
                
    end
            end
        end
    end
    Module
    .New('ImprovedItemMover', function(this)
        
    moveItems(toSort)
        
    this:Stop()
        
    end
    Last edited by kamilqq; 03-29-2016 at 08:24 PM. Reason: update

  2. #2

    Join Date
    Jul 2013
    Posts
    46
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Awesome man! Thanks for sharing it.

    Works 100%

  3. #3

    Join Date
    Jan 2014
    Posts
    183
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mvm1 View Post
    Awesome man! Thanks for sharing it.

    Works 100%
    Thanks

  4. #4
    Senior Member maroxy's Avatar
    Join Date
    Apr 2014
    Location
    EUW
    Posts
    897
    Mentioned
    137 Post(s)
    Tagged
    0 Thread(s)
    lua code:
    return moveItems(table)


    Why?


    Remember that the official XenoBot page is www.xenobot.net not xeno-bot.net or similar

  5. #5

    Join Date
    Jan 2014
    Posts
    183
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maroxy View Post
    lua code:
    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.
    Last edited by kamilqq; 03-28-2016 at 06:38 AM.

  6. #6
    Senior Member maroxy's Avatar
    Join Date
    Apr 2014
    Location
    EUW
    Posts
    897
    Mentioned
    137 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kamilqq View Post
    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 )


    Remember that the official XenoBot page is www.xenobot.net not xeno-bot.net or similar

  7. #7

    Join Date
    Jan 2014
    Posts
    183
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maroxy View Post
    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 )
    Read about functions. ( im not aggressive saying that )
    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.

  8. #8
    Senior Member maroxy's Avatar
    Join Date
    Apr 2014
    Location
    EUW
    Posts
    897
    Mentioned
    137 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kamilqq View Post
    Read about functions. ( im not aggressive saying that )
    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.


    Remember that the official XenoBot page is www.xenobot.net not xeno-bot.net or similar

  9. #9
    Senior Member Jontor's Avatar
    Join Date
    Sep 2014
    Posts
    446
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    You might want to add a delay to the code

  10. #10

    Join Date
    Jan 2014
    Posts
    183
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jontor View Post
    You might want to add a delay to the code
    Quote Originally Posted by kamilqq View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •