SRL Archive - Senior Scripts and Snippets

FindLadder - 99% PERFECT!


shaunthasheep

2007-08-13 11:25:53

Finds ladders, no autocoloring, pretty fast, less then 5 seconds.
It shouldn't get confused with anything, except maybe a darkbrown house barely on the minimap. Works perfect for me everytime though, searches from left to right, so if you want to use it, and have a better percentage of finding the ladder, make sure the ladder is closest to the upper left corner. So adjust your compass to the right angle.

I made FindLadderSkipBoxIn so people can use this to find all the ladders on the minimap, just SkipBox over the last ladder.
Also theres just a simple FindLadder(var x, y);
Test Please :)

btw lines 58 and 59 are for debugging purposes!
SCROLL DOWN FOR A FIXED (kinda) Version
program New;

function FindLadderSkipBoxIn(var x, y : integer; x1, y1, x2, y2 : integer; Skipboxes : TBoxArray) : boolean;
var
bmpLadder, MiniMap : integer;
H, xx, yy, i, laddercolor : integer;
F : TPoint;
a : extended;
MiniMapCanvas : TCanvas;
LadderTPA : TPointArray;
begin
bmpLadder := BitmapFromString2(False, 'a9594178DAD58D3B1280' +
'300844AF04849FA54673FF23C9DAA4D199B4523C66761E2C11313' +
'3D5F45130EBE0F0A20B629544A2171839998FD3E04BEAEBAD2756' +
'B4130C2446703CD0E8BB4E1E066783CF0D5D3C48BB54BAC2AF59F' +
'FF0C73F37D8F');

Minimap := BitmapFromString(iAbs(x2 - x1), iAbs(y2 - y1), '');
CopyClientToBitmap(Minimap, x1, y1, x2, y2);

H := GetClientWindowHandle;
SetTargetBitmap(Minimap);
MiniMapCanvas := GetBitmapCanvas(bmpLadder);
MiniMapCanvas.Brush.Color := 0;
MiniMapCanvas.Pen.Color := 0;

for i := 0 to Length(SkipBoxes) - 1 do
begin
MiniMapCanvas.Rectangle(SkipBoxes[i].x1, SkipBoxes[i].y1, SkipBoxes[i].x2, SkipBoxes[i].y2);
end;

repeat
if FindDeformedBitmapToleranceIn(bmpLadder, F.x, F.y, 0, 0, iAbs(x2 - x1), iAbs(y2 - y1), 60, 3, False, a) then
begin
if rs_OnMinimap(F.x + x1, F.y + y1) then
begin
if FindColorTolerance(xx, yy, 9548, F.x - 7, F.y - 7, F.x + 7, F.y + 7, 60) then
begin
laddercolor := FastGetPixel(Minimap, xx, yy);
FindColorsTolerance(LadderTPA, laddercolor, F.x - 7, F.y - 7, F.x + 7, F.y + 7, 0);
if (laddercolor <> 2040096) and (Length(LadderTPA) < 35) and (Length(LadderTPA) > 15) then
begin
Result := True;
SetClientWindowHandle(H);
x := F.x + 3 + x1;
y := F.y + 3 + y1;
FreeBitmap(Minimap);
FreeBitmap(bmpLadder);
Exit;
end;
end;
end;
for xx := 0 to 9 do
for yy := 0 to 9 do
if ((F.x + xx) > 0) and ((F.y + yy) > 0) then
if ((F.x + xx) < (x2 - x1)) and ((F.y + yy) < (y2 - y1)) then
FastSetPixel(Minimap, F.x + xx, F.y + yy, 0);
DisplayDebugImgWindow(x2 - x1, y2 - y1);
SafeDrawBitmap(MiniMap, GetDebugCanvas, 0, 0);
end else
begin
SetClientWindowHandle(H);
//We failed to find ladder.
FreeBitmap(Minimap);
FreeBitmap(bmpLadder);
Exit;
end;
until False
end;


function FindLadder(var x, y : integer) : boolean;
var
ETBA : TBoxArray;
begin
result := FindLadderSkipBoxIn(x, y, MMX1, MMY1, MMX2, MMY2, ETBA);
end;

