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