Results 1 to 10 of 10

Thread: Inventory Sorter

  1. #1
    Join Date
    Apr 2016
    Location
    New Zealand
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    32 Post(s)

    Default Inventory Sorter

    Wanted to make something move gems to the bottom of the inventory for my Powerminer, this is what I came up with.

    Also uses recursion, which took a while to wrap my head around.



    Simba Code:
    program InventorySorting;

    {$DEFINE SMART}
    {$i Aerolib/Aerolib.simba}
    {$i Reflection/Reflection.simba}

    {
      Inventory Sorting
      Author: Dissimulo (https://villavu.com/forum/member.php?u=160877)
      Last Update: 23/05/2016
      Version: 2.0
      Category: Utility
      Description: Moves Items to the bottom of the backpack
      Includes: Reflection and AeroLib
      Features:
        - Aerolib (https://villavu.com/forum/showthread.php?t=108953)
        - Reflection (https://villavu.com/forum/showthread.php?t=111662)
        - Simple SMART paint
      Versions:
        - 2.0 (22/05/2016)
          Reworked functions into Color and Reflection
          Rewrote functions (thanks to Turpinator and Le Jingle
          Using proper wrappers for Reflection (thanks Harrier)
        - 1.0 (22/05/2016)
          Cleaned up for public release
      Credits:
        - Flight (Aerolib)
        - Kyle (Lape Reflection)
    }


    var
      MyGuy: TReflectLocalPlayer;

    function InventorySorterColor: Boolean;
    var
      i, j: Integer;
    begin
      for i := 28 downto 1 do
        if (not itemInSlot(i)) then
        begin
          for j := 1 to i do
            if (itemInSlot(j)) then
            begin
              dragMouseBox(invBox(j), invBox(i));
              wait(RandomRange(400, 550));
              Break;
            end;
        end;
      Result := not isInvFull;
    end;

    function InventorySorterReflect: Boolean;
    var
      i, j: Integer;
    begin
      if Reflect.Gametab.Current <> 55 then
        Reflect.Gametab.Open(55);
      for i := 28 downto 1 do
        if (not Reflect.Inv.ItemInSlot(i)) then
        begin
          for j := 1 to i do
            if (Reflect.Inv.ItemInSlot(j)) then
            begin
              dragMouseBox(Reflect.Inv.InvBox(j), Reflect.Inv.InvBox(i));
              wait(RandomRange(400, 550));
              Break;
            end;
        end;
      Result := not Reflect.Inv.IsFull;
    end;

    begin
      initAL();
      Reflect.Setup;
      MyGuy.Username := 'USERNAME';
      MyGuy.Password := 'PASSWORD';
      MyGuy.Active := True;
      MyGuy.Login;
      wait(RandomRange(1000, 1550));
      if not InventorySorterReflect then
        Writeln('Inventory full');
    end.
    Last edited by Dissimulo; 05-23-2016 at 09:43 AM.

  2. #2
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.
    I didn't even know you could do that lol

  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by rj View Post
    I didn't even know you could do that lol
    You can't if it access anything from it's self (self.something) but you shouldn't really be doing it in the Lape that Simba has, also if you turn assertions on {$assertions on} it will error on compile.

  5. #5
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Quote Originally Posted by Olly View Post
    You can't if it access anything from it's self (self.something) but you shouldn't really be doing it in the Lape that Simba has, also if you turn assertions on {$assertions on} it will error on compile.
    With the current lape version in simba it wont error on compile, but it should during run time.
    [14:09:15] <niels> newer lape version should catch it at compile tie
    [14:09:17] <niels> time*
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  6. #6
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    I feel like the use of recursion is excessive and unneeded.
    Simba Code:
    Procedure InvSort();
    begin
      for i := 1 to 28 do
        if isiteminslot(i) then
          for j := 28 downto 1 do
          begin
            if i = j then
              exit();
            if not isiteminslot(j) then
            begin
              moveitemtoslot(i, j);
              break();
            end;
          end;
    end;

    Something as simple as this should work, i think.

  7. #7
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    With the current lape version in simba it wont error on compile, but it should during run time.
    [14:09:15] <niels> newer lape version should catch it at compile tie
    [14:09:17] <niels> time*
    That's why I said in the Lape version Simba has, the newer Lape has real support for static methods (which is what this is). But that's nice to know this mistake cant happen in the future.

  8. #8
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    well done OP @ learning

    also my input: (not test)

    Code:
    procedure InvyItemMover();
    var i, j: Integer;
    begin
      for i := 28 downto 1 do
        if (not TReflectionInventory.ItemInSlot(i)) then
          for j := 1 to i do
            if (TReflectionInventory.ItemInSlot(j)) then
              dragMouseBox(TReflectionInventory.InvBox(j), TReflectionInventory.InvBox(i));
    end;

  9. #9
    Join Date
    Apr 2016
    Location
    New Zealand
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    32 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.
    I see what meant when I asked on IRC, thanks for the heads up.


    Quote Originally Posted by Turpinator View Post
    I feel like the use of recursion is excessive and unneeded.
    Simba Code:
    snip

    Something as simple as this should work, i think.
    Quote Originally Posted by Le Jingle View Post
    well done OP @ learning

    also my input: (not test)

    Code:
    snip
    After looking at these 2 examples, I get why you say that Turp. I've been trying to learn about more intermediate programming concepts, and while thinking about how to write this function, recursion just popped into my head.



    I've also rewritten the snippet, as well as added a color only version (didn't know Aerolib was so versatile).

  10. #10
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Am I being as blind as a bat as well as a dumb as a donkey? Where's the recursion in this? Looks like I was late to the party?

    Cool function. Looks like you learned a fair bit. Now you just need it to work on gems only (and potentially swap them with ore rather than having to drop the ore first?)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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