SRL Archive - Help

DTMs question


Cigue

2010-08-06 05:35:58

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('78DA637464666058CE0006CC108A212946998' +
'10B483302F17F2060AC02CA5441E418A16AAAAAAAE06AC0E21B81' +
'6AB6A0AA69A82E4655930654F309554D749D368A1A007BC40D99');
end;
Result := MMWalk(InsideCastle);
FreeDTM(InsideCastle.DTM);
{$ENDIF}
end;

begin
SetupSRL;
Writeln(ToStr(STARTUP_WalkToLumbridgeCastleStairs));
end.

nielsie95

2010-08-06 07:19:46

Maybe the box you're looking in is too small, or maybe the cts isn't good?
I also noticed you use MM for the DTM search and MS for the color search?

Cigue

2010-08-06 13:32:58

From: nielsie95
Maybe the box you're looking in is too small, or maybe the cts isn't good?
I also noticed you use MM for the DTM search and MS for the color search?


1. The function fully executes successfully, up until the DTM Check, which returns false.
2. Commenting the FindColor part gives the same results.
3. I have stumbled on this problem back when I was working on my ectofuntus script. When I completed a run and restarted the main loop, it could never find a minimap DTM but that (here is the kicker) sent it into an error function, which called a locate function, which made the exact same DTM search but found it this time.

This is probably more related to the theory of DTMs rather than a faulty function, since after diagnosing the only thing to fuck up is the DTM Search, and if I put it into a blank script it works.

I've edited my first post to give you a better idea of what I'm looking for.

EDIT : Lol what about CTS fucks up DTMs?

ZephyrsFury

2010-08-07 00:11:19

From: Cigue

EDIT : Lol what about CTS fucks up DTMs?


If you make the DTM using the default CTS1 tolerances and then try to find the DTM with a different CTS setting the search could fail. Shouldn't be a problem though as long as you always set CTS back to default if you ever change it.

EDIT: You say you use DTMRotated but you only use FindDTM in the script above.