Hi Nielsie, I really enjoyed reading through your script. I've been playing around with your WeightedPoint function, and would really like to use it in my scripts if that's ok, I've posted my implementation below. If not, no worries, I'll delete it. Looking forward to the transition to Lape!
program new;
{$DEFINE SMART}
{$i SRL\SRL.simba}
{$i srl\srl\misc\paintsmart.simba}
{$i 3DProjection.simba}
type
TLandmark = record
Func: function(out p: TPoint): Boolean;
OffSet: TPoint;
Weight: Integer;
end;
function WeightedPoint(Points: TPointArray; Weights: TIntegerArray): TPoint; // by nielsie95
var
i, Sum: Integer;
begin
Result := Point(0, 0);
if (Length(Points) <> Length(Weights)) then
Exit;
for i := 0 to High(Points) do
begin
Result.x := Result.x + Points[i].x * Weights[i];
Result.y := Result.y + Points[i].y * Weights[i];
Sum := Sum + Weights[i];
end;
if (Sum <> 0) then
begin
Result.x := Result.x div Sum;
Result.y := Result.y div Sum;
end
end;
function FindBankerDTM(out p: TPoint): Boolean;
var
DTM: Integer;
af: Extended;
begin
DTM := DTMFromString('mbQAAAHicY2VgYJjExMBQB8RVSFgeKO4DxAFAHAnEiQwQ8P87JwpWYGZgkGNAxYxYMBgAADDXDJ8=');
Result := FindDTMRotated(DTM, p.x, p.y, MMX1, MMY1, MMX2, MMY2, -Pi, Pi, Pi/60, af);
FreeDTM(DTM);
end;
function FindTreeAboveBank(out p: TPoint): Boolean;
var
i, c: Integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result := True;
FindColorsTolerance(tpa, 1400630, MMX1 + ((MMCX-MMX1) div 4)*3, MMY1, MMX2, MMY2, 20);
atpa := SplitTPA(tpa, 1);
c := 0;
SetLength(tpa, Length(atpa));
for i := 0 to High(atpa) do
begin
if Length(atpa[i]) < 6 then
Continue;
tpa[c] := MiddleTPA(atpa[i]);
Inc(c);
end;
SetLength(tpa, c);
SortTPAByY(tpa, True);
case Length(tpa) of
2: p := tpa[0];
3: p := tpa[1];
else Result := False;
end;
end;
function FindLadder(out p: TPoint): Boolean;
var
i, c: Integer;
tp: TPoint;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result := True;
FindColorsTolerance(tpa, 601946, MMX1, MMY1, MMX2, MMY2, 10);
atpa := SplitTPA(tpa, 2);
c := 0;
SetLength(tpa, Length(atpa));
for i := 0 to High(atpa) do
begin
if InRange(Length(atpa[i]), 10, 40) then
begin
tp := MiddleTPA(atpa[i]);
if rs_OnMinimap(tp.x, tp.y) then
begin
tpa[c] := tp;
Inc(c);
end;
end;
end;
SetLength(tpa, c);
SortTPAByX(tpa, True);
case Length(tpa) of
1: p := tpa[0];
2: p := tpa[1];
else Result := False;
end;
end;
function FindTwoTreesMP(out p: TPoint): Boolean;
var
i, c: Integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result := False;
FindColorsTolerance(tpa, 1400630, MMX1 + ((MMCX-MMX1) div 2), MMY1, MMX2, MMY2, 20);
atpa := SplitTPA(tpa, 1);
c := 0;
SetLength(tpa, Length(atpa));
for i := 0 to High(atpa) do
begin
if Length(atpa[i]) < 6 then
Continue;
tpa[c] := MiddleTPA(atpa[i]);
Inc(c);
end;
SetLength(tpa, c);
atpa := SplitTPA(tpa, 25);
c := 0;
for i := 0 to High(atpa) do
begin
if Length(atpa[i]) = 2 then
begin
Result := True;
tpa[c] := MiddleTPA(atpa[i]);
Inc(c);
end;
end;
SetLength(tpa, c);
SortTPAByX(tpa, True);
if Length(tpa) <> 0 then
p := tpa[0];
end;
function FindWallPoint(out p: TPoint): Boolean;
var
i, c: Integer;
tpa, Dots, Walls: TPointArray;
atpa: T2DPointArray;
begin
Result := True;
FindColorsTolerance(tpa, clWhite, MMX1, MMY1, MMX2, MMY2, 40);
Dots := GetMiniMapDots('white');
c := 0;
SetLength(Walls, Length(tpa));
for i := 0 to High(tpa) do
if not NearbyPointInArrayEx(tpa[i], 7, 7, Dots) then
begin
Walls[c] := tpa[i];
Inc(c);
end;
SetLength(Walls, c);
atpa := SplitTPA(tpa, 2);
SetLength(tpa, Length(atpa));
for i := 0 to High(atpa) do
tpa[i] := MiddleTPA(atpa[i]);
SortTPAByY(tpa, True);
if Length(atpa[0]) < 95 then
Result := False;
p := tpa[0];
end;
function FindBeaconSymbol(out p: TPoint): Boolean;
var
Bmp: Integer;
acc: Extended;
begin
Bmp := BitmapFromString(2, 4, 'meJzLyPTMyPRkZGAAoua2CUAUEhIJ' +
'RABVEwdr');
FindDeformedBitmapToleranceIn(Bmp, p.x, p.y, MMX1, MMY1, MMX2, MMY2, 10, 0, True, acc)
Result := acc > SymbolAccuracy;
FreeBitmap(Bmp);
end;
function OffsetPoint(p, Offset: TPoint): TPoint;
begin
Result := Point(p.x + Offset.x, p.y + Offset.y);
end;
function MFlag(x, y, rx, ry: Integer): Boolean;
var
xMod, yMod: Integer;
v: TVector;
begin
v := CreateVector(Point(x, y), Point(MMCX, MMCY), True);
xMod := Round(v.x);
yMod := Round(v.y);
Result := MouseFlagEx(x, y, rx, ry, xMod, yMod, 0, False, False);
end;
function WalkWeighted(wpa: Array of TLandmark): Boolean;
var
i, l: Integer;
p: TPoint;
WalkPoints: TPointArray;
Weights: TIntegerArray;
begin
Result := False;
l := Length(wpa);
SetLength(WalkPoints, l);
SetLength(Weights, l);
for i := 0 to High(wpa) do
if not wpa[i].Func(p) then
begin
Weights[i] := 0
end
else
begin
WalkPoints[i] := OffsetPoint(p, wpa[i].Offset);
Weights[i] := wpa[i].Weight;
end;
p := WeightedPoint(WalkPoints, Weights);
if p = Point(0, 0) then
Exit;
Result := MFlag(p.x, p.y, 3, 3);
end;
function IsIdle: Boolean;
begin
Result := not IsMoving;
end;
function CrossWall: Boolean;
var
i, t, t2: Integer;
p, w: TPoint;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result := False;
MarkTime(t);
repeat
if not FindWallPoint(w) then
Continue;
if not MMToMSTileEx(p.x, p.y, w.x, w.y, True, clWhite) then
if TimeFromMark(t) > 10000 then
Exit
else
Continue;
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(1.18, 2.0);
FindColorsTolerance(tpa, 4014664, p.x-80, p.y-80, p.x+80, p.y+80, 8);
SetColorToleranceSpeed(1);
SetColorspeed2Modifiers(0.2, 0.2)
atpa := TPAtoATPA(tpa, 50);
SetLength(tpa, Length(atpa));
for i := 0 to High(atpa) do
tpa[i] := MiddleTPA(atpa[i]);
SortTPAFrom(tpa, p);
for i := 0 to High(tpa) do
begin
MMouse(tpa[i].x, tpa[i].y, 4, 4);
Wait(600+ Random(200));
if CountColorTolerance(12896779, 6, 9, 198, 24, 45) > 160 then
begin
GetMousePos(p.x, p.y);
Mouse(p.x, p.y, 0, 0, mouse_Left);
if DidYellowClick then
Break;
MarkTime(t2);
repeat
FindWallPoint(p);
if WaitColor(251, 51, 2070783, 5, 100) then
begin
MouseBox(146, 249, 224, 290, mouse_Left); // turn back on Doomslayer in Lumbridge
end;
if TimeFromMark(t2) > 10000 then
Exit;
until p.y > MMCY;
if WaitFunc(@IsIdle, 150, 2000) then
Result := True;
Exit;
end;
end;
until False;
end;
function WalkToZam: Boolean;
var
LandMarks: Array of TLandmark;
begin
SetLength(LandMarks, 3);
LandMarks[0].Func := @FindTreeAboveBank;
LandMarks[0].OffSet := Point(14, -11);
LandMarks[0].Weight := 2;
LandMarks[1].Func := @FindLadder;
LandMarks[1].OffSet := Point(19, 24);
LandMarks[1].Weight := 1;
LandMarks[2].Func := @FindBankerDTM;
LandMarks[2].OffSet := Point(0, 0);
LandMarks[2].Weight := 3;
WalkWeighted(LandMarks);
SetLength(LandMarks, 4);
LandMarks[0].Func := @FindWallPoint;
LandMarks[0].OffSet := Point(6, 10);
LandMarks[0].Weight := 1;
LandMarks[1].Func := @FindTwoTreesMP;
LandMarks[1].OffSet := Point(20, -11);
LandMarks[1].Weight := 3;
LandMarks[2].Func := @FindLadder;
LandMarks[2].OffSet := Point(24, -35);
LandMarks[2].Weight := 2;
LandMarks[3].Func := @FindBeaconSymbol;
LandMarks[3].OffSet := Point(53, -10);
LandMarks[3].Weight := 2;
WalkWeighted(Landmarks);
Wait(RandomRange(600, 800));
CrossWall;
SetLength(LandMarks, 3);
LandMarks[0].Func := @FindBeaconSymbol;
LandMarks[0].OffSet := Point(75, -86);
LandMarks[0].Weight := 2;
LandMarks[1].Func := @FindTwoTreesMP;
LandMarks[1].OffSet := Point(37, -87);
LandMarks[1].Weight := 3;
LandMarks[2].Func := @FindLadder;
LandMarks[2].OffSet := Point(41, -112);
LandMarks[2].Weight := 2;
WalkWeighted(LandMarks);
end;
var
kk: TPoint;
begin
SMART_Server := 10;
SMART_Members := True;
SMART_Signed := True;
SetupSRL;
{
FindTreeAboveBank;
FindLadder;
FindBankerDTM;
FindWallPoint;
FindTwoTreesMP;
FindLadder;
FindBeaconSymbol;
FindMiningSymbol;
FindWaterPoint; }
//FindTreeAboveBank(kk);
//FindLadder(kk);
//FindTwoTreesMP(kk);
//FindWallPoint(kk);
//FindBeaconSymbol(kk);
WalkToZam;
end.