SRL Archive - Help

Counting items


SwagDaddy

2012-12-31 15:47:42

How do you count stack-able items in your inventory? Like for me I want to count water runes in inventory.

Brandon

2012-12-31 15:54:00

ItemAmount function.

From the SRL include:



(*
ItemAmount
~~~~~~~~~~

.. code-block:: pascal

function ItemAmount(area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;

Counts the number of items found within the Area (counts stacks).
Parameters are exactly the same as ItemCoordinates.

.. note::

Author: masquerader
Last Modified: Unknown by ZephyrsFury

Example:

.. code-block:: pascal

var
itemsFound: integer;
begin
itemsFound := ItemAmount('inv', 'dtm', dtm_Ore, []);
writeln('Ore found: '+toStr(itemsFound));
end;
*)
function ItemAmount(area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;
var
startX, startY, rowSize, colSize, colNumber, rowNumber: integer;
Coords: TPointArray;
i, h: Integer;
begin
Result := 0;
AreaInfo(area, startX, startY, rowSize, colSize, colNumber, rowNumber);
Coords := ItemCoordinates(Area, ItemType, Item, Tol);
h := High(Coords);
for i := 0 to h do
Result := Result + GetAmountBox(IntToBox(Coords[i].x - floor(rowSize / 2),
Coords[i].y - floor(colSize / 2),
Coords[i].x + floor(rowSize / 2),
Coords[i].y + floor(colSize / 4)));
end;

SwagDaddy

2012-12-31 15:55:44

ah thanks I was trying to use CountItem but I see why it wasn't working

Le Jingle

2012-12-31 15:56:44

function GetAmountBox(box: TBox): integer;

Ex.


{$i srl/srl.simba}
var
amount : Integer;
b: TBox;
begin
SetupSRL;
b := InvBox(1); // creates a box from the first inventory slot.
amount := GetAmountBox(b); // counts the text in that first slot ^
writeln(amount);
end.

edit: :ninja:'d

Ian

2012-12-31 16:02:29

What about items in the bank?

Le Jingle

2012-12-31 16:04:53

From: BMWxi
What about items in the bank?


Here's what I used in my fletcher (prob outdated section now)


procedure CountItemCheck;
var
count: Integer;
b: TBox;
begin
if (bankscreen) then
begin
b := BankIndexToMSBox(BankPointToBankIndex(Point(9, 0)));
count := GetAmountBox(b);

Writeln('Items Remaining = ' + IntToStr(count) + '.');

if (count < 100) then
begin
Writeln('Almost out of supplies! -> CIAO / TERMINATING SCRIPT');
TerminateScript;
end;
end;
end;

^ Just more boxes. Could use a DTM/count colors/etc. (ex. to find the item in bank) to pass parameters for it too, the one I have above is static

Ian

2012-12-31 16:06:14

Ah, I see, thanks :)

Wardancer

2012-12-31 17:51:15

From: BMWxi
What about items in the bank?


Or, simpler, getting the number of items out of a TP:

GetBankItemAmount(((TP.x - 38) div 44), ((TP.y - 90) div 45)) < 50)

Same function can be used if you know the coordinates too (like 0, 0). The formulas I'm using are to transform a TP into a bank row and column.