n3ss3s
2007-08-06 05:22:10
Okay, first of all, my comp didnt let me download divi 3.11 so I dont have the function "AMin" in my scar to get the smallest value in an array.
So, I made it myself. What I know it has only one bug and that is that you cant use an array with only 1 slot. But, however the function works perfect with my object finding function. (the small function on the top is bobs :) )
I tried the object finder on a tree near champions guild and it worked good.
It spams your debug box a bit since I had to know what it does when testing..
So, just remove the writelns if you ever gonna use.
EDIT: Oops forgot usage instructions :D
for surecolor, set a color that is a color in the object which will like definetly be found. Then the array, put the array you have colors in there, for HowManyEnough, put how many colors is enough for the object to be really found. For area, put the area which is count from the coords of "surecolor". Tol and uptext everyone knows.
So, I made it myself. What I know it has only one bug and that is that you cant use an array with only 1 slot. But, however the function works perfect with my object finding function. (the small function on the top is bobs :) )
I tried the object finder on a tree near champions guild and it worked good.
It spams your debug box a bit since I had to know what it does when testing..
So, just remove the writelns if you ever gonna use.
EDIT: Oops forgot usage instructions :D
for surecolor, set a color that is a color in the object which will like definetly be found. Then the array, put the array you have colors in there, for HowManyEnough, put how many colors is enough for the object to be really found. For area, put the area which is count from the coords of "surecolor". Tol and uptext everyone knows.
program New;
{.include SRL/SRL.scar}
var
AC: TIntegerArray;
{*******************************************************************************
function WhichArraySlot(Number: Integer; TheArray: TIntegerArray): Integer;
By: Bobarkinator
Description: Returns what array slot has the value "Number" in "TheArray".
*******************************************************************************}
function WhichArraySlot(Number: Integer;TheArray: TIntegerArray): Integer;
var
i: Integer;
begin
for i:= 0 to GetArrayLength(TheArray)-1 do
begin
if (Number = TheArray[i]) then
begin
Result:=i;
Exit;
end;
end;
end;
{*******************************************************************************
function SmallestInArray(TheArray: TIntegerArray): Integer;
By: n3ss3s
Description: Returns the smallest integer in an array.
*******************************************************************************}
function SmallestInArray(TheArray: TIntegerArray): Integer;
var
I, Ax, Ay, DimensionHandler, TRL: Integer;
var
TempResult: TIntegerArray;
begin
Ax := 0;
Ay := 1;
for I := 0 to GetArrayLength(TheArray) / 2 do
begin
Wait(10);
SetArrayLength(TempResult, GetArrayLength(TempResult) +1);
if(not(Ay > GetArrayLength(TheArray) /2)) or (not(Ax > GetArrayLength(TheArray) /2)) then
begin
TempResult[I] := Min(TheArray[Ax], TheArray[Ay]);
Ax := Ax + 2;
Ay := Ax + 1;
end else
begin
Break;
end;
end;
I := 0;
repeat
Ax := 0;
Ay := 1;
TRL := GetArrayLength(TempResult) / 2 ;
TRL := TRL - 1;
for I := 0 to TRL do
begin
if(Ax > GetArrayLength(TheArray))then
begin
Break;
end;
if(I > GetArrayLength(TempResult))then
begin
Break;
end;
TempResult[I] := Min(TheArray[Ax], TheArray[Ay]);
Ax := Ax + 2;
Ay := Ax + 1;
DimensionHandler := DimensionHandler + 1;
end;
SetArrayLength(TempResult, DimensionHandler);
DimensionHandler := 0;
Wait(10);
if(GetArrayLength(TempResult) = 1)then
begin
Result := TempResult[0];
Break;
end;
until(GetArrayLength(TempResult) = 2);
if(not(Result) = TempResult[0])then
begin
Result := Min(TempResult[0], TempResult[1]);
end;
end;
{*******************************************************************************
function FindObject(var FoX, FoY: Integer; Colors: TIntegerArray;
SureColor, Area, HowManyEnough, Tol: Integer; UpText: string): Boolean;
By: n3ss3s
Description: Finds object.
*******************************************************************************}
function FindObject(var FoX, FoY: Integer; Colors: TIntegerArray;
SureColor,Area, HowManyEnough, Tol: Integer; UpText: string): Boolean;
var
I, S, GoodOnes, F, Toler, L: Integer;
var
TPA: TPointArray;
var
DIA: TIntegerArray;
var
Dx, Dy: Integer;
var
Mx, My: Integer;
var
SCFound, HMEnough: Boolean;
begin
SetArrayLength(TPA, 0);
SetArrayLength(DIA, 0);
for S := 1 to 10 do
begin
if(FindColorTolerance(Dx, Dy, SureColor, MSX1, MSY1, MSX2, MSY2, 10 + S))then
begin
MMouse(Dx, Dy, 0, 0);
if(IsUpText(UpText))then
begin
Writeln('"Sure Color" found!');
Writeln(IntToStr(DX)+','+IntToStr(Dy));
SCFound := True;
Dx := Dx;
Dy := Dy;
Break;
end;
end;
end;
if(SCFound)then
begin
for I := 1 to 10 do
begin
for I := 0 to GetArrayLength(Colors) - 1 do
begin
if(FindColorTolerance(Mx, My, Colors[i], Dx - Area /2, Dy - Area /2,
Dx + Area /2, Dy + Area /2, Toler)) then
begin
MMouse(Mx, My, 0, 0);
if(IsUpText(UpText))then
begin
SetArrayLength(TPA, GetArrayLength(TPA) + 1);
GoodOnes := GoodOnes + 1;
Writeln('Found');
TPA[GetArrayLength(TPA) -1].x := Mx;
TPA[GetArrayLength(TPA) -1].y := My;
if(GoodOnes >= HowManyEnough)then
begin
Writeln('Enough colours found!');
HMEnough := True;
Break;
end;
end;
end;
if(HMEnough)then
begin
Break;
end;
end;
if(not(HMEnough)) then
begin
Toler := Toler + 2;
end else
begin
Break;
end;
end;
end;
if(HMEnough)then
begin
Writeln('Solving closest');
for F := 0 to GetArrayLength(TPA) -1 do
begin
SetArrayLength(DIA, GetArrayLength(DIA) +1);
DIA[f] := Distance(TPA[f].x, TPA[f].y, MMCX, MMCY);
Wait(100);
Writeln('solvin');
end;
Writeln('gettin closest');
L := WhichArraySlot(SmallestInArray(DIA), DIA);
Mx := TPA[L].x;
MY := TPA[L].y;
FoX := Mx;
FoY := My;
Writeln(IntToStr(FoX));
Writeln(IntToStr(FoY));
Result := True;
Exit;
Writeln('solved');
end;
end;
begin
SetupSRL;
SetArrayLength(AC, 8);
AC[0] := 865582;
AC[1] := 2179644;
AC[2] := 2048571 ;
AC[3] := 265998 ;
AC[4] := 1651255;
AC[5] := 728349;
AC[6] := 203546;
AC[7] := 7039858;
if(FindObject(x, y, AC, 536614, 100, 2, 10, 'down'))then
begin
Mouse(x, y, 0, 0, True);
end;
end.