PDA

View Full Version : [Aerolib Snippet] GetBlackCountAll



Dan the man
11-13-2015, 12:38 PM
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!


{*
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

kristi
11-15-2015, 02:11 AM
Looks nice, but what practical uses does this have?

tls
11-15-2015, 03:09 AM
Looks nice, but what practical uses does this have?

Could use it to count specific items in inventory.

Flight
11-15-2015, 03:31 AM
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.

function TItem.getAmount(ExcludeBank: Boolean): Integer;

Dan the man
11-16-2015, 05:22 AM
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.



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.

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 :(

Laquisha
11-16-2015, 07:47 AM
You could shorten it a bit with something like


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;

Dan the man
11-16-2015, 10:08 AM
You could shorten it a bit with something like


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