SRL Archive - Research & Development Lounge

Fishing Spot Finder


TViYH

2008-08-06 17:29:59

Please post anything that you find that may be wrong, or anything that I can improve on.

This will be a function that will go into the script I'm posting in my members application.



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

var
FishezTPA : TPointArray;
FishezATPA : T2DPointArray;
FishezPoint : TPoint;
x, y, i, r, z : Integer;



{*******************************************************************************
function FindFishez(FishyColor, FishyColor1, FishyColor2 : integer) : boolean;
By: TheVoiceInYourHead(Elkins121)
Description: Finds a fishing spot using the colors you provide. FishyColor,
FishyColor1, and FishyColor2 should be the "sparkling" parts of the water.
*******************************************************************************}
function FindFishez(FishyColor, FishyColor1, FishyColor2 : integer) : boolean;
begin
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x, y, FishezTPA, FishyColor, MSX1, MSY1, MSX2, MSY2, 5);
if Length(FishezTPA)=0 then FindColorsSpiralTolerance(x, y, FishezTPA, FishyColor1, MSX1, MSY1, MSX2, MSY2, 5);
if Length(FishezTPA)=0 then FindColorsSpiralTolerance(x, y, FishezTPA, FishyColor2, MSX1, MSY1, MSX2, MSY2, 5);
FishezATPA := SplitTPA(FishezTPA, 8);
for i := 0 to High(FishezATPA) do
begin
FishezPoint := MiddleTPA(FishezATPA[i]);
MMouse(FishezPoint.x, FishezPoint.y, 3, 3);
if IsUpTextMultiCustom(['et', 'ishing']) then
begin
GetMousePos(x, y);
MarkTime(r);
z := InvCount;
case Random(2) of
1: Mouse(x, y, 1, 1, True);
2: Mouse(x, y, 3, 3, True);
end;
repeat
Wait(250+Random(750));
FindNormalRandoms;
until((InvFull) or (TimeFromMark(r)>=15000));
if z=InvCount then
begin
FindFishez(FishyColor, FishyColor2, FishyColor2);
end else
Result := True;
end;
end;
end;


begin
SetupSRL;
FindFishez({FishyColor}, {FishyColor1}, {FishyColor2});
end.

Macrosoft

2008-08-06 18:10:49

fishycolor could be made into an tintegerarray so the person can choose how many colors they want to have and then you could make a loop instead of the three if statements. (if this isnt clear then i will explain more)

Umm, why do you use FindFishez IN FindFishez. Is that even possible? You cant use a function in the declaration of that function.

TViYH

2008-08-06 18:21:17

No, it just starts the function over again, that I know of.

Macrosoft

2008-08-06 19:09:10

really? i learned something new today :)

TViYH

2008-08-06 19:20:18

It may not, but I'm pretty sure it does.

If it doesn't then I can just change it to a label.

HyperSecret

2008-08-06 19:54:38

there is something weird about the function, but i can't put my finger on it.

and yes declaring the function inside itself just loops around to start over the function.

and why not just use findObjTPA?

TViYH

2008-08-06 20:11:41

Because I wanted to show my knowledge of TPAs.

Macrosoft

2008-08-06 20:19:28

well, if it does loop it back then couldn't it result in a potentially endless loop?

EvilChicken!

2008-08-06 20:20:37

Hey, sorry for not repying.

Here's a "fixed" version:
{*******************************************************************************
function FindFishez(FishyColor, FishyColor1, FishyColor2 : integer) : boolean;
By: TheVoiceInYourHead(Elkins121)
Description: Finds a fishing spot using the colors you provide. FishyColor,
FishyColor1, and FishyColor2 should be the "sparkling" parts of the water.
*******************************************************************************}
function FindFishez(FishColors: TIntegerArray): Boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
I, A, X, Y: Integer;

begin
Result := False;
for I := 0 to High(FishColors) do
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, FishyColor[I], MSX1, MSY1, MSX2, MSY2, 15);
if Length(TPA) = 0 then
if I = High(TPA) then exit
else
Continue;
end;
ATPA := TPAtoATPA(TPA, 8);
for A := 0 to High(ATPA) do
begin
MiddleTPAEx(FishezATPA[A], X, Y);
MMouse(X, Y, 6, 6);
if IsUpTextMultiCustom(['et', 'ishing']) then
begin
GetMousePos(x, y);
MarkTime(r);
z := InvCount;
if Random(2) = 0 then
Mouse(x, y, 1, 1, True)
else
Mouse(x, y, 3, 3, True);
repeat
Wait(250+Random(750));
FindNormalRandoms;
until((InvFull) or (TimeFromMark(r)>=15000));
if z=InvCount then
begin
FindFishez([FishColors]);
end else
Result := True;
end;
end;
end;


