SRL Archive - MSI Archives

MSI_WaitWhileFishing


3Garrett3

2010-07-27 15:05:16


{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, CheckTime : Integer;
MyChar : TBox;
script: TScript;
TColour, TTol, TCount, AvCount, i, TWait : Integer;
THue, TSat : Extended;
Tools : TPointArray;
ToolAmount : TIntegerArray;
begin
Flag;
Wait(RandomRange(300, 450));
if InvFull then
Exit;
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
MyChar := IntToBox(205, 121, 338, 219);
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];

// Have a case to determine what colours/tols/hue/sat to look for and what counts of it

case (script.ObjectConstants[i]) of
FISHSPOT_NET:
begin
TColour:= 2108472;
TTol := 11;
THue := 0.09;
TSat := 0.27;
TCount := 50;
TWait := 1000;
end;

FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 1000;
end;

FISHSPOT_LURE: // Still not done
begin
TColour:= 2108472;
TTol := 11;
THue := 0.09;
TSat := 0.27;
TCount := 50;
TWait := 1000;
end;

FISHSPOT_CAGE:
begin
TColour:= 4934735;
TTol := 11;
THue := 0.38;
TSat := 0.08;
TCount := 8;
TWait := 3000;
end;

FISHSPOT_HARPOON: // Still not done
begin
TColour:= 2108472;
TTol := 11;
THue := 0.09;
TSat := 0.27;
TCount := 50;
end;
end;

SetToleranceSpeed2Modifiers(THue, TSat); // Set the vars and such
WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);

repeat

MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);

if (TimeFromMark(InvTimer) > 30000) then // If no new fish in inv after 30 seconds, spot probably moved
if (OldInvCount = InvCount) then break
else begin
OldInvCount := InvCount;
MarkTime(InvTimer);
end;

MarkTime(CheckTime);
repeat // Counts the occurance of a tool colour on the MS
FindColorsSpiralTolerance(MMCX, MMCY, Tools, TColour, MyChar.X1, MyChar.Y1, MyChar.X2, MyChar.Y2, TTol);
CombineIntArray(ToolAmount, [Length(Tools)]); // adds the length of the tool array (how many instances found)
Wait(55);
until(TimefromMark(CheckTime) > TWait)
AvCount := AverageTIA(ToolAmount);
if AvCount < TCount then break; // If count of tool on MS is less, it should be done fishing

Wait(RandomRange(200, 500));

until(WaitTime > GetSystemTime)

ColorToleranceSpeed(cts);
end;

So basically, to break it down. Here are the main points of what I am trying to do:

  • Set the colours/tols/wait times
  • Find the average amount of matching pixels in a box around the player
  • Compare to the amount which I have found most accurate
  • If it is less, then the tool is no longer on the main screen = fishing is done

So this worked 100% when I tested with nets and bait, and presumably lure (since it is the exact same as bait). But then I went to try it with harpoon and lobster cage, and they disappear under the water while fishing, so it is much more random whether or not you see the tool while checking. To counteract it, I set up a larger wait time, but it is still pretty sketchy. I've tried PixelShift (after Coh3n suggested it) and it was pretty much a failure. The char moves around while just swaying more than he does while fishing. I don't know what else gives off that the fishing spot is gone or not, as they can overlap (and they visually disappear during their animation anyway).

So here are the problems:
  • Fishing Spots have dynamic animations - Making it hard to figure out if they are there
  • Fishing spots can overlap - If your spot is gone, there may be one below it which means a false positive
  • Some fishing tools disappear while others do not during the fishing progress - It is difficult to count the occurrence of lobster pot pixels when it is underwater = invisible
  • With all of the above methods, the general search box must accommodate a larger search area, for the possibility of a fishing spot being above/below/left/right of the character - This allows for false positives if someone is fishing on a spot directly below you (almost all fishing locations have this possibility)
  • PixleShift has proven mostly useless because the amount of pixels which shift around the character are generally the same (240 and 250 for fishing/standing respectively)

So a list of solutions must be made. I'm willing to incorporate all of the above methods to make it work, I just don't know how yet, there will obviously have to be a case statement inside the wait procedure.

