SRL Archive - SRL Archives

FastFindLadderColor and FindLaddersIn


nielsie95

2007-10-02 15:23:06

Hey,

I made this for my Lumbridge script. It does practically what it says; it finds the laddercolor on the minimap (and fast :p). Works great for me and takes about 15ms.


function FastFindLadderColor: Integer;
var
i, c, n, bmp, Handle, cts:Integer;
p: TPointArray;
ca: TIntegerArray;
pa: TPointArrayArray;
W, H, S, L: Extended;
begin
if (not LoggedIn) then Exit;
bmp := BitmapFromString(MMX2 - MMX1, MMY2 - MMY1, '');
CopyClientToBitmap(bmp, MMX1, MMY1, MMX2, MMY2);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
Handle := GetClientWindowHandle;
SetTargetBitmap(bmp);
FindColorsSpiralTolerance(MMCX - MMX1, MMCY - MMY1, p, 79973, 0, 0, MMX2 - MMX1, MMY2 - MMY1, 55);
pa := SplitTPAEx(p, 2, 2);
n := Length(pa) -1;
SortATPAFromSize(pa, 32, True);
for i := 0 to n do
if (Length(pa[i]) > 15) and (Length(pa[i]) < 42) then
begin
c := FastGetPixel(bmp, pa[i][0].x, pa[i][0].y);
//WriteLn(IntToStr(c)+' '+IntToStr(Length(pa[i])));
ColorToHSL(c, H, S, L);
if (H < 11.0) and (H > 4.5) then
if (L < 30.0) and (L > 10.0) then
begin
ca := GetColors(pa[i]);
ClearSameIntegers(ca);
if (Length(ca) = 1) then
begin
p := ReArrangeTPA(pa[i], 0, Length(pa[i]), True, True);
w := Abs(p[0].x - p[Length(p) -2].x);
p := ReArrangeTPA(pa[i], 0, Length(pa[i]), False, True);
h := Abs(p[0].y - p[Length(p) -2].y);
WriteLn('Color: '+IntToStr(c)+'w: '+FloatToStr(w)+' h: '+ FloatToStr(h));
WriteLn('ratio: '+FloatToStr(MaxE(w, h) div MinE(w, h)));
if (MaxE(w, h) div MinE(w, h) >= 1.12) and (MaxE(w, h) div MinE(w, h) <= 1.8) then
begin
Result := c;
Break;
end;
end;
end;
end;
SetLength(p, 0);
SetLength(pa, 0);
SetClientWindowHandle(Handle);
FreeBitmap(bmp);
ColorToleranceSpeed(cts);
end;

FindLaddersIn also does what it says. It finds all the ladders in an area on the minimap :)


function FindLaddersIn(x1, y1, x2, y2: Integer): TPointArray;
var
i, n, bmp, Handle, cts, x, y, r:Integer;
p: TPointArray;
pa: TPointArrayArray;
W, H: Extended;
begin
if (not LoggedIn) then Exit;
if (LadderColor = 0) or (not FindColor(x, y, LadderColor, MMX1, MMY1, MMX2, MMY2)) then
LadderColor := FastFindLadderColor;
bmp := BitmapFromString(x2 - x1, y2 - y1, '');
CopyClientToBitmap(bmp, x1, y1, x2, y2);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
Handle := GetClientWindowHandle;
SetTargetBitmap(bmp);
FindColorsSpiralTolerance(((x1 + x2) / 2) - x1, ((y1 + y2) / 2) - y1, p, LadderColor, 0, 0, x2 - x1, y2 - y1, 0);
pa := SplitTPAEx(p, 2, 2);
n := Length(pa) -1;
SortATPAFromSize(pa, 32, True);
for i := 0 to n do
if (Length(pa[i]) > 20) and (Length(pa[i]) < 42) then
begin
{p := ReArrangeTPA(pa[i], 0, Length(pa[i]), True, True);
w := Abs(p[0].x - p[Length(p) -2].x);
p := ReArrangeTPA(pa[i], 0, Length(pa[i]), False, True);
h := Abs(p[0].y - p[Length(p) -2].y);
if ((MaxE(w, h) div MinE(w, h)) >= 1.12) and ((MaxE(w, h) div MinE(w, h)) <= 1.8) then
begin}
SetLength(Result, r +1);
Result[r] := MiddleTPA(pa[i]);
IncEx(Result[r].x, x1);
IncEx(Result[r].y, y1);
Inc(r);
//end;
end;
SetLength(p, 0);
SetLength(pa, 0);
SetClientWindowHandle(Handle);
FreeBitmap(bmp);
ColorToleranceSpeed(cts);
end;

