SRL Archive - MSI Suggestions

MSI_FindTool


Coh3n

2009-11-10 14:46:12

MSI_FindTool(ToolMaterial: TItem);


I know NCDS is working on Objects.scar, but I was bored and decided to make this function. It looks for the specified tool in the inventory, if it doesn't find it, it looks to see if it's equipped.
{*******************************************************************************}
{ function MSI_FindTool(ToolMaterial: TItem): Boolean; }
{ By: Coh3n }
{ Rev: }
{ Date: 10 Nov 09 }
{ Description: Finds the specified tool when equipped or when in the inventory. }
{*******************************************************************************}

function MSI_FindTool(ToolMaterial: TItem): Boolean;
var
SearchLocation: TIntegerArray;
ColorsArr: TPointArray;
I, II, H, X, Y, X1, X2, Y1, Y2, Tol: Integer;
ColorCheck, BitmapCheck, DTMCheck: Boolean;
begin
if not LoggedIn then Exit;

SearchLocation := [tab_Inv, tab_Equip];

for II := 0 to 1 do
begin
GameTab(SearchLocation[II]);

if II = 0 then
begin
X1 := MIX1; X2 := MIX2;
Y1 := MIX2; Y1 := MIY2;
end else begin
X1 := 570; X2 := 602;
Y1 := 289; Y2 := 322;
{ Weapon Equipment Slot }
end;

H := High(ToolMaterial.Colors);
for I := 0 to H do
begin
FindColorsTolerance(ColorsArr, ToolMaterial.Colors[I], X1, Y1, X2, Y2, 5);
ColorCheck := Length(ColorsArr) >= 15;

Writeln('Colors Found: ' + IntToStr(Length(ColorsArr)) + '.');

if ColorCheck then
Break;
end;

if not ColorCheck then
begin
Tol := 0;
repeat
BitmapCheck := FindBitmapToleranceIn(X, Y, ToolMaterial.BMP, X1, Y1, X2, Y2, Tol);
IncEx(Tol, 5);
until((Tol >= 50) or BitmapCheck);
end;

if not BitmapCheck and (Tol >= 50) then
DTMCheck := FindDTM(ToolMaterial.DTM, X, Y, X1, Y1, X2, Y2);

Result := ColorCheck or BitmapCheck or DTMCheck;
if Result then
begin
Writeln('Found Tool.');
Break;
end;

end; // of GameTab for..to..do

FreeBitmap(ToolMaterial.BMP);
FreeDTM(ToolMaterial.DTM);
end;
I tested it with this script:
{.Include SRL/SRL.Scar}

type
TItem = record
Name : String;
UpText : TStringArray;
ItemP : TPoint;
Stackable : Boolean;
Colors : TIntegerArray;
DTM : Integer;
BMP : Integer;
end;


{*******************************************************************************}
{ function MSI_FindTool(ToolMaterial: TItem): Boolean; }
{ By: Coh3n }
{ Rev: }
{ Date: 10 Nov 09 }
{ Description: Finds the specified tool when equipped or when in the inventory. }
{*******************************************************************************}

function MSI_FindTool(ToolMaterial: TItem): Boolean;
var
SearchLocation: TIntegerArray;
ColorsArr: TPointArray;
I, II, H, X, Y, X1, X2, Y1, Y2, Tol: Integer;
ColorCheck, BitmapCheck, DTMCheck: Boolean;
begin
if not LoggedIn then Exit;

SearchLocation := [tab_Inv, tab_Equip];

for II := 0 to 1 do
begin
GameTab(SearchLocation[II]);

if II = 0 then
begin
X1 := MIX1; X2 := MIX2;
Y1 := MIX2; Y1 := MIY2;
end else begin
X1 := 570; X2 := 602;
Y1 := 289; Y2 := 322;
{ Weapon Equipment Slot }
end;

H := High(ToolMaterial.Colors);
for I := 0 to H do
begin
FindColorsTolerance(ColorsArr, ToolMaterial.Colors[I], X1, Y1, X2, Y2, 5);
ColorCheck := Length(ColorsArr) >= 15;

Writeln('Colors Found: ' + IntToStr(Length(ColorsArr)) + '.');

if ColorCheck then
Break;
end;

if not ColorCheck then
begin
Tol := 0;
repeat
BitmapCheck := FindBitmapToleranceIn(X, Y, ToolMaterial.BMP, X1, Y1, X2, Y2, Tol);
IncEx(Tol, 5);
until((Tol >= 50) or BitmapCheck);
end;

if not BitmapCheck and (Tol >= 50) then
DTMCheck := FindDTM(ToolMaterial.DTM, X, Y, X1, Y1, X2, Y2);

Result := ColorCheck or BitmapCheck or DTMCheck;
if Result then
begin
Writeln('Found Tool.');
Break;
end;

end; // of GameTab for..to..do

FreeBitmap(ToolMaterial.BMP);
FreeDTM(ToolMaterial.DTM);
end;

var
Hatchet_Rune: TItem;
begin
SetupSRL;
ActivateClient;

with Hatchet_Rune do
begin
Colors := [4932921, 5261885];
BMP := BitmapFromString(4, 4, 'beNpz8XLwDf7vHfjf0++/mw' +
'+QtPH0s3LzsXDxAiI429TBFSoIALTvD9s=');
DTM := DTMFromString('78DA63F4646260B8C380022C5CBC18F881342' +
'394CF680F54F384010D3041E4606AEC80FCDB04D47800F93708A8' +
'F105F2EFE2570300DB0B069D');
end;

MSI_FindTool(Hatchet_Rune);
end.

Everything seemed to work fine, please post your thoughts.

Coh3n

NCDS

2009-11-10 23:26:17

Very nice ;)

Coh3n

2009-11-11 11:30:06

From: NCDS
Very nice ;)

Thanks. :smile:

If no one has any other comments, does anyone object to me committing this?

Coh3n

2009-11-12 00:01:31

Sorry for double post, but I thought I'd explain a few things before I commit this function.
  • I changed the ColorCheck to return true only if the length of the ColorsArr is greater than 15. I stumbled across this when I was gathering the colors for ItemInfo.scar and realized that it can pick up a few similar colors from other items. This way, if the length is greater than 15, we know for sure that it's the correct item. I will be sure to test this for all hatchets and pickaxes in the morning. It is possible I'll have to change the "15".
  • You may wonder why I didn't just use an uptext check. Well, I simply wanted to avoid having to move the mouse. It would make the function slower, not to mention not many people move the mouse when checking for a particular tool.
  • I just remembered NCDS suggested a long time ago that I have the functions return a TPoint rather than a boolean. I think this is very possible, and I should be able to edit accordingly without problems.

Well that's all for now, time for bed. Please post your thoughts! :smile:

Thanks,

Coh3n