To solve the last problem - I can create 4 boxes; one containing the player and the small area above the fishing spot on the left, one on the right, etc. This allows for it to only be searching in the spot that you are fishing, rather than the large box around your player (all four spots). I would have to create another function to determine which side it is on, most likely through the use of the coordinates that it found the fishing spot in.

I have no general solution for the other problems (obviously), which is why I am posting it here. Anyone who can offer some feedback on what I should do, I will love you forever. This is the one thing that is keeping me from testing Fishing.scar, and then incorporating it into MSI.

Blumblebee

2010-07-27 17:56:14

I would do a check for 1 second long (or maybe the length of an average fishing animation?) and if during that whole second a certain instance of color isn't found then it breaks. That should allow it to see the animation where the equiptment is out of the water and the color to be found.

Shuttleu

2010-07-27 17:59:51

how about checking if you, yourself is moving?

~shut

3Garrett3

2010-07-27 18:18:10

From: Blumblebee
I would do a check for 1 second long (or maybe the length of an average fishing animation?) and if during that whole second a certain instance of color isn't found then it breaks. That should allow it to see the animation where the equiptment is out of the water and the color to be found.


That's mostly what I'm trying to do, but it is rather ineffective, because I'm pretty sure that the animation is long :P. It would probably be 5 seconds or so. I can give that a shot though. The only thing is that the colour does sometimes return things like boots, or a staff, so there is a small number (it was up to 40 for netting, but the count when the net is showing is always above 55) so finding if only one instance shows up doesn't work.

From: Shuttleu
how about checking if you, yourself is moving?

~shut


Well, if you can figure out PixelShift, could you throw some code at me? I tried finding out when I was animating, but it was relatively unsuccessful, because the char sways back and forth while standing still (resulting in a pixel movement of 250 average over 1000ms) and doesn't really significantly move more than when they bend down to fish (cage, harpoon, net only) and the numbers were around 240 or so average for that, over the same time period. That means that I would have gotten a lot of false positives. If you can find something that works though I'd love if you could share :)

Shuttleu

2010-07-27 18:34:51

i tried this, the fishing spot should be directly below you
i always get < 100 if im not fishing and between 200 and 500 if i am

program new;
{$i srl/srl.scar}
begin
setupsrl;
writeln(PixelShift(IntToBox(246, 196, 272, 217), 1000));
end.

~shut

3Garrett3

2010-07-27 19:39:31


program Template;
//{$DEFINE REFLECTION}
//{.include srl/srl/misc/smart.scar}
{.include srl/srl.scar}
//{.include reflection/reflection.simba}

const
Smart_World = 152;
Members = False;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := '';
Pass := '';
Nick := '';
Active := True;
Pin := '';
end;

end;

var
ShiftArray : TIntegerArray;


Function Outliers(TheArray : TIntegerArray) : TintegerArray;
var
i,lower, higher : integer;
begin
lower := TheArray[0];
higher := TheArray[0];
setlength(Result, 2);
for i := 0 to High(TheArray) do
begin
if TheArray[i] < Lower then Lower := TheArray[i];
if TheArray[i] > Higher then Higher := TheArray[i];
end;
Result[0] := Lower;
Result[1] := Higher;
end;

Function Average(TheArray : TIntegerArray) : Integer;
var
i,total : integer;
begin
for i := 0 to high(TheArray) do
IncEx(Total, TheArray[i]);
Result := Round(Total/Length(TheArray));
end;

Function AddToArray(TheArray : TIntegerArray; addin : Integer) : TintegerArray;
var
i : Tintegerarray;
begin
i := TheArray;
SetLength(i, Length(i) + 1);
i[High(i)] := Addin;
Result:= i;
end;

Procedure IsAnimationatering;
var
Me : TBox;
Shifty : Integer;
begin
Me := IntToBox(257, 160, 266, 169);
Shifty := PixelShift(Me, 500);
if Shifty > 0 then
ShiftArray := AddToArray(ShiftArray, Shifty);
end;

