SCAR Code:
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.