Cigue
08-06-2010, 09:35 AM
TL;DR WHAT can cause a FindDTM/DTMRotated to fail when :
1. The object searched for is visible and completely included in the search area;
2. The DTM is tested and works;
3. This only happens after going through a long set of instructions?
Why is it that after certain series of functions I can't ever find a DTM? here is an example script that always return false because DTMRotated gets jammed, even though if I run the DTM through DTM Editor it says it's been found.
I joined the script so you could try it, just home teleport to lumbridge then run it.
{$i SRL/SRL.scar}
{************************************************* ******************************
function CFlag :`Boolean;
Description: Custom flag.
************************************************** *****************************}
function CFlag : Boolean;
var
x, y, T : integer;
begin
MarkTime(T);
Wait(400+Random(200));
while ((FlagDistance >= Random(4)) and FindColor(x, y, FlagColor, MMX1, MMY1, MMX2, MMY2))
and (TimeFromMark(T) < 15000) do
Wait(100 + Random(50));
if (FlagDistance < 4) then Result := True;
end;
type
TMMObject = record
Color, Tolerance, xWhenLookingNorth, yWhenLookingNorth, Size, DTM : integer;
Hue, Sat : extended;
Name : string;
end;
{************************************************* ******************************
function MMWalk : Boolean;
Description: Walks to part of map clicked.
************************************************** *****************************}
function MMWalk(TargetObject : TMMObject) : Boolean;
var
SPoint : TPoint;
SPoints : TPointArray;
SBox : TBox;
SBoxes : T2DPointArray;
MinLength, tmpTol, T, HorizontalBounds, VerticalBounds, x1, y1, x2, y2: Integer;
begin
if RS_GetCompassAngleRadians < 0 then Exit;
Writeln('MMWalk ' + TargetObject.Name);
if not LoggedIn then
Exit;
SPoint := RotatePoint(Point(TargetObject.xWhenLookingNorth,
TargetObject.yWhenLookingNorth), (RS_GetCompassAngleRadians), MMCX, MMCY);
Writeln(ToStr(SPoint.x) + ' ' + ToStr(SPoint.y));
if Point(TargetObject.xWhenLookingNorth, TargetObject.yWhenLookingNorth) = Point(0, 0) then
SBox := IntToBox(MMX1, MMY1, MMX2, MMY2)
else
begin
HorizontalBounds := SPoint.x/10;
if (HorizontalBounds <> 0) then HorizontalBounds := HorizontalBounds/iAbs(HorizontalBounds);
VerticalBounds := SPoint.x/10;
if (VerticalBounds <> 0) then VerticalBounds := VerticalBounds/iAbs(VerticalBounds);
case HorizontalBounds of
-1 : begin
x1 := MMCX;
x2 := MMX2;
end;
0 : begin
x1 := MMCX-20;
x2 := MMCX+20;
end;
1 : begin
x1 := MMX1;
x2 := MMCX;
end;
end;
case VerticalBounds of
-1 : begin
y1 := MMY1;
y2 := MMCY;
end;
0 : begin
y1 := MMCY-20;
y2 := MMCY+20;
end;
1 : begin
y1 := MMCY;
y2 := MMY2;
end;
end;
SBox := IntToBox(x1, y1, x2, y2);
Writeln(ToStr(SBox.x1) + ' ' + ToStr(SBox.y1) + ' ' + ToStr(SBox.x2) + ' ' + ToStr(SBox.y2));
end;
if not PointInBox(SPoint, SBox) then
SRL_Warn('MMWalk', 'Searching point is not in Search Area', 0);
if (TargetObject.Hue <> 0) or (TargetObject.Sat <> 0) then
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(TargetObject.Hue, TargetObject.Sat);
end else
begin
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
MarkTime(T);
for tmpTol := TargetObject.Tolerance to (2*TargetObject.Tolerance) do
begin
if TimeFromMark(T) > 10000 then Break;
FindColorsSpiralTolerance(SPoint.x, SPoint.y, SPoints, TargetObject.Color, SBox.x1, SBox.y1, SBox.x2,
SBox.y2, TargetObject.Tolerance);
MinLength := TargetObject.Size*TargetObject.Size/2;
if Length(SPoints) > MinLength then
begin
SBoxes := TPAtoATPA(SPoints, TargetObject.Size);
SortATPAFromFirstPoint(SBoxes, SPoint);
SPoint := MiddleTPA(SBoxes[0]);
Mouse(SPoint.x, SPoint.y, TargetObject.Size/3, TargetObject.Size/3, True);
{$IFDEF REFLECTION}
R_Flag;
{$ELSE}
CFlag;
{$ENDIF}
Wait(RandomRange(2600, 2800));
TargetObject.Tolerance := tmpTol;
Result := FindDTM(TargetObject.DTM, x1, y1, MMX1, MMY1, MMX2, MMY2) and
FindColorTolerance(x2, y2, TargetObject.Color, MSCX-25, MSCY-25, MSCX+25, MSCY+25, TargetObject.Tolerance+2);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;
Writeln('MM Object ' + TargetObject.Name + ' has not been found, increasing tolerance...');
IncEx(TargetObject.Tolerance, 2);
end;
SRL_Warn('MMWalk', 'Couldn''t find MM object ' + TargetObject.Name, 0);
end;
{************************************************* ******************************
function STARTUP_WalkToLumbridgeCastleStairs : Boolean;
Description: Walks to Lumbridge Castle stairs. Will return true if it did, false
if it didn't.
************************************************** *****************************}
function STARTUP_WalkToLumbridgeCastleStairs : Boolean;
var
InsideCastle : TMMObject;
begin
{$IFDEF REFLECTION}
Result := WalkToTile(Point(3208, 3210), 1, 0);
{$ELSE}
With InsideCastle do
begin
Color := 7831166;
Tolerance := 10;
xWhenLookingNorth := 570;
yWhenLookingNorth := 125;
Size := 3;
Hue := 1.31;
Sat := 0.25;
Name := 'InsideCastle';
DTM := DTMFromString('78DA637464666058CE0006CC108A2129469 98' +
'10B483302F17F2060AC02CA5441E418A16AAAAAAAE06AC0E2 1B81' +
'6AB6A0AA69A82E4655930654F309554D749D368A1A007BC40 D99');
end;
Result := MMWalk(InsideCastle);
FreeDTM(InsideCastle.DTM);
{$ENDIF}
end;
begin
SetupSRL;
Writeln(ToStr(STARTUP_WalkToLumbridgeCastleStairs) );
end.
1. The object searched for is visible and completely included in the search area;
2. The DTM is tested and works;
3. This only happens after going through a long set of instructions?
Why is it that after certain series of functions I can't ever find a DTM? here is an example script that always return false because DTMRotated gets jammed, even though if I run the DTM through DTM Editor it says it's been found.
I joined the script so you could try it, just home teleport to lumbridge then run it.
{$i SRL/SRL.scar}
{************************************************* ******************************
function CFlag :`Boolean;
Description: Custom flag.
************************************************** *****************************}
function CFlag : Boolean;
var
x, y, T : integer;
begin
MarkTime(T);
Wait(400+Random(200));
while ((FlagDistance >= Random(4)) and FindColor(x, y, FlagColor, MMX1, MMY1, MMX2, MMY2))
and (TimeFromMark(T) < 15000) do
Wait(100 + Random(50));
if (FlagDistance < 4) then Result := True;
end;
type
TMMObject = record
Color, Tolerance, xWhenLookingNorth, yWhenLookingNorth, Size, DTM : integer;
Hue, Sat : extended;
Name : string;
end;
{************************************************* ******************************
function MMWalk : Boolean;
Description: Walks to part of map clicked.
************************************************** *****************************}
function MMWalk(TargetObject : TMMObject) : Boolean;
var
SPoint : TPoint;
SPoints : TPointArray;
SBox : TBox;
SBoxes : T2DPointArray;
MinLength, tmpTol, T, HorizontalBounds, VerticalBounds, x1, y1, x2, y2: Integer;
begin
if RS_GetCompassAngleRadians < 0 then Exit;
Writeln('MMWalk ' + TargetObject.Name);
if not LoggedIn then
Exit;
SPoint := RotatePoint(Point(TargetObject.xWhenLookingNorth,
TargetObject.yWhenLookingNorth), (RS_GetCompassAngleRadians), MMCX, MMCY);
Writeln(ToStr(SPoint.x) + ' ' + ToStr(SPoint.y));
if Point(TargetObject.xWhenLookingNorth, TargetObject.yWhenLookingNorth) = Point(0, 0) then
SBox := IntToBox(MMX1, MMY1, MMX2, MMY2)
else
begin
HorizontalBounds := SPoint.x/10;
if (HorizontalBounds <> 0) then HorizontalBounds := HorizontalBounds/iAbs(HorizontalBounds);
VerticalBounds := SPoint.x/10;
if (VerticalBounds <> 0) then VerticalBounds := VerticalBounds/iAbs(VerticalBounds);
case HorizontalBounds of
-1 : begin
x1 := MMCX;
x2 := MMX2;
end;
0 : begin
x1 := MMCX-20;
x2 := MMCX+20;
end;
1 : begin
x1 := MMX1;
x2 := MMCX;
end;
end;
case VerticalBounds of
-1 : begin
y1 := MMY1;
y2 := MMCY;
end;
0 : begin
y1 := MMCY-20;
y2 := MMCY+20;
end;
1 : begin
y1 := MMCY;
y2 := MMY2;
end;
end;
SBox := IntToBox(x1, y1, x2, y2);
Writeln(ToStr(SBox.x1) + ' ' + ToStr(SBox.y1) + ' ' + ToStr(SBox.x2) + ' ' + ToStr(SBox.y2));
end;
if not PointInBox(SPoint, SBox) then
SRL_Warn('MMWalk', 'Searching point is not in Search Area', 0);
if (TargetObject.Hue <> 0) or (TargetObject.Sat <> 0) then
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(TargetObject.Hue, TargetObject.Sat);
end else
begin
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
MarkTime(T);
for tmpTol := TargetObject.Tolerance to (2*TargetObject.Tolerance) do
begin
if TimeFromMark(T) > 10000 then Break;
FindColorsSpiralTolerance(SPoint.x, SPoint.y, SPoints, TargetObject.Color, SBox.x1, SBox.y1, SBox.x2,
SBox.y2, TargetObject.Tolerance);
MinLength := TargetObject.Size*TargetObject.Size/2;
if Length(SPoints) > MinLength then
begin
SBoxes := TPAtoATPA(SPoints, TargetObject.Size);
SortATPAFromFirstPoint(SBoxes, SPoint);
SPoint := MiddleTPA(SBoxes[0]);
Mouse(SPoint.x, SPoint.y, TargetObject.Size/3, TargetObject.Size/3, True);
{$IFDEF REFLECTION}
R_Flag;
{$ELSE}
CFlag;
{$ENDIF}
Wait(RandomRange(2600, 2800));
TargetObject.Tolerance := tmpTol;
Result := FindDTM(TargetObject.DTM, x1, y1, MMX1, MMY1, MMX2, MMY2) and
FindColorTolerance(x2, y2, TargetObject.Color, MSCX-25, MSCY-25, MSCX+25, MSCY+25, TargetObject.Tolerance+2);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;
Writeln('MM Object ' + TargetObject.Name + ' has not been found, increasing tolerance...');
IncEx(TargetObject.Tolerance, 2);
end;
SRL_Warn('MMWalk', 'Couldn''t find MM object ' + TargetObject.Name, 0);
end;
{************************************************* ******************************
function STARTUP_WalkToLumbridgeCastleStairs : Boolean;
Description: Walks to Lumbridge Castle stairs. Will return true if it did, false
if it didn't.
************************************************** *****************************}
function STARTUP_WalkToLumbridgeCastleStairs : Boolean;
var
InsideCastle : TMMObject;
begin
{$IFDEF REFLECTION}
Result := WalkToTile(Point(3208, 3210), 1, 0);
{$ELSE}
With InsideCastle do
begin
Color := 7831166;
Tolerance := 10;
xWhenLookingNorth := 570;
yWhenLookingNorth := 125;
Size := 3;
Hue := 1.31;
Sat := 0.25;
Name := 'InsideCastle';
DTM := DTMFromString('78DA637464666058CE0006CC108A2129469 98' +
'10B483302F17F2060AC02CA5441E418A16AAAAAAAE06AC0E2 1B81' +
'6AB6A0AA69A82E4655930654F309554D749D368A1A007BC40 D99');
end;
Result := MMWalk(InsideCastle);
FreeDTM(InsideCastle.DTM);
{$ENDIF}
end;
begin
SetupSRL;
Writeln(ToStr(STARTUP_WalkToLumbridgeCastleStairs) );
end.