SRL Archive - SRL Archives

New AWESOME findObject


danrox2004

2007-10-07 08:54:19

function findObject(text: string; colors: array of integer): tPoint;
Description
Finds an object using hue, saturation and luminance with a given uptext and colors.
What it does
It calculates the best hue, saturation and luminance from the colors given, then finds the average color in red, green and blue. It uses this in a findColorsSpiralTolerance to get all the points with that color and j tolerance. It then sorts the array (rearrangeandshortenarray). For each of the points in the array it checks if it has seen it before (the ignore array). If it has then it goes onto the next point. If it hasnt it converts the color of the point into HSL and checks if it is in the range of the best hue saturation and luminance. If it is then it checks the spot for the object and uptext. If it finds it returns the coordinates. If it does not find the object then it adds the object to the ignore array so it doesnt check there again to avoid detectable mouse movements. It increases the range of the hue saturation and luminance as it goes, to find more points. (Wow that took alot to explain).

How to use it
To use it get an array of colors from different worlds and different angles of ONE part of the object. For instance if you were looking for a goblin, you would only get say the green color, not brown and green. Put in the uptext and your ready to go =)

If anyone has a better way to calculate the BestHSL then please tell me :).

program New;
{.include SRL/SRL.scar}

procedure bestHSL(colors: array of integer; var lh, ls, ll, mh, ms, ml : extended; range: integer);
var
i: integer;
h, s, l: extended;
begin
for i := 0 to length(colors) - 1 do
begin
colorToHSL(colors[i], h, s, l);
mh := maxE(h, mh);
ms := maxE(s, ms);
ml := maxE(l, ml);
lh := minE(h, lh);
ls := minE(s, ls);
ll := minE(l, ll);
if(i = 0) then
begin
lh := h;
ls := s;
ll := l;
end;
end;
//writeln('max: ' + floatToStr(mh) + ' - ' + floatToStr(ms) + ' - ' + floatToStr(ml));
//writeln('min: ' + floatToStr(lh) + ' - ' + floatToStr(ls) + ' - ' + floatToStr(ll));
//writeln('Best Hue: ' + floatToStr(maxE(lh -(mh - lh)/range, 0)) + ' to ' + floatToStr(minE(mh +(mh - lh)/range, 360)));
//writeln('Best Sat: ' + floatToStr(maxE(ls -(ms - ls)/range, 0)) + ' to ' + floatToStr(minE(ms +(ms - ls)/range, 100)));
//writeln('Best Lum: ' + floatToStr(maxE(ll -(ml - ll)/range, 0)) + ' to ' + floatToStr(minE(ml +(ml - ll)/range, 100)));
end;

function inRangeFloat(a, b, c: extended): Boolean;
begin
result := (a >= b) and (a <= c);
end;

function getAvgRGB(colors: array of integer): integer;
var
i, k: integer;
r, g, b: integer;
tr, tg, tb: integer;
begin
k := length(colors);
for i := 0 to k - 1 do
begin
colorToRGB(colors[i], tr, tg, tb);
r := r + tr;
g := g + tg;
b := b + tb;
end;
r := r / k;
g := g / k;
b := b / k;
result := RGBToColor(r, g, b);
end;

procedure addToTPointArray(var arr: array of tPoint; tp: tPoint);
var
i: integer;
begin
i := length(arr);
setLength(arr, i + 1);
arr[i] := tp;
end;

function findObject(text: string; colors: array of integer): tPoint;
var
h, s, l: extended;
lh, ls, ll: extended;
mh, ms, ml: extended;
avgColor: integer;
i, j, k: integer;
points: array of tPoint;
ignore: array of tPoint;
begin
avgColor := getAvgRGB(colors);
for i := 10 downto 1 do
begin
bestHSL(colors, lh, ls, ll, mh, ms, ml, i);
wait(2);
ignore := [];
for j := 0 to 40 do
begin
wait(2);
findColorsSpiralTolerance(MSCX, MSCY, points, avgColor, MSX1, MSY1, MSX2, MSY2, j);
points := reArrangeandShortenArray(points, 5);
for k := 0 to length(points) - 1 do
begin
if(nearbyPointInArray(points[k], 5, ignore)) then
continue;
wait(2);
colorToHSL(getColor(points[k].x, points[k].y), h, s, l);
if(inRangeFloat(h, lh, mh)) then
if(inRangeFloat(s, ls, ms)) then
if(inRangeFloat(l, ll, ml)) then
begin
mMouse(points[k].x, points[k].y, 0, 0);
wait(50 + random(100));
if(isUpText(text)) then
begin
result := points[k];
exit;
end;
end;
addToTPointArray(ignore, points[k]);
end;
end;
end;
end;

begin
setupSRL;
findObject('ones', [5592411, 12171714, 12764106, 10000805, 8355977, 10790064, 14211293, 11119028]);
end.

That example will try to find bones. Note the colors were only taken from one world and one angle, so it might not work that well…

EDIT: I think you can use it for finding npcs, objects, anything! I tested with bones, lobster pot, and Miss Schism in draynor and it found all the items and objects within 4 mouse movements. I expected it to take a while with Miss Schism because she is the same color as wizards robes, but it found her on the first try and did not get her mixed up with the people wearing wizards robes.

EDIT2: Seems to work REALLY well for banks too. Tested in draynor bank with:
findObject('ank', [4936537, 4936537, 5463907, 4936537, 5461593, 4937311]);
and it found the bank booth first time, 6 times in different worlds!