Please post bugs/improvements/suggestions :)

Nielsie95

Wizzup?

2007-10-02 16:09:57

Very nice. :)

the scar noob

2007-10-02 16:33:17

Indeed Wizzup? this is nice.
Can I ask some questions?
a.)Am I right that Abs get the abstract value?
b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
c.)What does ReArrangeTPA do?
d.)Xhat does SetClientWindowHandle do?

If possible can you explain me??
My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people :)

Thanks in advance,

Stijn.

Markus

2007-10-02 16:36:46

From: the scar noob
Indeed Wizzup? this is nice.
a.)Am I right that Abs get the abstract value?
It just converts a negative number in a positive one.
b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
Yes
d.)Xhat does SetClientWindowHandle do?
The window handle (Id of a (part) window) gets set (it'll tell scar use the window with that ID)

:f:
Lemme study this a bit first, all that TPA stuff gets confusing after a while.
edit: this gets the laddercolor by looking at the ratio of a ladder? If so wow, never saw something like that before.

WT-Fakawi

2007-10-02 16:44:01

Very sophisticated. I am glad to see you have outmastered me :)

ShowerThoughts

2007-10-02 17:09:39

i got headache i can dream about i am so good as fawk someday

mastaraymond

2007-10-02 17:11:27

Well done ;).

Lorax

2007-10-02 17:16:07

great, very usefull..

ShowerThoughts

2007-10-02 17:16:28

From: hermpie
i got headache, i can dream about i am so good as fawk someday


nielsie i wont forget you :p

SKy Scripter

2007-10-02 17:24:21

From: the scar noob
Indeed Wizzup? this is nice.
Can I ask some questions?
a.)Am I right that Abs get the abstract value?
b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
c.)What does ReArrangeTPA do?
d.)Xhat does SetClientWindowHandle do?

If possible can you explain me??
My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people :)

Thanks in advance,

Stijn.



1 : Absolute Value

3 : put the points in order

4 : sets your client back to rs.

WT-Fakawi

2007-10-02 17:49:50

From: WT-Fakawi
Very sophisticated. I am glad to see you have outmastered me :)


Correction: As most of you have done, btw!

The Claw

2007-10-03 01:37:26

wow great stuff

Santa_Clause

2007-10-03 02:03:04

From: WT-Fakawi
Correction: As most of you have done, btw!


Hah! You obviously underestimate yourself, sir.

nielsie95

2007-10-03 04:18:14

Thanks for the nice comments all :)

From: the scar noob
Indeed Wizzup? this is nice.
Can I ask some questions?
a.)Am I right that Abs get the abstract value?
b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
c.)What does ReArrangeTPA do?
d.)Xhat does SetClientWindowHandle do?

If possible can you explain me??
My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people :)

Thanks in advance,

Stijn.



a.) Yes
b.) The colorfinding funtions, yes.
c.) Exactly as it says; it arranges your TPA by x or y, up or down.
d.) Sets the client back to then window instead of the bitmap.

Run the script beneath to find out more.


program new;

var
i: Integer;
p, tp: TPointArray;
begin
WriteLn('Abs -10.0 = '+FloatToStr(Abs(-10.0))+', Abs 10.0 = '+ FloatToStr(Abs(10.0)));
//iAbs for integers..
WriteLn(' ');
SetLength(p, 10);
SetLength(tp, 10);
for i := 0 to 9 do
begin
p[i] := Point(Random(100), Random(100));
tp[i] := p[i];
end;
WriteLn('Arranging the TPA..');
ReArrangeTPA(tp, 0, High(tp), True, True);
for i := 0 to 9 do
WriteLn('before x:'+IntToStr(p[i].x)+' y: '+IntToStr(p[i].y)+' after x: '+IntToStr(tp[i].x)+' y: '+IntToStr(tp[i].y));
end.

pwnaz0r

2007-10-03 10:57:12

very nice. thats all there is to it

Rikje

2007-10-03 11:38:44

looks realy nice. dont understand it atm :confused:

it resurns the color right?. meh,, tryed it in the guild. dind't work..