Results 1 to 7 of 7

Thread: InvCountStack

  1. #1
    Join Date
    Aug 2008
    Location
    Canada
    Posts
    67
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Post InvCountStack

    I have been having some problems with the ItemAmount function.
    So I have decided to make a function that will get the amount of
    an item in the inventory.

    The Function(s)...
    Code:
    program TS_InvCountStack;
    {.include srl\srl.scar}
    
    function TS_FindColorsMultiTolerances(var Points: TPointArray; Colors, Tolerances: TIntegerArray; X1, Y1, X2, Y2: Integer): Boolean;
    var
      I: Integer;
      A: TPointArray;
    begin
      for I := 0 to High(Colors) do
        if FindColorsTolerance(A, Colors[I], X1, Y1, X2, Y2, Tolerances[Min(I, High(Tolerances))]) then
          Points := CombineTPA(Points, A);
        Result := Length(Points) > 0;
    end;
    
    function TS_FindColorsMulti(var Points: TPointArray; Colors: TIntegerArray; X1, Y1, X2, Y2: Integer): Boolean;
    begin
      Result := TS_FindColorsMultiTolerances(Points, Colors, [0], X1, Y1, X2, Y2);
    end;
    
    function TS_InvCountStack(var Stack: Integer; Slot: Integer): Boolean;
    var
      P, T, M: TPointArray;
      I: TPoint;
      D: T2DPointArray;
      N: TStringArray;
      C, L, H: Integer;
    begin
      try
        if not GameTab(tab_Inv) and not BankScreen then
          Exit;
        if (Slot < 1) or (Slot > 28) then
          Exit;
        if not ExistsItem(Slot) then
          Exit;
        I := ItemCoords(Slot);
        if not TS_FindColorsMulti(P, [65535, 16777215, 8453888], I.X - 20, I.Y - 20, I.X + 20, I.Y) then
          Exit;
        D := FindGapsTPA(P, 0);
        if Length(D) = 0 then
          Exit;
        N := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'K', 'M'];
        for C := 0 to High(D) do
          for L := 0 to High(N) do
          begin
            T := LoadTextTPA(N[L], StatChars, H);
            if FindTextTPAinTPA(H, T, D[C], M) then
              if L < 10 then
                Stack := Stack * 10 + StrToInt(N[L])
              else
                Stack := Stack * Round(Pow(1000, L - 9));
          end;
        if Length(IntToStr(Stack)) < Length(D) then
          Exit;
        Result := True;
      finally
        case True of
          not (GetCurrentTab = tab_Inv) and not BankScreen:
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> Unable to open inventory tab.');
          (Slot < 1) or (Slot > 28):
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> Invalid slot number.');
          not ExistsItem(Slot):
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> No item in specified slot.');
          Length(P) = 0:
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> Item is not stackable.');
          Length(D) = 0:
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> Unable to find numbers.');
          Length(IntToStr(Stack)) < Length(D):
            WriteLn('Error: function TS_InvCountStack(Slot: Integer): Integer; -> Unable to count the stack.');
        end;
      end;
    end;
    
    var
      Stack: Integer;
    
    begin
      SetupSRL;
      if TS_InvCountStack(Stack, 1) then
        WriteLn(Stack)
      else
        WriteLn('Boo!');
    end.
    All of my current testing has been accurate, but I am unable to
    test the function with values greater then 10M (not enough cash).

    If someone could please test my function with a few amounts greater
    than 10M and report back the result, I would greatly appreciate it.

    Also, feel free to comment.

    Thanks,
    The_Scripts
    Last edited by The_Scripts; 10-09-2009 at 05:30 PM.

  2. #2
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Well I'm guessing the ItemAmount function is probably slightly off in Finding the text of the Item(s) in question. It probably just needs a tweak.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  3. #3
    Join Date
    Aug 2008
    Location
    Canada
    Posts
    67
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Im sure I could of tweaked it a bit. but I was bored and wanted to make a function from scratch

  4. #4
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    SCAR Code:
    Function HowManyAlchs:Integer;
    Begin
      Disguise('Counting Nature Runes')
      NatureMask := BitmapFromString(29, 3, 'beNpjYMAK/sMAA25AjBpStZBhJ' +
           'rJGMs0EALHBMs4=');
      If FindBitmapMaskTolerance(NatureMask,x,y,MiX1,MiY1,MiX2,MiY2,3,3) Then
      Begin
       Players[CurrentPlayer].Integers[1]:=ItemAmount('inv','bmpmask',NatureMask,[3,3]);
       Writeln('Can cast ' + IntToStr( Players[CurrentPlayer].Integers[1]) + ' times');
       Result:=Players[CurrentPlayer].Integers[1];
      End Else
      Begin
        Status('Cant Count Natures');
        Logout;
        Players[CurrentPlayer].Loc:='Cant Count';
      End;
    End;

    ItemAmmount using BitmapMask is working just fine for me.

  5. #5
    Join Date
    Aug 2008
    Location
    Canada
    Posts
    67
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    @YoHoJo: Perhaps I just don't know hot to use the ItemAmount function properly.
    I need to get the stack size of many different items, so making bitmaps would not
    be the best solution. How could I get the stack size of anytype of item using the
    ItemAmount function?

  6. #6
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Make bitmap masks, they are tiny and work just fine. See:
    SCAR Code:
    NatureMask := BitmapFromString(29, 3, 'beNpjYMAK/sMAA25AjBpStZBhJ' +
           'rJGMs0EALHBMs4=');
    Do something like

    SCAR Code:
    For i:=0 to 20 Do
      If FindBitmapMaskTolerance(Item[i],x,y,MiX1,MiY1,MiX2,MiY2,3,3) Then
      Begin
        Ammount[i]:=ItemAmount('inv','bmpmask',Item[i],[3,3]);

    something of that sort...
    Or just make DTMs for them all or something.

  7. #7
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Why not just use GetAmount?

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
  •