Function CountNet : Integer;
var
Nets : TPointArray;
cts : Integer;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.38, 0.08);
FindColorsSpiralTolerance(MMCX, MMCY, Nets, 4934735, 205, 121, 338, 219, 11);
Result := Length(Nets);
ShiftArray := AddToArray(ShiftArray, Length(Nets));
end;

Procedure ScriptSetup;
begin
{Smart_Server := Smart_World;
Smart_Members := Members;
Smart_Signed := True;
Smart_SuperDetail := False;}
ActivateClient;
SetupSRL;
//SetupReflectionEx(true);
DeclarePlayers;
end;

var
Results : TIntegerArray;
i, f, w : Integer;

begin
ScriptSetup;
Wait(1500);
ShiftArray := [];
MarkTime(w);
repeat
//if IsFKeyDown(8) then
IsAnimationatering;
//CountNet;
Wait(50);
//until TimeFromMark(w) > 3000
until isFKeyDown(9)
Writeln(ToStr(ShiftArray));
Results := Outliers(ShiftArray);
Writeln('Lowest = ' + ToStr(Results[0]));
Writeln('Highest = ' + ToStr(Results[1]));
Writeln('Average = ' + ToStr(Average(ShiftArray)));
{ For i := 0 to High(ShiftArray) do
if ShiftArray[i] < 50 then inc(f);
Writeln(ToStr(f) + ' false positives would happen below 50 out of ' +ToStr(Length(ShiftArray)) + ' samples'); }
end.

I've been using this ugly piece of work to figure out the stuff, could you fill your info into the function "IsAnimationatering" and let it run for… say 30 seconds or so? It stops at the press of f9, which works for me. You just have to target RS, I was using the internet, but it should be easy enough to make SMART work with it, considering the settings are all there :p

It gives an awful lot of stats on the numbers, prints the array, tells you the highest and lowest counts, and gives the average. It can give you false positives if you set the number to what you think the lowest should be (ideally the false positives should be 0 ;))

Could you maybe run that with your info and post the data for standing and for fishing? And for what type of fishing you are doing. If not, I'll update the box and then try it myself later, I just really don't have time right now.

Ps- Thanks for the help :)

Shuttleu

2010-07-27 20:00:55

not fishing
[75, 48, 68, 65, 69, 64, 54, 73, 57, 69, 19, 70, 54, 74, 53, 52, 78, 41, 80, 7, 76, 53, 66, 63, 71, 64, 65, 75, 51, 69, 55, 77, 27, 78, 36, 66, 49, 75, 63, 61, 78, 65, 64, 40, 67, 71, 73, 59, 70, 71, 72, 65, 75, 67, 22, 63, 34, 66, 16, 60, 15, 66, 34, 65, 57, 63, 72, 65, 74, 72, 62, 63, 72, 59, 68, 40, 70, 45, 58, 44, 63, 62, 71, 68, 71, 75, 70, 67, 58, 75, 69, 56, 40, 57, 64, 76, 59, 62, 72, 74]
Lowest = 7
Highest = 80
Average = 60

fishing
[80, 90, 79, 82, 36, 35, 55, 55, 94, 83, 67, 37, 52, 53, 38, 54, 92, 27, 83, 57, 90, 81, 34, 39, 54, 38, 70, 81, 33, 48, 38, 55, 91, 37, 98, 77]
Lowest = 27
Highest = 98
Average = 61


~shut

EDIT: with what i posted earlier
not fishing
[37, 59, 68, 69, 79, 87, 56, 55, 63, 55, 69, 102, 60, 9, 27, 63, 55, 69, 115, 61, 9, 55, 60, 41, 56, 73, 72, 32, 64, 70, 68, 101, 113, 73, 20, 74, 25, 59, 111, 60, 4, 28, 45, 33, 73, 101, 87, 13, 56, 55, 57, 61, 74, 67, 40, 65, 68]
Lowest = 4
Highest = 115
Average = 60

fishing
[205, 373, 343, 353, 353, 215, 337, 256, 386, 380, 374, 330, 325, 342, 290, 377, 394, 363, 302, 313, 354, 215, 356, 344, 380, 273, 355, 374, 250, 386, 410, 366, 311, 325, 367, 264, 387, 345, 366, 324, 379, 375, 276, 423, 395, 322, 342, 385, 391, 334, 394, 345, 322, 348, 340, 365, 254, 383]
Lowest = 205
Highest = 423
Average = 340

