Results 1 to 6 of 6

Thread: Counting the number of items?

  1. #1
    Join Date
    Jan 2012
    Posts
    64
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Counting the number of items?

    Code:
    function Count(Item: TInventoryItem): Integer;
    var
      i: Integer;
      N: Integer;
      x: Integer;
      y: Integer;
      Slot: TBox;
    begin
      for i := 1 to 28 do
      begin
        Slot := InvBox(i);
        if FindDTM(Item.ItemDTM, x, y, Slot.X1, Slot.Y1, Slot.X2, Slot.Y2) then
          N := N + 1;
      end;
      Result := N;
    end;
    Will this work/is this relatively time efficient or is there a better way of doing it?

  2. #2
    Join Date
    Nov 2011
    Location
    MA
    Posts
    545
    Mentioned
    3 Post(s)
    Quoted
    10 Post(s)

    Default

    Simba Code:
    (*
    CountItems
    ~~~~~~~~~~

    .. code-block:: pascal

        function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;

    Counts Items in the inventory:

      - ItemType: 'dtm', 'bitmap', 'bitmap mask', 'color'
      - Item: name/value of your dtm/bmp/color/bmpmask.
      - Tol:

            *   'dtm' - [] (dtm's can't have tolerance).
            *   'bmp' - [BMPTol].
            *   'color' - [COLOUR Tol, Colour Count].
            *   'bmpmask' - [BMPTol, ContourTol].

    .. note::

        by WT-Fakawi / Sumilion

    Example:

    .. code-block:: pascal

        numbOfItems := CountItems('dtm', TheDTM, []);

    *)

    function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;
    begin
      GameTab(tab_Inv);
      Result := CountItemsIn('inv', ItemType, Identifier, Tol)
    end;

  3. #3
    Join Date
    Mar 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Personally, I prefer this way =D
    Simba Code:
    function CountInventoryDTM(DTMToCount: Integer): Integer;
    var
      CurrentCount, i, x, y: Integer;
      Sequence: TIntegerArray;
      InventorySlot: TBox;
    begin
      CurrentCount := 0;
      Sequence := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
                  19, 20, 21, 22, 23, 24, 25, 26, 27, 28];
      for i := 0 to 27 do
      begin
        InventorySlot := InvBox(Sequence[i]);
        if FindDTM(DTMToCount, x, y, InventorySlot.X1, InventorySlot.Y1,
                   InventorySlot.X2, InventorySlot.Y2) then
        begin
          CurrentCount := CurrentCount + 1;
        end;
      end;
      Result := CurrentCount;
      writeln(IntToStr(CurrentCount));
      FreeDTM(DTMToCount);
    end;

  4. #4
    Join Date
    Jan 2012
    Posts
    64
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    That really isn't any different from the one I posted except you had different names for the variables and you used an Array of 1 to 28 instead of simply doing an integer.

    I think I'll just try mine first and go with the one tehq posted if it doesn't work.

  5. #5
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by scipio View Post
    I think I'll just try mine first and go with the one tehq posted if it doesn't work.
    Just in case you didn't know, the on tehq posted is in the SRL Include.

  6. #6
    Join Date
    Mar 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by abu_jwka View Post
    Just in case you didn't know, the on tehq posted is in the SRL Include.
    Didn't know that... Sorry (A)
    But I still learned from making that method, took me a good 15 or so minutes to figure it out.

    Thanks, again

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
  •