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 :).
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:
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!