3Garrett3

2010-07-27 20:23:45

From: Shuttleu
not fishing

fishing


~shut

EDIT: with what i posted earlier
not fishing

fishing


So it appears that with a custom box it will likely detect the movement much more efficiently.

What kind of fishing were you doing? I'm assuming net or cage or harpoon, because bait and lure really are pretty useless, and don't move much at all.

Shuttleu

2010-07-28 07:58:20

From: 3Garrett3
So it appears that with a custom box it will likely detect the movement much more efficiently.

What kind of fishing were you doing? I'm assuming net or cage or harpoon, because bait and lure really are pretty useless, and don't move much at all.


i was fishing for lobsters
i will now check with a harpoon and post the results

~shut

EDIT:with harpoon
not fishing
[138, 66, 22, 59, 73, 64, 79, 99, 111, 57, 82, 77, 95, 122, 135, 78, 38, 87, 48, 87, 145, 97, 41, 62, 54, 63, 69, 94, 101, 70, 74, 77, 107, 133, 148, 17, 44, 75, 51, 72, 109, 94, 39, 70, 78, 93, 102, 121, 88]
Lowest = 17
Highest = 148
Average = 81

fishing
[74, 118, 93, 132, 180, 93, 80, 100, 96, 137, 126, 120, 169, 93, 98, 112, 128, 154, 161, 112, 84, 132, 100, 131, 187, 147, 70, 114, 108, 110, 126, 111, 142, 111, 91, 131, 148, 148, 137, 72, 74, 139, 127, 95, 159, 145, 84, 120, 114, 136, 156, 155, 126, 83, 137, 96, 150, 191]
Lowest = 70
Highest = 191
Average = 121



EDIT: big net
not fishing
[65, 76, 111, 72, 16, 41, 75, 70, 58, 85, 68, 39, 65, 69, 84, 102, 92, 50, 30, 79, 37, 81, 124, 75, 20, 49, 57, 73, 88, 84, 150, 24, 53, 59, 74, 108, 75, 17, 49, 62, 63, 65, 86, 64, 37, 60, 69, 86, 110]
Lowest = 16
Highest = 150
Average = 68

fishing
[369, 402, 408, 432, 460, 426, 455, 349, 377, 404, 391, 441, 452, 462, 397, 415, 439, 357, 375, 357, 329, 404, 522, 485, 409, 405, 391, 371, 412, 458, 382, 396, 391, 380, 415, 362, 348, 343, 411, 414, 480, 460, 372, 408, 387, 434, 448, 437, 332]
Lowest = 329
Highest = 522
Average = 407




so its very effective with lobster and netting, but not so effective with anything else

Coh3n

2010-07-28 11:57:50

Well for the rod fishing spots, just looking for the rod on the MS should work pretty well. Harpooning seems to be the most difficult right now.

NCDS

2010-07-28 15:16:31

Perhaps make a constant for rod, harpoon, etc with the amount of animation set to each const?
Not sure if that would work though, I'm not too familiar with animation.scar.

Shuttleu

2010-07-28 18:43:56

harpoon
not fishing
[26, 37, 40, 39, 39, 25, 16, 33, 34, 39, 43, 42, 37, 34, 3, 26, 35, 55, 38, 40, 41, 21, 28, 39, 42, 43, 39, 28, 20, 19, 41, 42, 47, 49, 39, 11, 53, 42, 50, 56, 52, 45, 33, 31, 17, 34]
Lowest = 3
Highest = 56
Average = 35

fishing
[60, 140, 137, 21, 139, 139, 110, 141, 139, 142, 141, 144, 141, 135, 142, 134, 143, 96, 142, 143, 89, 141, 143, 89, 142, 140, 47, 144, 140, 8, 142, 140, 47, 140, 140, 16, 140, 139, 142, 135, 71, 74, 143, 132, 141, 143, 84, 140, 141, 42, 141, 142, 88, 120]
Lowest = 8
Highest = 144
Average = 118


