Results 1 to 11 of 11

Thread: Amount.scar -- GetAmount

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default Amount.scar -- GetAmount

    I put one of each rune in my inventory to test some MSI functions, and GetAmount is returning that there's 11 of a lot of runes. I've tested the DTMs individually, so that's not the problem.

    I looked at GetAmount, and I think it would work better if it was based of inventory slots rather than item coordinates. It uses the coords as a 'mainpoint' to figure out where the text is. I think it would be more accurate if this 'mainpoint' was in the center of the inventory slot, no?

    Make sense?

    Also, the reason I'm posting this is because I don't have time to do this for the next few days. If someone is up for the challenge, be my guest.

    Cheers,
    Coh3n

  2. #2
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    I might have a minute tomorrow to test that theory. I'm just concerned as to how that would handle the situation of having a large number of items in the slot next to the one your looking at.

  3. #3
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    well, I don't like that idea, cause it would stop it being used for the bank, however a fix would be a good idea...

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  4. #4
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Bad Boy JH View Post
    well, I don't like that idea, cause it would stop it being used for the bank, however a fix would be a good idea...
    It can always be edited to work with the bank... and deposit box for that matter.

  5. #5
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    as long as it remains so it can do that, I have no issue...
    it was poorly phrased...

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  6. #6
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    If this does end up working (I'll know soon) then it would be pretty simple to see what interface is open (ie BankScreen, DepositScreen, or just Inv), and just store the TBox to a var so it could work either way.

  7. #7
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    1. Get pixel coords of rune
    2. Find out which inventory slot (via TBoxes) the rune is in
    3. use center coords ((box.x2-box.x1), (box.y2-box.y2)) as a reference point to get text
    4. OCR text
    5. Result := ...

    just an idea :P

  8. #8
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by TomTuff View Post
    1. Get pixel coords of rune
    2. Find out which inventory slot (via TBoxes) the rune is in
    3. use center coords ((box.x2-box.x1), (box.y2-box.y2)) as a reference point to get text
    4. OCR text
    5. Result := ...

    just an idea :P
    That's just a more specific way of what I meant.

  9. #9
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Alright, I think I have this working pretty well. I even added a little part it that will get the exact number of the item if greater than 100k. I'd like a few people to test with different numbers before I commit, just to be sure. In the image below, the red box is just the inventory slot, and the yellow box is where it searches for the text. You can test with this script:
    Simba Code:
    program new;
    {$i srl/srl/misc/smart.scar}
    {$i srl/srl.scar}
    {$i srl/srl/misc/PaintSmart.scar}

    function tGetAmount(Area: string; Slot: Integer): Integer;
    var
      textCols: TIntegerArray;
      x, y, i: Integer;
      b, bounds: TBox;
      TPA: TPointArray;
      s: String;
    begin
      case Lowercase(Area) of
        'inv': b := InvBox(Slot);
        'bank': b := BankIndexToMSBox(Slot);
        'deposit box', 'dbox': b := DepositItemBox(Slot);
        else
          srl_Warn('GetAmount', 'Invalid GetAmount area ', warn_AllVersions);
      end;

      // If no item is found in the specified slot
      if (not FindColor(x, y, SRL_OUTLINE_BLACK, b.x1, b.y1, b.x2, b.y2)) then
      begin
        srl_Warn('GetAmount', 'Item doesn''t exist in '+Capitalize(Area)+' slot '+IntToStr(Slot)+' ', warn_AllVersions);
        Exit;
      end;

      Inc(Result);
      textCols := [65535, 65278, 16777215, 8453888];

      SMART_DrawBoxEx(False, b, clRed);

      // Loop through all the possible text colors until one is found
      for i := 0 to High(textCols) do
        if (FindColor(x, y, textCols[i], b.x1, b.y1, b.x2, b.y2)) then
        begin
          FindColors(TPA, textCols[i], b.x1, b.y1, b.x2, b.y2);
          bounds := GetTPABounds(TPA);
          bounds := IntToBox(bounds.x1-2, bounds.y1-2, bounds.x2+2, bounds.y2+2);
          SMART_DrawBoxEx(False, bounds, clYellow);

          s := GetTextAtExWrap(bounds.x1, bounds.y1, bounds.x2, bounds.y2, 0, 1, 1, textCols[i], 0, StatChars);

          Result := StrToIntDef(GetNumbers(s), 1);

          // If greater than 100k, examine it to get the exact number
          if ((i = 2) or (i = 3)) then
          begin
            MouseBox(b.x1, b.y1, b.x2, b.y2, 2);
            if (WaitOption('xamine', 500)) then
              Result := StrToInt(GetNumbers(GetChatBoxText(8, clBlack)));
          end;

          Exit;
       end;
    end;

    var
      i: Integer;
    begin
      Smart_Server := 152;
      Smart_Members := False;
      Smart_Signed := True;
      Smart_SuperDetail := False;

      SetupSRL;
      ClearDebug;
      SmartSetDebug(True);
      ActivateClient;
      SMART_DrawBoxEx(True, IntToBox(0, 0, 0, 0), clRed); // Clears the canvas

      for i := 1 to 15 do
        Writeln(IntToStr(tGetAmount('bank', i)));

      //Writeln(GetNumbers(GetChatBoxText(8, clBlack)));
    end.
    Inventory:


    Bank:


    Deposit Box:
    Haven't tested yet.

    E: Oh, I forgot to mention that it did printed out all the right amounts.

    E2: I've found that occasionally it won't get the right number after it right clicks an item and reads the chat text for whatever reason. Something may be wrong with that function, or GetAmount can just give an approximate result if the calculated result is less than 100k.
    Last edited by Coh3n; 11-16-2010 at 08:22 AM.

  10. #10
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Turns out the original wasn't as hard to fix as I though. Committed a fixed version. The one that I wrote above hasn't been committed. I may use it in MSI, we'll have to see.

  11. #11
    Join Date
    Sep 2006
    Location
    Texas
    Posts
    1,349
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol silly coh3n.

    my turn to post a bug!

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
  •