SRL Archive - SRL Archives

FindNearestObj - Dont just sit there! Come see!


n3ss3s

2007-06-20 09:02:44

FindNearestObj

What it is, what it does and WHY IT DOES -

* It is another object finding function with 3 different text and color params.
* The difference to FindObj is that it looks for the closest object identified by Color1,Color2,Color3 and Text1,Text2,Text3 , StartTol and MaxTol within the range in pixels from MainScreen center defined in "MaxDist"

*WHY? Because some times you need to look for an object near you as possible.
Good example is flax picking - It looks very botty if the character runs around the flax field picking different flaxes with like 7 tiles distance.
Also, if mining rocks and you dont want it to mess someones characters hair or something.

Works good for me and should work for you too.


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

function FindNearestObj(var Nx, Ny: integer; Color1, Color2, Color3,
StartTol, MaxTol, MaxDist: integer; Text1, Text2, Text3: string): boolean;
var i, j: integer;
begin
if (not (LoggedIn)) then Exit;
for j := 5 to MaxDist do
begin
for i := StartTol to MaxTol do
begin
if (FindColorTolerance(x, y, Color1, MSCX - j, MSCY - j, MSCX + j, MSCY + j, I))
or (FindColorTolerance(x, y, Color2, MSCX - j, MSCY - j, MSCX + j, MSCY + j, I))
or (FindColorTolerance(x, y, Color3, MSCX - j, MSCY - j, MSCX + j, MSCY + j, I)) then
begin
Break;
MMouse(x, y, 0, 0);
if (IsUpText(Text1))
or (IsUpText(Text2))
or (IsUpText(Text3)) then
begin
GetMousePos(Nx, Ny);
Result := True;
Break;
end;
end;
end;
end;
end;
// Example below
begin
setupsrl;
FindNearestObj(x, y, 15197342, 14999694, 14868361, 10, 50, 300, 'Flax', 'Fla', 'lax');
MMouse(x, y, 0, 0);
end.
// End Example

That example in mainloop works at flaxfield. Change the 300 (MaxDist) to your liking.

nielsie95

2007-06-20 09:19:38

Nice :)
IsUpTextMulti? :)
And maybe a TolStepSize?

n3ss3s

2007-06-20 09:59:36

Both was in my mind but I watched south park and forgot :D
Ill put them in there soon.

n3ss3s

2007-06-20 10:21:11

omfg 1337? I was testing again on flaxes and it moved to mouse on an empty tile and I was like WTF but after 1 sec a flax spawned there?!

Bobarkinator

2007-06-20 10:30:00

Lol this function tells the future.

n3ss3s

2007-06-20 10:37:48

Yea, very useful for autofighter to know when to eat :)