~shut

3Garrett3

2010-07-28 20:38:11

So i'm going to have to make personalized boxes for each skill, for each direction? There has to be an easier way..

Shuttleu

2010-07-29 04:51:11

From: 3Garrett3
So i'm going to have to make personalized boxes for each skill, for each direction? There has to be an easier way..

no, the box which i done the harpooning with should also work with netting and cageing, im not too sure if it will work for others

if it does then all you need to do is make it so it rotates the camera depending on where the water is

~shut

Sir R. M8gic1an

2010-07-29 18:43:01

From: Shuttleu
no, the box which i done the harpooning with should also work with netting and cageing, im not too sure if it will work for others

if it does then all you need to do is make it so it rotates the camera depending on where the water is

~shut


Or rotate the box of where to look…..

Fishing spots are very easy to detect.

IsFishing could be very easily made.
1. Detect Where there is water
2. Detect where there is a fishing spot
3. Make sure it is within fishable distance
4. Break IsFishing if you haven't received a fish in the last 30 secs (this is the part I dislike)

but let's say we change point 4.
You already know where you are fishing. You can just do the pixel shit counting on that.

~RM

Shuttleu

2010-07-29 18:48:04

but if the walking is in reflection, and most scripts only use reflection in their walking, so maybe you could make the WaitWhileFishing in reflection until you have perfected the color version?

~shut

Sir R. M8gic1an

2010-07-29 18:50:33

From: Shuttleu
but if the walking is in reflection, and most scripts only use reflection in their walking, so maybe you could make the WaitWhileFishing in reflection until you have perfected the color version?

~shut


Uh. This was something we discussed in the beginning.
The answer to that was no, as that would be way too easy, we'd have this project done in a good week's work and next month MSI wouldn't work anymore.

Color.

~RM

3Garrett3

2010-07-29 19:12:29

From: Rasta Magician
Or rotate the box of where to look…..

Fishing spots are very easy to detect.

IsFishing could be very easily made.
1. Detect Where there is water
2. Detect where there is a fishing spot
3. Make sure it is within fishable distance
4. Break IsFishing if you haven't received a fish in the last 30 secs (this is the part I dislike)

but let's say we change point 4.
You already know where you are fishing. You can just do the pixel shit counting on that.

~RM


The point of it was to determine when you were fishing, not when the fishing spot was.

I think that was what you meant maybe? Fishing spots overlap and if the one you are fishing disappears, there could be one there. We could use it as a backup though, because if the fishing spot is gone, then we definitely aren't fishing.

Sir R. M8gic1an

2010-07-29 19:20:16

If you know WHERE it is then you can look for your fishing equipment in the right place, look for animation in the right place, etc.

~RM

3Garrett3

2010-07-29 19:51:20

From: Rasta Magician
If you know WHERE it is then you can look for your fishing equipment in the right place, look for animation in the right place, etc.

~RM


Yeah, I think I was trying to get at that, when I mentioned personalized boxes and such.

I was thinking something like a case for LEFT, RIGHT, ABOVE, BELOW and having a custom search box for all of them. The whole thing just adds more complexities to the function, which is already overloaded with variables and the like.

Sir R. M8gic1an

2010-07-30 07:04:33

Uh. I'd rather have something complex that works well.


function FollowFishSpot(var TP: TPoint): boolean;
var
i, Timer: integer;
SearchBox: TBox;
begin
GetMousePos(TP.x, TP.y);

MarkTime(Timer);
Result := true;

repeat
SearchBox := IntToBox(TP.x - 30, TP.y - 30, TP.x + 30, TP.y + 30);
//search for it an re.adjust the box etc
//so that when you start fishing you already know where the spot is.
//you can then have a IsFishingSpotHere function
//And do the equip & inv check

until( not IsMoving(1000))
end;

~RM

Sir R. M8gic1an

2010-08-03 14:14:17

If this compiles, can we put it up for a few test runs? I'd rather see a fisher than not :) My own pickyness about WaitWhileFishing can wait a bit :)

~RM

3Garrett3

2010-08-03 20:31:36

Well the idea isn't even done yet :P