begin
SetupSRL;
FindFishez([FishColors]);
end.

Fixed the most serious errors.

See the differences?

And also, run this:


var
I: Byte;

begin
for I := 0 to 255 do
WriteLn(IntToStr(Random(2)));
end.

Random(2) = 0 or 1, Random(5) = 0..4 ect.

From: HyperSecret
there is something weird about the function, but i can't put my finger on it.

and yes declaring the function inside itself just loops around to start over the function.

and why not just use findObjTPA?


This will be in his app, it is supposed to show his über mad hax0r skillz.

TViYH

2008-08-06 20:21:04

It wouldn't be endless if it found the correct colors. That's why I have you set up the Fishing Spot colors.

E: Thanks, EC! I don't quite understand the TPAtoATPA, etc..ATPA's confuse me. I guess it replaces SplitTPA?

Macrosoft

2008-08-06 20:26:18

but what if there are no fish on the minimap and the colors can not be found. Does this mean you should continue checking or you should log out?

TViYH

2008-08-06 20:29:36

Mate, this is only 1 function of the script…I'm going to implement into it a counter..In another function it'll be along the lines of:

begin
repeat
FindFishez(blah);
Inc(Counter);
until((FindFishez(blah)) or Counter>=5);

Macrosoft

2008-08-06 20:39:39

but you will never get out of the first findfishez if it doesnt find the fish because you will keep redoing findfishes.

also, look at this

    begin
GetMousePos(x, y);
MarkTime(r);
z := InvCount;
if Random(2) = 0 then
Mouse(x, y, 1, 1, True)
else
Mouse(x, y, 3, 3, True);
repeat
Wait(250+Random(750));
FindNormalRandoms;
until((InvFull) or (TimeFromMark(r)>=15000));
if z=InvCount then
begin
FindFishez([FishColors]);
end else
Result := True;


first, r and z are never declared as variables. Also, the function will always repeat no matter what because you never do anything to if after you assign it to the value of invcount.

TViYH

2008-08-06 20:43:28

-.-

r and z are globally declared. If it clicks and the InvCount stays the same then it starts over..It does this because you SHOULD put the right colors in.

Macrosoft

2008-08-06 20:55:35

But you never change invcount so why wouldn't it be the same as z?(this question should lead you to the solution)

What if the person DID input the right colors but you havent arrived at the fishing spot yet so it wont find the colors?

      if Random(2) = 0 then
Mouse(x, y, 1, 1, True)
else
Mouse(x, y, 3, 3, True);

what is the point of this?

TViYH

2008-08-06 20:57:47

Mate. Remember, this is only 1 function.

And, the InvCount wouldn't be the same because it checks it for the second time after it clicks.

Alas, that is just a little bit of AntiBan.

Macrosoft

2008-08-06 21:03:44

oh sorry, i didn't know invcount was a function XD

      case Random(2) of
1: Mouse(x, y, 1, 1, True);
2: Mouse(x, y, 3, 3, True);
end;
^^This is not needed
no randomness is needed Mouse(x, y, 0, 0, True) is fine. You have already moved your mouse to the spot+randomness. If you add more randomness then it will have a little jump (think about it).

TViYH

2008-08-06 21:10:59

function InvCount : integer;

…Duhhh??

Macrosoft

2008-08-06 21:24:10

sorry lol iv been away from srl for a while :)

      if z=InvCount then
begin
FindFishez(FishyColor, FishyColor2, FishyColor2);
end else
Result := True;

should be

      if z=InvCount then
begin
A:=A-1;
end else
begin
Result := True;
Exit;
end;

Because otherwise it will continue with the for loop even if you have successfully fished.

I added A:=A-1 because then it will redo the fish thing with the same color because it found the fish but obviously didn't fish for some reason (probably a lag)

Also, add a Result:=False at the end because you know if it hasnt exited (it exits when it succeeds) then it has failed.

TViYH

2008-08-06 21:43:16

What does the A have to do with anything?

Macrosoft

2008-08-06 22:14:25

its i in yours and a in ec's. It is basicly the var that you are using in the for loop.