Results 1 to 10 of 10

Thread: Improved / fixed inventory functions

  1. #1
    Join Date
    May 2007
    Posts
    527
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default Improved / fixed inventory functions

    Hi,

    I suggest to replace current InvBox and ExistsItem -functions with below I've written. The current ones are over-complicated and doesn't even work. For instance, if you have coal bag in your inventory, current ExistsItem returns false.

    Simba Code:
    function InvBox(s: integer): TBox;
    begin
        if not InRange(s, 1, 28) then begin
            result := IntToBox(-1, -1, -1, -1);

            srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);
       
            exit;
        end;  

        Dec(s);

        with result do begin
            x1 := 559 + (s and 3) * 42;
            y1 := 210 + (s shr 2) * 36;
            x2 := x1 + 40;
            y2 := y1 + 34;
        end;
    end;

    function ExistsItem(s: integer): boolean;
    var
        b: TBox;
    begin
        GameTab(tab_Inv);

        b := InvBox(s);
        result := (CountColor(srl_outline_black, b.x1, b.y1, b.x2, b.y2) > 0);
    end;

  2. #2
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
    Shoudln't that be:
    Simba Code:
    srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);

    Also FindColor should be quicker than CountColor so I think the old ExistsItem Works Better, if I missed something let me know

    Your Boxes are slightly different to the current ones (yours are white):

    But I think yours are as good if not better, I agree your code is a lot neater
    Last edited by putonajonny; 06-09-2012 at 12:14 PM.

  3. #3
    Join Date
    May 2007
    Posts
    527
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    Simba Code:
    srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
    Shoudln't that be:
    Simba Code:
    srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);
    Yes, it should!

  4. #4
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by superuser View Post
    Yes, it should!
    Also see my edit

  5. #5
    Join Date
    May 2007
    Posts
    527
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    Also see my edit
    Then there must be something wrong with FindColor, since it doesn't work at least with coal bag Also, the old InvBox is cropping the actual boundaries, mine does not.

  6. #6
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by superuser View Post
    Then there must be something wrong with FindColor, since it doesn't work at least with coal bag Also, the old InvBox is cropping the actual boundaries, mine does not.
    Yeah, I think your InvBox is definitely better

  7. #7
    Join Date
    May 2007
    Posts
    527
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Gonna be implemented?

  8. #8
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I did some changes, some OCD some actually practical, just for you to consider:
    Simba Code:
    function InvBox(Slot : integer): TBox;
    begin

        if not InRange(Slot, 1, 28) then
          begin
            result := IntToBox(-1, -1, -1, -1);
            srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(Slot), warn_AllVersions);
            exit;
          end;

        Dec(Slot);

        with result do
          begin
            x1 := 559 + (Slot and 3) * 42;
            y1 := 210 + (Slot shr 2) * 36;
            x2 := x1 + 40;
            y2 := y1 + 34;
          end;
    end;

    function ExistsItem(Slot : integer): boolean;
    var
      B : TBox;
    begin
      if(GetCurrentTab <> tab_Inv)then
        begin
          GameTab(tab_Inv);
          Wait(500+Random(500));
        end;
      B := InvBox(Slot);
      result := (CountColor(srl_outline_black, B.x1, B.y1, B.x2, B.y2) > 0);
    end;

  9. #9
    Join Date
    May 2007
    Posts
    527
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    I did some changes, some OCD some actually practical, just for you to consider:

    Simba Code:
    function ExistsItem(Slot : integer): boolean;

      ...

      if(GetCurrentTab <> tab_Inv)then
        begin
          GameTab(tab_Inv);
          Wait(500+Random(500));
        end;
     
       ...
    end;
    Completely unnecessary. As in gametab.simba:

    Simba Code:
    function GameTab(Tab: Integer): Boolean;
       ...

       Result := (GetCurrentTab = Tab);
       if (Result) then exit

    Also,

    Simba Code:
    Wait(500+Random(500));

    Is unnecessary, as there's dynamic wait in gametab.simba as well:

    Simba Code:
    function GameTab(Tab: Integer): Boolean;
       ...

            Result := (GetCurrentTab = Tab);
            Wait(100 + Random(100))

    As I said in OP, no need to overcomplicate things. My suggestions are perfect just as they are

  10. #10
    Join Date
    Jun 2012
    Location
    THE Students-City of Holland
    Posts
    332
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    sorry to interrupt, but how do you make that colored border around something? I need that to make my bot better (Is it a function inside the client or simba?)

    and does it have to do something with TBoxes?

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
  •