neG

2007-10-07 09:39:15

It sounds really impressive.
What kind of strain does this put on the computer, would older computers struggle with this?
Im going to have to learn how to use hue and luminance now, I feel left out ;)
Im sure this will be included in the next SRL :)

danrox2004

2007-10-07 09:40:56

From: neG
It sounds really impressive.
What kind of strain does this put on the computer, would older computers struggle with this?
Im going to have to learn how to use hue and luminance now, I feel left out ;)
Im sure this will be included in the next SRL :)


I'm not sure, it doesnt lag with my computer though. Maybe i should ask someone to put this into a plugin, that might improve speed.

Santa_Clause

2007-10-07 09:41:51

None at all, most of the stuff is done in WizzyPlugin :)

the scar noob

2007-10-07 09:49:56

Santa can say what he wants, I say it looks pretty cool ;)
Congratulations on making a such nice looking function!;)

-Tsn.

Santa_Clause

2007-10-07 09:54:54

I said a good thing : That it doesn't lag ;)

danrox2004

2007-10-07 09:55:34

Okay I did some tests, and for finding logs on the ground it takes between 110 - 140 ms, without moving the mouse, as this seems to be the biggest thing slowing it down. I think this could be reduced lots by putting it into a plugin.

the scar noob

2007-10-07 10:58:04

From: danrox2004
Okay I did some tests, and for finding logs on the ground it takes between 110 - 140 ms, without moving the mouse, as this seems to be the biggest thing slowing it down. I think this could be reduced lots by putting it into a plugin.


True and I also think I know someone that can help you:p
PM mastaraymond, I heard Ray can handle plugins:)

-Tsn.

BobboHobbo

2007-10-08 04:51:03

Works really well! Found the bank booth straight away good job!

Mind if i use this procedure's in my script? (ill credit and make it go off SCAR's screen so Non srl members dont see?)

danrox2004

2007-10-08 06:38:22

From: BobboHobbo
Works really well! Found the bank booth straight away good job!

Mind if i use this procedure's in my script? (ill credit and make it go off SCAR's screen so Non srl members dont see?)


Yeah, I dont mind if you use it in your script, thats what this sections for. Oh and i dont mind releasing to non srl members, i just couldnt find the right section in the non srl member forum.

EDIT: Is public test corner the right place? If so can a mod please move it there.

BobboHobbo

2007-10-08 07:17:17

From: danrox2004
Yeah, I dont mind if you use it in your script, thats what this sections for. Oh and i dont mind releasing to non srl members, i just couldnt find the right section in the non srl member forum.

EDIT: Is public test corner the right place? If so can a mod please move it there.


Kk thanks man :)

Home

2007-10-14 04:16:30

I will try use this for a OpenDoor in my seers spinner when i start doing it :)


~Home

n3ss3s

2007-10-14 04:46:53

Try to make it "perfect" so you dont need uptext checking, up text plain sucks :D

ShowerThoughts

2007-10-14 04:46:58

Home you stole my idea!!!

but is this already in the newest srl or not?
because i need a good door finding procedure :)

Hugolord

2007-10-14 04:58:34

From: n3ss3s
Try to make it "perfect" so you dont need uptext checking, up text plain sucks :D


you can always add a function to right click and check if it doesn't find the uptext after like 5 tries.. :D

mat_de_b

2007-10-14 07:55:47

Add an array of strings to search with

danrox2004

2007-10-14 09:28:13

From: mat_de_b
Add an array of strings to search with


Yeah I put that in my version because it helps when finding doors, for example:
function findObjectMultiText(text: array of string; colors: array of integer): tPoint;
var
h, s, l: extended;
lh, ls, ll: extended;
mh, ms, ml: extended;
avgColor: integer;
i, j, k: integer;
points: array of tPoint;
ignore: array of tPoint;
begin
bestHSL(colors, lh, ls, ll, mh, ms, ml, 5);
avgColor := getAvgRGB(colors);
for i := 10 downto 1 do
begin
wait(2);
ignore := [];
for j := 0 to 40 do
begin
wait(2);
findColorsSpiralTolerance(MSCX, MSCY, points, avgColor, MSX1, MSY1, MSX2, MSY2, j);
points := reArrangeandShortenArray(points, 5);
for k := 0 to length(points) - 1 do
begin
if(nearbyPointInArray(points[k], 5, ignore)) then
continue;
wait(2);
colorToHSL(getColor(points[k].x, points[k].y), h, s, l);
if(inRangeFloat(h, lh, mh)) then
if(inRangeFloat(s, ls, ms)) then
if(inRangeFloat(l, ll, ml)) then
begin
mMouse(points[k].x, points[k].y, 0, 0);
wait(100 + random(100));
if(isUpTextMultiCustom(text)) then
begin
result := points[k];
exit;
end;
end;
addToTPointArray(ignore, points[k]);
end;
end;
end;
end;
And use:

function openDoor: boolean;
var
tp: tPoint;
begin
tp := findObjectMultiText(['pen', 'lose'], OtherParams);
if(tp.x > 0) and (tp.y > 0) then
begin
if(isUpText('pen')) then
begin
mouse(tp.x, tp.y, 0, 0, false);
result := chooseOption('pen');
end;
end;
end;
Something like that

mat_de_b

2007-10-14 09:42:46

Another idea is to make the parameters
function findObjectMultiText(var Point:Tpoint; text: array of string; colors: array of integer): boolean;
so you can call
if (FindObjectMultiText)then