SRL Archive - SRL Archives

FindFirstInv + FindLastInv


Tootoot222

2008-10-27 02:31:27

{*******************************************************************************
function FT(var x, y: Integer; Thing, x1, y1, x2, y2: Integer;
Tol: array of Integer; ThingType: String): Boolean;
By: Tootoot222
Description: Finds "Thing" in x1, y1, x2, y2 and stores the coords in x, y;
*******************************************************************************}

function FT(var X, Y: Integer; Thing, X1, Y1, X2, Y2: Integer;
Tol: array of Integer; ThingType: String): Boolean;
begin
case Lowercase(ThingType) of
'b', 'bmp', 'bitmap':
Result:= FindBitmapToleranceIn(Thing, X, Y, X1, Y1, X2, Y2, Tol[0]);
'c', 'clr', 'color':
Result:= FindColorTolerance(X, Y, Thing, X1, Y1, X2, Y2, Tol[0]);
'd', 'dtm':
Result:= FindDTM(Thing, X, Y, X1, Y1, X2, Y2);
'm', 'msk', 'bmpmask', 'bitmapmask', 'bmp mask', 'bitmap mask', 'mask':
Result:= FindBitmapMaskTolerance(Thing, X, Y, X1, Y1, X2, Y2, Tol[0], Tol[1]);
end;
end;

{*******************************************************************************
function FindLastInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
By: Tootoot222 / small edit by Nava2
Description: Returns the inv slot of the last occurrence of Thing in inventory
Returns 0 if Thing is not found
*******************************************************************************}

function FindLastInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
var
B: TBox;
X, Y: Integer;
begin
for Result:= 28 downto 1 do
begin
B:= InvBox(Result);
if(ExistsItem(Result)) then
if(FT(X, Y, Thing, B.X1, B.Y1, B.X2, B.Y2, Tol, ThingType)) then
Exit;
end;
Result:= 0;
end;

{*******************************************************************************
function FindFirstInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
By: Tootoot222 / small edit by Nava2
Description: Returns the inv slot of the first occurrence of Thing in inventory
Returns 0 if Thing is not found
*******************************************************************************}

function FindFirstInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
var
B: TBox;
X, Y: Integer;
begin
for Result:= 1 to 28 do
begin
B:= InvBox(Result);
if(ExistsItem(Result)) then
if(FT(X, Y, Thing, B.X1, B.Y1, B.X2, B.Y2, Tol, ThingType)) then
Exit;
end;
Result:= 0;
end;

FT is a great little function i made, it finds everything ^_^

hope this is good enough for SRL :sasmokin:


EDIT: This would go into Inventory.scar

Nava2

2008-10-27 08:27:39

I like your use of Result in the for loop! :)

Most don't think of that.

Instead of having an else statement which sets the result to 0.. why not just set it to 0 at the end of the function? That way it won't set it if it exits anyways. It'll save you a few lines :)

Tootoot222

2008-10-27 08:55:24

yes, sadly everyone wastes the tiny little bit of memory to hold a var where it's not needed =P

ah, yes, i could do that… thanks for pointing that out

HyperSecret

2008-10-27 09:30:28

There is already a function that is more elaborate than your FT, that is already in SRL.

WT-Fakawi made it I believe. I don't remember the name of the function off the top of my head.

Tootoot222

2008-10-27 09:54:50

it's imbedded in alot of his functions/procedures, and i *ahem* may have copied "'bmpmask', 'bitmapmask', 'bmp mask', 'bitmap mask'" from him, but i've never seen it as it's own function before…

btw, FT stands for FindThing, but i use FT in another function called FindThing, which is like FindObj but it uses bmps/masks/dtms/colors and checks the uptext