Macrosoft
2008-07-29 00:58:44
UPDATE: All Problems Fixed! (Except for flag problem)
I have spent the last few weeks doing nothing but scripting this function and taking Xbox Live Breaks (lol). Oh yeah and playing tennis.
Your help is needed in order to find bugs and solve problems.
What it does
This function/script finds a DTM on the world map and then finds the angle needed to walk to that location.
Future Updates
Much more will be added later including the use of boats to travel onto and off of islands and the use of my currently not working CheckMovement function (Which should be better than flag because the flag tends to move off the screen when walking around walls etc.)
How to Use It
WMDestinationDTM is the DTM you are walking to MADE ON THE WORLD MAP. MMDestinationDTM is the DTM you are walking to MADE ON THE MINI MAP.
MLx and MLy are the coords of the TOP LEFT corner of the RED RECTANGLE on the mini overview of the world map. You should be standing at the location that you want the script to walk to when you press the word map button and find these coords.
Known Bugs
In the normal version, if the flag goes off the minimap, the "Flag" function will fail. Thus the function will fail. This will be fixed once I get CheckMovement working.
The Script
This script should walk to the Varrock East Bank (Or at least towards it for now). Keep in mind this is still in the testing stages and will have bugs. I suggest you try this somewhere in Varrock though it should work from almost anywhere. If the flag goes off the map at any time, the function will not work unless you are using the reflection version (This will be fixed with CheckMovement when I get it working).
NORMAL VERSION
program New;
{.include SRL/SRL.scar}
var
x, y, WMDTM, MMDTM: Integer;
function Loading: Boolean;
var
Load, x, y: integer;
begin
Load := BitmapFromString(29, 3, 'beNr7/x8CGFABsiCagv+oAJ' +
'd6kowlnk0TYwEHnoCA');
Result := FindBitmap(Load, x, y);
FreeBitmap(Load);
end;
function OpenMap: Boolean;
var
a: Integer;
begin
Mouse(530, 130, 20, 20, true);
a:=0;
repeat
Wait(500);
a:=a+1;
until(Loading)or(a=15);
if(a=15)then
begin
Result:=False;
WriteLn('Error: Could nor open map: Wont start to load');
Exit;
end;
a:=0;
repeat
Wait(1000);
a:=a+1;
until(not(Loading))or(a=20);
Wait(500+Random(1000));
if(a=20)then
begin
WriteLn('Error: Could not open map: Loading for too long');
Result:=False;
Exit;
end;
Result:=True;
end;
procedure CloseMap;
begin
Mouse(740, 10, 15, 15, True);
Wait(2000 + Random(1000));
end;
function FindAngle(L, D: Tpoint):Extended;
var
TrigAngle: Integer;
begin
if(L.x=D.x)then //if must go perfect n or s
begin
if(L.y>D.y)then //if go p north
begin
Result:=0;
Exit;
end else //if go p south
begin
Result:=180;
Exit;
end;
end;
if(L.y=D.y)then //if must go perfect e or w
begin
if(L.x>D.x)then //if go p west
begin
Result:=270;
Exit;
end else //if go p east
begin
Result:=90;
Exit;
end;
end;
TrigAngle:=Round(Degrees(ArcTan(Abs(D.y-L.y)/Abs(D.x-L.x))));
if(L.y>D.y)then //if need go north (destination higher than location
begin
if(L.x<D.x)then Result:=90-TrigAngle; //If need go NorthEast
if(L.x>D.x)then Result:=270+TrigAngle; //if need go NorthWest
end;
if(L.y<D.y)then //if need go south
begin
if(L.x<D.x)then Result:=90+TrigAngle; //if need go SouthEast
if(L.x>D.x)then Result:=270-TrigAngle; //If need southwest
end;
end;
function ChangeZoom(CurrentZoom, Zoom: Integer): Boolean;
var
ColCheck: array[0..1] of integer;
begin
if(CurrentZoom=Zoom)then Exit;
ColCheck[0]:=GetColor(565, 342);
ColCheck[1]:=GetColor(565, 373);
Mouse(562, 472, 27, 17, True);
Wait(100 + Random(100));
if(ColCheck[0]=GetColor(565, 342))and(ColCheck[1]=GetColor(565, 373))then
begin
Result:=False;
Exit;
end;
case(Zoom)of
37: Mouse(562, 340, 27, 17, True);
50: Mouse(562, 371, 27, 17, True);
75: Mouse(562, 402, 27, 17, True);
100: Mouse(562, 433, 27, 17, True);
end;
Mouse(562, 472, 27, 17, True);
Result:=True;
end;
function FindBRCorner(x, y: integer): Tpoint;
var
EdgeCol: integer;
begin
EdgeCol:=GetColor(x, y);
repeat
begin
x:=x+1;
end;
until(not(GetColor(x+1, y)=EdgeCol));
repeat
begin
y:=y+1;
end;
until(not(GetColor(x, y+1)=EdgeCol));
Result.x:=x;
Result.y:=y;
end;
function MoveMap(x, y: integer): boolean;
var
Cx, Cy, x1, y1, x2, y2, MS: Integer;
BR, Change: Tpoint;
begin
if(not(FindColorTolerance(x2, y2, 255, 605, 310, 760, 460, 5)))then
begin
Result:=False;
Exit;
end;
BR:=FindBRCorner(x2, y2);
Change.x:=x-x2;
Change.y:=y-y2;
Cx:=Round(Abs(BR.x-x2)/4);
Cy:=Round(Abs(BR.y-y2)/4);
MMouse(x2+Cx, y2+Cy, 2*Cx, 2*Cy);
MS:=MouseSpeed;
MouseSpeed:=3;
GetMousePos(x1, y1);
HoldMouse(x1, y1, True);
x2:=x1+Change.x-5+Random(10);
y2:=y1+Change.y-5+Random(10);
MMouse(x2, y2, 4, 4);
Wait(100+Random(100));
GetMousePos(x1, y1);
ReleaseMouse(x1, y1, True);
MouseSpeed:=MS;
Result:=True;
end;
procedure AngleWalk(Degrees, Radius: Integer);
var
x1, y1, Quad, Angle, x, y: Integer;
begin
Angle:=Round(rs_GetCompassAngleDegrees+Degrees);
if(Angle>=360)then Angle:=Angle-360;
if(Angle<0)then Angle:=Angle+360;
case Angle of
0..90: Quad:=1;
91..179: Quad:=2;
180..270: Quad:=3;
271..359: Quad:=4;
end;
repeat
if(Angle>=90)then Angle:=Angle-90;
until(Angle<=90);
y:= Round((cos(Radians(Angle))) * Radius);
x:= Round((sin(Radians(Angle))) * Radius);
case Quad of
1:
begin
y1:=MMCY-y
x1:=MMCX+x
end;
2:
begin
y1:=MMCY+x
x1:=MMCX+y
end;
3:
begin
y1:=MMCY+y
x1:=MMCX-x
end;
4:
begin
y1:=MMCY-x
x1:=MMCX-y
end;
end;
MouseFlag(x1, y1, 0, 0);
end;
function WorldMAPWalk(WMDestinationDTM, MMDestinationDTM: Integer; MLx, MLy: Integer): Boolean;
var
RDis, Trav, TDis, Dis, Angle, x, y, a, W, H: integer;
MC, Loc, Des: Tpoint;
Check, Stop: Boolean;
begin
MC.x:=383;
MC.y:=252;
GetClientDimensions(W, H);
MakeCompass('n');
for a:=0 to 3 do
begin
if(DTMRotated(MMDestinationDTM, x, y, MMX1, MMY1, MMX2, MMY2))then
begin
MouseFlag(x, y, 10, 10);
WriteLn('Arrived at destination');
Result:=True;
Exit;
end;
Wait(500);
end;
repeat
begin
if(not(OpenMap))then
begin
Result:=False;
Exit;
end;
Check:=False;
if(DTMRotated(WMDestinationDTM, x, y, 0, 0, W, H))then
begin
Des.x:=x;
Des.y:=y;
Angle:=Round(FindAngle(MC, Des));
Dis:=Distance(MC.x, MC.y, Des.x, Des.y);
Check:=True;
CloseMap;
end else
begin
Mouse(670, 470, 27, 17, True);
Wait(400 + Random(100));
if(not(FindColorTolerance(x, y, 255, 605, 310, 760, 460, 5)))then
begin
Result:=False;
Exit;
end;
Loc.x:=x;
Loc.y:=y;
Des.x:=MLx;
Des.y:=MLy;
Dis:=(Distance(x, y, MLx, MLy)*455)/8;
Angle:=Round(FindAngle(Loc, Des));
MoveMap(MLx, MLy);
Wait(2000+Random(1000));//IdleTime(2000, 1000, 7);
CloseMap;
end;
WriteLn(Floattostr(Angle));
case Dis of
0..400: RDis:=Dis;
401..899: RDis:=Round(Dis/2+50)+Random(100);
900..1600: RDis:=Round((Dis/2)+Random(100));
else RDis:=800+Random(100);
end;
Trav:=0;
repeat
begin
case RDis-Trav of
(0-10)..10:Stop:=True;
0..75:
begin
TDis:=RDis-Trav;
AngleWalk(Angle-4+Random(8), TDis);
end;
76..120:
begin
TDis:=Round(((RDis-Trav)/2)-5+Random(10));
AngleWalk(Angle-4+Random(8), TDis);
end;
else
begin
TDis:=45+Random(30);
AngleWalk(Angle-5+Random(10), TDis);
end;
end;
Trav:=Trav+TDis;
end;
until(Stop);
if(Check)then
begin
MakeCompass('n');
for a:=0 to 15 do
begin
if(DTMRotated(MMDestinationDTM, x, y, MMX1, MMY1, MMX2, MMY2))then
begin
if(Distance(MMCX, MMCY, x, y)>20)then MouseFlag(x, y, 10, 10);
WriteLn('Arrived at destination');
Result:=True;
Exit;
end;
Wait(250);
end;
Check:=False;
end;
Wait(300+Random(500));
end;
until(false);
end;
begin
SetupSRL;
ActivateClient;
WMDTM := DTMFromString('78DA639CCFC4C0C0C7C800024C0C10D0585BC' +
'6C00EA441A2FF8180712250460455CD993367E06A408071135046' +
'88809A354019595435B6B20CA86A960165D850D5009D80A20600F' +
'2E01161');
MMDTM := DTMFromString('78DA632C646260486700032608C5D05C5FC1C' +
'005A41981F83F10302600657250D5E4C6E8C2D580006323502617' +
'55CDDBA7EF50D5E402659C71DB05565386A906C31C907BBCF0AB0' +
'10096F1152C');
WorldMAPWalk(WMDTM, MMDTM, 698, 372);
FreeDTM(WMDTM);
FreeDTM(MMDTM);
end.
SMART/Reflection Version
This should work with Reflection and should thus be more dependable. I haven't tried it yet though.
{SMART/Reflection version}
program New;
{.Include SRL/SRL/Misc/SMART.scar}
{.Include SRL/SRL.scar}
{.Include SRL/SRL/reflection/reflection.scar}
var
x, y, WMDTM, MMDTM: Integer;
function Loading: Boolean;
var
Load, x, y: integer;
begin
Load := BitmapFromString(29, 3, 'beNr7/x8CGFABsiCagv+oAJ' +
'd6kowlnk0TYwEHnoCA');
Result := FindBitmap(Load, x, y);
FreeBitmap(Load);
end;
function OpenMap: Boolean;
var
a: Integer;
begin
Mouse(530, 130, 20, 20, true);
a:=0;
repeat
Wait(500);
a:=a+1;
until(Loading)or(a=15);
if(a=15)then
begin
Result:=False;
WriteLn('Error: Could nor open map: Wont start to load');
Exit;
end;
a:=0;
repeat
Wait(1000);
a:=a+1;
until(not(Loading))or(a=20);
Wait(500+Random(1000));
if(a=20)then
begin
WriteLn('Error: Could not open map: Loading for too long');
Result:=False;
Exit;
end;
Result:=True;
end;
procedure CloseMap;
begin
Mouse(740, 10, 15, 15, True);
Wait(2000 + Random(1000));
end;
function FindAngle(L, D: Tpoint):Extended;
var
TrigAngle: Integer;
begin
if(L.x=D.x)then //if must go perfect n or s
begin
if(L.y>D.y)then //if go p north
begin
Result:=0;
Exit;
end else //if go p south
begin
Result:=180;
Exit;
end;
end;
if(L.y=D.y)then //if must go perfect e or w
begin
if(L.x>D.x)then //if go p west
begin
Result:=270;
Exit;
end else //if go p east
begin
Result:=90;
Exit;
end;
end;
TrigAngle:=Round(Degrees(ArcTan(Abs(D.y-L.y)/Abs(D.x-L.x))));
if(L.y>D.y)then //if need go north (destination higher than location
begin
if(L.x<D.x)then Result:=90-TrigAngle; //If need go NorthEast
if(L.x>D.x)then Result:=270+TrigAngle; //if need go NorthWest
end;
if(L.y<D.y)then //if need go south
begin
if(L.x<D.x)then Result:=90+TrigAngle; //if need go SouthEast
if(L.x>D.x)then Result:=270-TrigAngle; //If need southwest
end;
end;
function ChangeZoom(CurrentZoom, Zoom: Integer): Boolean;
var
ColCheck: array[0..1] of integer;
begin
if(CurrentZoom=Zoom)then Exit;
ColCheck[0]:=GetColor(565, 342);
ColCheck[1]:=GetColor(565, 373);
Mouse(562, 472, 27, 17, True);
Wait(100 + Random(100));
if(ColCheck[0]=GetColor(565, 342))and(ColCheck[1]=GetColor(565, 373))then
begin
Result:=False;
Exit;
end;
case(Zoom)of
37: Mouse(562, 340, 27, 17, True);
50: Mouse(562, 371, 27, 17, True);
75: Mouse(562, 402, 27, 17, True);
100: Mouse(562, 433, 27, 17, True);
end;
Mouse(562, 472, 27, 17, True);
Result:=True;
end;
function FindBRCorner(x, y: integer): Tpoint;
var
EdgeCol: integer;
begin
EdgeCol:=GetColor(x, y);
repeat
begin
x:=x+1;
end;
until(not(GetColor(x+1, y)=EdgeCol));
repeat
begin
y:=y+1;
end;
until(not(GetColor(x, y+1)=EdgeCol));
Result.x:=x;
Result.y:=y;
end;
function MoveMap(x, y: integer): boolean;
var
Cx, Cy, x1, y1, x2, y2: Integer;
BR, Change: Tpoint;
begin
if(not(FindColorTolerance(x2, y2, 255, 605, 310, 760, 460, 5)))then
begin
Result:=False;
Exit;
end;
BR:=FindBRCorner(x2, y2);
Change.x:=x-x2;
Change.y:=y-y2;
Cx:=Round(Abs(BR.x-x2)/4);
Cy:=Round(Abs(BR.y-y2)/4);
MMouse(x2+Cx, y2+Cy, 2*Cx, 2*Cy);
MS:=MouseSpeed; //
MouseSpeed:=3;
GetMousePos(x1, y1);
HoldMouse(x1, y1, True);
x2:=x1+Change.x-5+Random(10);
y2:=y1+Change.y-5+Random(10);
MMouse(x2, y2, 4, 4);
Wait(100+Random(100));
GetMousePos(x1, y1);
ReleaseMouse(x1, y1, True);
MouseSpeed:=MS;
Result:=True;
end;
procedure AngleWalk(Degrees, Radius: Integer);
var
x1, y1, Quad, Angle, x, y: Integer;
begin
Angle:=Round(GetMinimapAngleDeg+Degrees);
if(Angle>=360)then Angle:=Angle-360;
if(Angle<0)then Angle:=Angle+360;
case Angle of
0..90: Quad:=1;
91..179: Quad:=2;
180..270: Quad:=3;
271..359: Quad:=4;
end;
repeat
if(Angle>=90)then Angle:=Angle-90;
until(Angle<=90);
y:= Round((cos(Radians(Angle))) * Radius);
x:= Round((sin(Radians(Angle))) * Radius);
case Quad of
1:
begin
y1:=MMCY-y
x1:=MMCX+x
end;
2:
begin
y1:=MMCY+x
x1:=MMCX+y
end;
3:
begin
y1:=MMCY+y
x1:=MMCX-x
end;
4:
begin
y1:=MMCY-x
x1:=MMCX-y
end;
end;
Mouse(x1, y1, 0, 0, True);
Wait(1000);
R_Flag;
end;
function WorldMAPWalk(WMDestinationDTM, MMDestinationDTM: Integer; MLx, MLy: Integer): Boolean;
var
RDis, Trav, TDis, Dis, Angle, x, y, a: integer;
MC, Loc, Des: Tpoint;
Check, Stop: Boolean;
begin
MC.x:=383; //
MC.y:=252; //
GetClientDimensions(W, H);
MakeCompassR('n');
for a:=0 to 3 do
begin
if(DTMRotated(MMDestinationDTM, x, y, MMX1, MMY1, MMX2, MMY2))then
begin
Mouse(x, y, 10, 10, True);
Wait(1000);
R_Flag;
WriteLn('Arrived at destination');
Result:=True;
Exit;
end;
Wait(500);
end;
repeat
begin
if(not(OpenMap))then
begin
Result:=False;
Exit;
end;
Check:=False;
if(DTMRotated(WMDestinationDTM, x, y, 0, 0, W, H))then
begin
Des.x:=x;
Des.y:=y;
Angle:=Round(FindAngle(MC, Des));
Dis:=Distance(MC.x, MC.y, Des.x, Des.y);
Check:=True;
CloseMap;
end else
begin
Mouse(670, 470, 27, 17, True);
Wait(400 + Random(100));
if(not(FindColorTolerance(x, y, 255, 605, 310, 760, 460, 5)))then
begin
Result:=False;
Exit;
end;
Loc.x:=x;
Loc.y:=y;
Des.x:=MLx;
Des.y:=MLy;
Dis:=(Distance(x, y, MLx, MLy)*455)/8;
Angle:=Round(FindAngle(Loc, Des));
MoveMap(MLx, MLy);
Wait(2000+Random(1000));//IdleTime(2000, 1000, 7);
CloseMap;
end;
WriteLn(Floattostr(Angle));
case Dis of
0..400: RDis:=Dis;
401..899: RDis:=Round(Dis/2+50)+Random(100);
900..1600: RDis:=Round((Dis/2)+Random(100));
else RDis:=800+Random(100);
end;
Trav:=0;
repeat
begin
case RDis-Trav of
(0-10)..10:Stop:=True;
0..75:
begin
TDis:=RDis-Trav;
AngleWalk(Angle-4+Random(8), TDis);
end;
76..120:
begin
TDis:=Round(((RDis-Trav)/2)-5+Random(10));
AngleWalk(Angle-4+Random(8), TDis);
end;
else
begin
TDis:=45+Random(30);
AngleWalk(Angle-5+Random(10), TDis);
end;
end;
Trav:=Trav+TDis;
end;
until(Stop);
if(Check)then
begin
MakeCompassR('n');
for a:=0 to 15 do
begin
if(DTMRotated(MMDestinationDTM, x, y, MMX1, MMY1, MMX2, MMY2))then
begin
if(Distance(MMCX, MMCY, x, y)>20)then
begin
Mouse(x, y, 10, 10);
Wait(800+Random(400));
R_Flag;
end;
WriteLn('Arrived at destination');
Result:=True;
Exit;
end;
Wait(250);
end;
Check:=False;
end;
Wait(300+Random(500));
end;
until(false);
end;
begin
SMARTSetUp('world38', True, True, False);
SetTargetDC(SMARTGetDC);
SetupSRL;
SetupReflection;
ActivateClient;
WMDTM := DTMFromString('78DA639CCFC4C0C0C7C800024C0C10D0585BC' +
'6C00EA441A2FF8180712250460455CD993367E06A408071135046' +
'88809A354019595435B6B20CA86A960165D850D5009D80A20600F' +
'2E01161');
MMDTM := DTMFromString('78DA632C646260486700032608C5D05C5FC1C' +
'005A41981F83F10302600657250D5E4C6E8C2D580006323502617' +
'55CDDBA7EF50D5E402659C71DB05565386A906C31C907BBCF0AB0' +
'10096F1152C');
WorldMAPWalk(WMDTM, MMDTM, 698, 373);
FreeDTM(WMDTM);
FreeDTM(MMDTM);
end.Have Fun!
-Macrosoft