Results 1 to 7 of 7

Thread: [Aerolib Snippet] GetBlackCountAll

  1. #1
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default [Aerolib Snippet] GetBlackCountAll

    Hi all,

    Created this to learn a bit about arrays and for..to..do.

    Let me know what you think and improvements i could make on it!

    Simba Code:
    {*
    GetBlackCountAll
    ~~~~~~~~~~~~

    .. code-block:: AeroLib

        GetBlackCountAll(MyArray: TIntegerArray; Count: Integer): Integer;

    Checks the nominated TIntegerArray and reports back with the amount of black pixels found, storing it in an integer.

    .. note::

        by Dan the man

    Example:

        //Counts how many items in the inventory have 68 black pixels in them and saves it to an integer.
        BlackitemCount := (GetBlackCountAll(TItem.getslots(), 68));

    *}

    function GetBlackCountAll(MyArray: TIntegerArray; Count: Integer): Integer;
    var
      i: integer;
      ItemCount: integer;
      TempBox: Tbox;
      BlackPixelCol: TColEx;

    begin
      BlackPixelCol.create(65536, 0);
      ItemCount := 0;
      Setlength(MyArray, 28);
      for i := Low(MyArray) to High(MyArray) do
        if ((MyArray[i]) > 0) then
        begin
          TempBox := (InvBox(MyArray[i]));
          if (BlackPixelCol.count(TempBox) = Count) then
            Inc(ItemCount);
        end;
      Result := ItemCount;
    end;


    @Flight

  2. #2
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Looks nice, but what practical uses does this have?

  3. #3
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by kristi View Post
    Looks nice, but what practical uses does this have?
    Could use it to count specific items in inventory.

  4. #4
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by tls View Post
    Could use it to count specific items in inventory.
    We have such a function in AL, which returns the count of a TItem. If it's stackable the result will be of the stack amount, if not the number of the TItem will be counted. Works for both bank and inventory.
    Simba Code:
    function TItem.getAmount(ExcludeBank: Boolean): Integer;

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  5. #5
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Quote Originally Posted by kristi View Post
    Looks nice, but what practical uses does this have?
    It is used to count the quantity of items in your inventory that are otherwise hard to determine via DTM (like Strung/unstrung bows). It counts the pixel count of each unit, checks if it matches the required pixel count, and then adds to the count if true.


    Quote Originally Posted by Flight View Post
    We have such a function in AL, which returns the count of a TItem. If it's stackable the result will be of the stack amount, if not the number of the TItem will be counted. Works for both bank and inventory.
    Simba Code:
    function TItem.getAmount(ExcludeBank: Boolean): Integer;
    I use the TItem.getAmount a lot, but some items are very difficult to be identified by it due to the use of a DTM. The one that spawned this snippet was Strung/Unstrung bows. A unstrung bow gets identified as a strung bow, and can only really be differentiated by the black pixel count.

    There may be a better method to differentiate them, but I haven't been able to track one down

  6. #6
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    You could shorten it a bit with something like

    Simba Code:
    function GetBlackCountAll(MyArray: TIntegerArray; Count: Integer): Integer;
    var
      i: Integer;
    begin
      for i := 0 to High(MyArray) do
        if CountColor(65536, InvBox(MyArray[i]).x1, InvBox(MyArray[i]).y1, InvBox(MyArray[i]).x2, InvBox(MyArray[i]).y2) = Count then
          Inc(result);
    end;

  7. #7
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Quote Originally Posted by The Simba Noob View Post
    You could shorten it a bit with something like

    Simba Code:
    function GetBlackCountAll(MyArray: TIntegerArray; Count: Integer): Integer;
    var
      i: Integer;
    begin
      for i := 0 to High(MyArray) do
        if CountColor(65536, InvBox(MyArray[i]).x1, InvBox(MyArray[i]).y1, InvBox(MyArray[i]).x2, InvBox(MyArray[i]).y2) = Count then
          Inc(result);
    end;
    Oo i like that.

    When I made this, I actually didn't know CountColor was a thing in lape lol. Thought it was part of the SRL include xD

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
  •