var
x, y : integer;
SkipBoxes : TBoxArray;

begin
if FindLadder(x, y) then
MoveMouse(x, y);
end.

EDIT: editted the script just a tiny bit after posting it, nothing major, just uncommented 1 thing and got rid of 1 line that got there while debugging a error.

Ejjman

2007-08-13 12:22:55

Hm, it blocked out most of the area, well, 1/3 of it, then it would fail (not move mouse). I don't know. Sorry man :S

shaunthasheep

2007-08-13 12:50:51

i updated a bit, may work for you now.
lowered tolerance, lessened deformed range.
some other stuff. Hope this works for you now.
Thinks dead trees are ladders.

function FindLadderSkipBoxIn(var x, y : integer; x1, y1, x2, y2 : integer; Skipboxes : TBoxArray) : boolean;
var
bmpLadder, MiniMap : integer;
H, xx, yy, i, laddercolor : integer;
F : TPoint;
a : extended;
MiniMapCanvas : TCanvas;
LadderTPA : TPointArray;
begin
bmpLadder := BitmapFromString2(False, 'a9594178DAD58D3B1280' +
'300844AF04849FA54673FF23C9DAA4D199B4523C66761E2C11313' +
'3D5F45130EBE0F0A20B629544A2171839998FD3E04BEAEBAD2756' +
'B4130C2446703CD0E8BB4E1E066783CF0D5D3C48BB54BAC2AF59F' +
'FF0C73F37D8F');

Minimap := BitmapFromString(iAbs(x2 - x1), iAbs(y2 - y1), '');
CopyClientToBitmap(Minimap, x1, y1, x2, y2);

H := GetClientWindowHandle;
SetTargetBitmap(Minimap);
MiniMapCanvas := GetBitmapCanvas(bmpLadder);
MiniMapCanvas.Brush.Color := 0;
MiniMapCanvas.Pen.Color := 0;

for i := 0 to Length(SkipBoxes) - 1 do
begin
MiniMapCanvas.Rectangle(SkipBoxes[i].x1, SkipBoxes[i].y1, SkipBoxes[i].x2, SkipBoxes[i].y2);
end;

repeat
if FindDeformedBitmapToleranceIn(bmpLadder, F.x, F.y, 0, 0, iAbs(x2 - x1), iAbs(y2 - y1), 50, 3, False, a) then
begin
if rs_OnMinimap(F.x + x1, F.y + y1) then
begin
if FindColorTolerance(xx, yy, 9548, F.x - 7, F.y - 7, F.x + 7, F.y + 7, 50) then
begin
laddercolor := FastGetPixel(Minimap, xx, yy);
FindColorsTolerance(LadderTPA, laddercolor, F.x - 5, F.y - 5, F.x + 11, F.y + 11, 0);
if (laddercolor <> 2040096) and (laddercolor <> 4543328) and (Length(LadderTPA) < 35) and (Length(LadderTPA) > 15) then
begin
Result := True;
SetClientWindowHandle(H);
for i := 0 to Length(LadderTPA) - 1 do
begin
x := LadderTPA[i].x + x;
y := LadderTPA[i].y + y;
end;
x := (x / Length(LadderTPA)) + x1;
y := (y / Length(LadderTPA)) + y1;
FreeBitmap(Minimap);
FreeBitmap(bmpLadder);
Exit;
end;
end;
end;
for xx := 0 to 7 do
for yy := 0 to 7 do
if ((F.x + xx) > 0) and ((F.y + yy) > 0) then
if ((F.x + xx) < (x2 - x1)) and ((F.y + yy) < (y2 - y1)) then
FastSetPixel(Minimap, F.x + xx, F.y + yy, 0);
DisplayDebugImgWindow(x2 - x1, y2 - y1);
SafeDrawBitmap(MiniMap, GetDebugCanvas, 0, 0);
end else
begin
SetClientWindowHandle(H);
//We failed to find ladder.
FreeBitmap(Minimap);
FreeBitmap(bmpLadder);
Exit;
end;
until False
end;