SRL Archive - SRL Archives

FindObjCustomEx / FindObjCustomCArray


Special Ed

2007-10-28 01:18:37

Well this is the technique that I use for finding fishing spots, and I've also used the same technique for finding Rocks, Trees, ect. So I worked for a bit and Made it as universal as I could. Credits to Boreas for helping with Removing Duplicates from an Array.

program New;
{.include SRL/SRL.scar}
var
Ox, Oy: Integer;
Color, Tolerance, CTS: array [0..1] of Integer;

{
Name: FindObjCustomEx
By: Special Ed
Description: Finds and Object using one Color and returns its Coordinates.
Vars:
Ox, Oy - The "Center" of the Object.
Color, Tolerance, ColorTolSpeed - Self Explanitory.
MaxHeight, MaxWidth - The Height and Width of the Object, Ex. Fishing Spots are normally 25, 27.
MaxCount - Max Points it should find using FindColors, Trial and error when finding it.
MinCount - Minimun Points it should find Using FindColors, Keeps out pieces of Armor, ect.
MaxTries - Number of Times it should try to find the Obj, Normally I use 3.
Spiral - Whether or not to Sprial out from Ox, Oy or not.
}

function FindObjCustomEx(var Ox, Oy: Integer; Color: Integer; Tolerance, ColorTolSpeed: Byte; MaxHeight, MaxWidth, MinCount, MaxCount, MaxTries: SmallInt; Spiral: Boolean): Boolean;
var
Top, Bottom, Right, Left, Tries, CCount, ArrayLength, pFindDups, pBubbleUp: SmallInt;
i, CTS: Byte;
NewCol: Boolean;
Sear, ObjectArea: TBox;
Cx, Cy: array of Integer;
CArr, CArr2: array of TPoint;
BoxMod, tpSwap: TPoint;
label Start;
begin
if(not(LoggedIn))then Exit;
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(ColorTolSpeed);
Start:
for i:= 1 to 10 do
begin
Sear.x1:= MSCX - Ceil(i * 51.3);
Sear.y1:= MSCY - Ceil(i * 33.5);
Sear.x2:= MSCX + Ceil(i * 51.3);
Sear.y2:= MSCY + Ceil(i * 33.5);
Ox:= MSCX;
Oy:= MSCY;
if(Spiral)then Result:= FindColorSpiralTolerance(Ox, Oy, Color, Sear.x1, Sear.y1, Sear.x2, Sear.y2, Tolerance)else
Result:= FindColorTolerance(Ox, Oy, Color, Sear.x1, Sear.y1, Sear.x2, Sear.y2, Tolerance);
if(Result)then
begin
BoxMod.x:= MaxWidth div 2;
BoxMod.y:= MaXHeight div 2;
ObjectArea.x1:= Ox - BoxMod.x;
ObjectArea.y1:= Oy - BoxMod.y;
ObjectArea.x2:= Ox + BoxMod.x;
ObjectArea.y2:= Oy + BoxMod.y;
FindColorsTolerance(CArr, Color, ObjectArea.x1, ObjectArea.y1, ObjectArea.x2, ObjectArea.y2, Tolerance);
SetArrayLength(Cx, Length(CArr));
SetArrayLength(Cy, Length(CArr));
for i:= 0 to Length(CArr) - 1 do
begin
Cx[i]:= CArr[i].x;
Cy[i]:= CArr[i].y;
end;
BubbleSort(Cx);
BubbleSort(Cy);
Left:= Cx[0];
Right:= Cx[GetArrayLength(CArr) - 1];
Top:= Cy[0];
Bottom:= Cy[GetArrayLength(CArr) - 1];
FindColorsTolerance(CArr2, Color, Left - BoxMod.x, Top - BoxMod.y, Right + BoxMod.x, Bottom + BoxMod.y, Tolerance);
CArr:= CombineTPA(CArr, CArr2);
ArrayLength:= GetArrayLength(CArr);
CArr:= RearrangeTPA(CArr, 0, ArrayLength - 1, True, True);
for pFindDups:= 0 to ArrayLength - 2 do
begin
if(CArr[pFindDups].x = CArr[pFindDups + 1].x) then
begin
if(CArr[pFindDups].y = CArr[pFindDups + 1].y)then
begin
for pBubbleUp:= pFindDups to ArrayLength - 2 do
begin
tpSwap:= CArr[pBubbleUp];
CArr[pBubbleUp]:= CArr[pBubbleUp + 1];
CArr[pBubbleUp + 1]:= tpSwap;
end;
ArrayLength:= ArrayLength - 1;
SetArrayLength(CArr, ArrayLength);
end;
end;
end;
CCount:= GetArrayLength(CArr);
if(CCount < MinCount)or(CCount > MaxCount)then
begin
if(Tries = MaxTries)then
begin
Result:= False;
NewCol:= False;
Exit;
end;
Result:= False;
NewCol:= True;
Inc(Tries);
Break;
end else
begin
Result:= True;
NewCol:= False;
Break;
end;
end;
end;
if(Result)then
begin
SetArrayLength(Cx, Length(CArr));
SetArrayLength(Cy, Length(CArr));
for i:= 0 to Length(CArr) - 1 do
begin
Cx[i]:= CArr[i].x;
Cy[i]:= CArr[i].y;
end;
BubbleSort(Cx);
BubbleSort(Cy);
Ox:= (Cx[0] + Cx[GetArrayLength(CArr) - 1]) div 2;
Oy:= (Cy[0] + Cy[GetArrayLength(CArr) - 1]) div 2;
Result:= True;
end else Result:= False;
if(NewCol)then goto Start;
ColorToleranceSpeed(CTS);
end;

