SRL Archive - Research & Development Lounge

InvCountStack


The_Scripts

2009-10-09 12:59:08

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)…

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

Narcle

2009-10-09 13:18:40

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.

The_Scripts

2009-10-09 13:26:02

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

YoHoJo

2009-10-09 14:55:34

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.

The_Scripts

2009-10-09 16:55:28

@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?

YoHoJo

2009-10-09 17:06:25

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

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.

Naike

2009-10-09 18:54:14

Why not just use GetAmount?