{
Name: FindObjCustomCArray
By: Special Ed
Description: Finds and Object using multiple Colors and returns its Coordinates.
Vars:
Ox, Oy - The "Center" of the Object.
Color, Tolerance, ColorTolSpeed - All are arrays of Integer, each corrisponds with itself,
this provides more accurate finding.
MaxHeight, MaxWidth - The Height and Width of the Object, Ex. Fishing Spots are normally 25, 27.
MaxCount - Max Points it should find using FindColors, Trial and error when finding it.
MinCount - Minimun Points it should find Using FindColors, Keeps out pieces of Armor, ect.
MaxTries - Number of Times it should try to find the Obj, Normally I use 3.
Spiral - Whether or not to Sprial out from Ox, Oy or not.
}

function FindObjCustomCArray(var Ox, Oy: Integer; Color, Tolerance, ColorTolSpeed: array of Integer; MaxHeight, MaxWidth, MinCount, MaxCount, MaxTries: SmallInt; Spiral: Boolean): Boolean;
var
Tries, CCount, ArrayLength, pFindDups, pBubbleUp: SmallInt;
i, CTS, a: Byte;
NewCol: Boolean;
Sear, ObjectArea: TBox;
Cx, Cy: array of Integer;
CArr, CArr2: array of TPoint;
CArrX: array [0..1] of array of TPoint;
BoxMod, tpSwap: TPoint;
label Start;
begin
if(not(LoggedIn))then Exit;
CTS:= GetColorToleranceSpeed;
Start:
for i:= 1 to 10 do
begin
Sear.x1:= MSCX - Ceil(i * 51.3);
Sear.y1:= MSCY - Ceil(i * 33.5);
Sear.x2:= MSCX + Ceil(i * 51.3);
Sear.y2:= MSCY + Ceil(i * 33.5);
Ox:= MSCX;
Oy:= MSCY;
if(Spiral)then
begin
for i:= 0 to GetArrayLength(Color) - 1 do
begin
ColorToleranceSpeed(ColorTolSpeed[i]);
if(FindColorSpiralTolerance(Ox, Oy, Color[i], Sear.x1, Sear.y1, Sear.x2, Sear.y2, Tolerance[i]))then
begin
Result:= True;
Break;
end;
end;
end else
begin
for i:= 0 to GetArrayLength(Color) - 1 do
begin
ColorToleranceSpeed(ColorTolSpeed[i]);
if(FindColorTolerance(Ox, Oy, Color[i], Sear.x1, Sear.y1, Sear.x2, Sear.y2, Tolerance[i]))then
begin
Result:= True;
Break;
end;
end;
end;
if(Result)then
begin
BoxMod.x:= MaxWidth div 2;
BoxMod.y:= MaXHeight div 2;
ObjectArea.x1:= Ox - BoxMod.x;
ObjectArea.y1:= Oy - BoxMod.y;
ObjectArea.x2:= Ox + BoxMod.x;
ObjectArea.y2:= Oy + BoxMod.y;
for i:= 0 to GetArrayLength(Color) - 1 do
begin
ColorToleranceSpeed(ColorTolSpeed[i]);
FindColorsTolerance(CArrX[a], Color[i], ObjectArea.x1, ObjectArea.y1, ObjectArea.x2, ObjectArea.y2, Tolerance[i]);
SetArrayLength(CArr, GetArrayLength(CArrX[0]) + GetArrayLength(CArrX[1]));
for i:= 0 to GetArrayLength(CArrX[0]) - 1 do
CArr[i]:= CArrX[0][i];
for i:= GetArrayLength(CArrX[0]) to GetArrayLength(CArrX) - 1 do
CArr[i]:= CArrX[1][i];
a:= a + 1;
if(a = 2)then a:= a xor a;
end;
SetArrayLength(Cx, Length(CArr));
SetArrayLength(Cy, Length(CArr));
for i:= 0 to Length(CArr) - 1 do
begin
Cx[i]:= CArr[i].x;
Cy[i]:= CArr[i].y;
end;
BubbleSort(Cx);
BubbleSort(Cy);
ObjectArea.x1:= Cx[0];
ObjectArea.y1:= Cy[0];
ObjectArea.x2:= Cx[GetArrayLength(CArr) - 1];
ObjectArea.y2:= Cy[GetArrayLength(CArr) - 1];
for i:= 0 to GetArrayLength(Color) - 1 do
begin
ColorToleranceSpeed(ColorTolSpeed[i]);
FindColorsTolerance(CArrX[a], Color[i], ObjectArea.x1, ObjectArea.y1, ObjectArea.x2, ObjectArea.y2, Tolerance[i]);
SetArrayLength(CArr2, GetArrayLength(CArrX[0]) + GetArrayLength(CArrX[1]));
for i:= 0 to GetArrayLength(CArrX[0]) - 1 do
CArr2[i]:= CArrX[0][i];
for i:= GetArrayLength(CArrX[0]) to GetArrayLength(CArrX) - 1 do
CArr2[i]:= CArrX[1][i];
a:= a + 1;
if(a = 2)then a:= a xor a;
end;
CArr:= CombineTPA(CArr, CArr2);
ArrayLength:= GetArrayLength(CArr);
CArr:= RearrangeTPA(CArr, 0, ArrayLength - 1, True, True);
for pFindDups:= 0 to ArrayLength - 2 do
begin
if(CArr[pFindDups].x = CArr[pFindDups + 1].x) then
begin
if(CArr[pFindDups].y = CArr[pFindDups + 1].y)then
begin
for pBubbleUp:= pFindDups to ArrayLength - 2 do
begin
tpSwap:= CArr[pBubbleUp];
CArr[pBubbleUp]:= CArr[pBubbleUp + 1];
CArr[pBubbleUp + 1]:= tpSwap;
end;
ArrayLength:= ArrayLength - 1;
SetArrayLength(CArr, ArrayLength);
end;
end;
end;
CCount:= GetArrayLength(CArr);
if(CCount < MinCount)or(CCount > MaxCount)then
begin
if(Tries = MaxTries)then
begin
Result:= False;
NewCol:= False;
Exit;
end;
Result:= False;
NewCol:= True;
Inc(Tries);
Break;
end else
begin
Result:= True;
NewCol:= False;
Break;
end;
end;
end;
if(Result)then
begin
SetArrayLength(Cx, Length(CArr));
SetArrayLength(Cy, Length(CArr));
for i:= 0 to Length(CArr) - 1 do
begin
Cx[i]:= CArr[i].x;
Cy[i]:= CArr[i].y;
end;
BubbleSort(Cx);
BubbleSort(Cy);
Ox:= (Cx[0] + Cx[GetArrayLength(CArr) - 1]) div 2;
Oy:= (Cy[0] + Cy[GetArrayLength(CArr) - 1]) div 2;
Result:= True;
end else Result:= False;
if(NewCol)then goto Start;
ColorToleranceSpeed(CTS);
end;

{Should find A Fishing Spot, I know the first one works, but the second is untested}
begin
SetupSRL;
Wait(1000);
if(FindObjCustomEx(Ox, Oy, 14858393, 33, 0, 22, 22, 3, 60, 5, True))then
MMouse(Ox, Oy, 0, 0);
Color[0]:= 14796708;
Tolerance[0]:= 10;
CTS[0]:= 0;
Color[1]:= 15123625;
Tolerance[1]:= 12;
CTS[1]:= 1;
if(FindObjCustomCArray(Ox, Oy, Color, Tolerance, CTS, 22, 22, 3, 60, 3, True))then
MMouse(Ox, Oy, 0, 0);
end.

n3ss3s

2007-10-28 05:32:51

Gotta say that it looks just amazing =)

Do you know how fast average it is?

Special Ed

2007-10-28 12:18:44

Well for the First one, Looking for fishing Spots it gets around… 8 - 30ms depending on how far you are away, for the first one looking for Coal it took 12 - 40ms to find them. The second one I have yet to test but I'm guessing probably double those numbers.

the scar noob

2007-10-28 14:59:21

IT looks really nice, great work!
I wish I had that much experience as you have:p

-Tsn.

Special Ed

2007-11-04 12:01:02

Yes, as both of you have said, it "looks" amazing, has anyone even tried it yet? :D

EDIT: Bump? 1 Week, 2 replies, not one thing that is helpful? Jeeze… I didn't know it was that bad :p

P.S. Or are you just sick of ObjFinders?

R0b0t1

2007-11-04 21:11:34

I think object finders are … complete?

Special Ed

2007-11-04 21:40:43

From: R0b0t1
I think object finders are … complete?


NEVER! You always need more object finder's *twitch**twitch* right n3ss3s?

Also that was a really, really pointless post, you could of at least made something up like "Yep, tried it and it works, GG nub!" or something, at least that would have made me feel special :D

King of Knives

2007-11-05 07:06:42

Yep, tried it and it works, GG nub!

(Haha :P I haven't tried it. I mostly use colors for object-finding, though, so I won't really use it.)

-Knives

gerauchert

2007-11-05 07:36:04

looks usefull, im on a mac at school atm, cant exactly test it, but I may be able to during web page design….

good work ;)

Special Ed

2007-11-05 16:15:18

From: King of Knives
Yep, tried it and it works, GG nub!

(Haha :P I haven't tried it. I mostly use colors for object-finding, though, so I won't really use it.)

-Knives


Umm… it uses colors… and it is an object finder, I'm confused by your statement. Also I can't believe you copy / pasted my response… XD

King of Knives

2007-11-05 16:23:41

Sorry, I though it was a TPointArray… Shows how much I actually pay attention sometimes :D

You said you wanted a reply like that :P I'm just here to make you happy.

-Knives

Special Ed

2007-11-05 19:38:00

From: King of Knives
Sorry, I though it was a TPointArray… Shows how much I actually pay attention sometimes :D

You said you wanted a reply like that :P I'm just here to make you happy.

-Knives


Well at least someone cares… XD

Do you at least think you could give it a try for me though. Seeing as how you've spent more time talking to me on the forums than you would have using it on RS?