3Garrett3
2010-08-24 13:23:43
It doesn't give any errors, and I'm trying to get MSI's fishing to work, but I can't test because something in the code makes it fail/freeze/crash.
Here is the code:
The crash happens during MSI_WaitWhileFishing, but I'm not sure what part. During the repeat loop is my guess. It makes it past the changing compass angle part, so it must be during the waiting. It might be because of the Pixelshift part, but I can't be sure.
Here is the code:
{==============================================================================\
| MSI Group Scripting Include |
| Fishing.scar |
|==============================================================================|
| For all fishing routines. |
| |
| * function MSI_FishingTools() * by 3Garrett3 |
| * function MSI_DetectWaterDirections(); * by 3Garrett3 |
| * function MSI_DetectSide(); * by 3Garrett3 |
| * function MSI_FishPixels(); * by 3Garrett3 |
| * function MSI_FishGear(); * by 3Garrett3 |
| * procedure MSI_WaitWhileFishing(); * by 3Garrett3 |
| * function MSI_Fish(); * by 3Garrett3 |
| * function MSI_FishInvFull(); * by 3Garrett3 |
| |
| |
\ _____________________________________________________________________________}
{******************************************************************************}
{ Function MSI_FishingTools : TIntegerArray }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Figures out which tool the script needs to use }
{******************************************************************************}
Function MSI_FishingTools : TIntegerArray;
var
script: TScript;
i: Integer;
begin
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
for i := 0 to High(script.Objects) do
case (script.Objects[i]) of
FISHSPOT_NET:
Result := CombineIntArray(Result, [FISH_SMALLNET]);
FISHSPOT_BAIT:
Result := CombineIntArray(Result, [FISH_ROD, FISH_BAIT]);
FISHSPOT_LURE:
Result := CombineIntArray(Result, [FISH_FLY, FISH_FEATHER]);
FISHSPOT_CAGE:
Result := CombineIntArray(Result, [FISH_CAGE]);
FISHSPOT_HARPOON:
Result := CombineIntArray(Result, [FISH_HARPOON]);
else
MSI_Debug('MSI_FishingTools', 'Invalid Fishing Spot', DEBUG_FUNCTIONS);
end;
ClearSameIntegers(Result);
end;
{******************************************************************************}
{ Function MSI_DetectWaterDirections() : TBoolArray }
{ By: 3Garrett3 }
{ Date: 24 August 2010 }
{ Description: Finds the directions of water, helping find the fishing spot }
{******************************************************************************}
Function MSI_DetectWaterDirections(var Counts : TIntegerArray) : TBoolArray; // Array - 0 = right 1 = left 2 = below 3 = above
var
ATPA : T2DPointArray;
cts, i : Integer;
begin
SetLength(ATPA, 4);
SetLength(Result, 4);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.25, 0.25);
FindColorsTolerance(ATPA[0], 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14); // To the right
FindColorsTolerance(ATPA[1], 9602689, MSCx - 40 , MSCy - 10, MSCx - 20, MSCy + 10, 14); // To the left
FindColorsTolerance(ATPA[2], 9602689, MSCx - 10 , MSCy + 30, MSCx + 10, MSCy + 50, 14); // below
FindColorsTolerance(ATPA[3], 9602689, MSCx - 10 , MSCy - 50, MSCx + 10, MSCy - 30, 14); // above
for i := 0 to 3 do
begin
Result[i] := (Length(ATPA[i]) > 200);
Counts[i] := Length(ATPA[i]);
end;
ColorToleranceSpeed(cts);
end;
{******************************************************************************}
{ Function MSI_DetectSide : String }
{ By: 3Garrett3 }
{ Date: 24 August 2010 }
{ Description: Finds the direction of a fishing spot and returns compass angle }
{******************************************************************************}
Function MSI_DetectSide : String;
var
Water : TBoolArray;
Right, Left, Above, Below : Boolean;
i, TrueCount, cts : Integer;
WaterCount : TIntegerArray;
TPA : TpointArray;
begin
SetLength(Water, 4);
SetLength(WaterCount, 4);
Water := MSI_DetectWaterDirections(WaterCount);
for i := 0 to 3 do
if Water[i] then Inc(TrueCount);
if TrueCount = 1 then
begin
for i := 0 to 3 do
case i of
0: //right
if Water[i] then
begin
Result := 'n';
Exit;
end;
1: // left
if Water[i] then
begin
Result := 's';
Exit;
end;
2: // below
if Water[i] then
begin
Result := 'e';
Exit;
end;
3: // above
if Water[i] then
begin
Result := 'w';
Exit;
end;
end; // This means if there is only water on one side, there can only be fish on one side
// The camera angle is set as the result, it will allow for only one search box (the right side of char)
end;
Right := Water[0]; // For me to not get confused, if someone else does work they can make this prettier and stuff
Left := Water[1];
Below := Water[2];
Above := Water[3];
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.25, 0.25);
if Right then
begin
MakeCompass('n');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'n';
Exit;
end;
end;
if Left then
begin
MakeCompass('s');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 's';
Exit;
end;
end;
if Above then
begin
MakeCompass('w');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'w';
Exit;
end;
end;
if Below then
begin
MakeCompass('e');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'e';
Exit;
end;;
end;
end;
{******************************************************************************}
{ Procedure MSI_FishPixels }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Detects the pixelshift to decide if fishing }
{******************************************************************************}
Function MSI_FishPixels(TWait, TCount : Integer; TTBox : TBox) : Boolean;
var
Shifts, FinalCount, Waiting : Integer;
ShiftsArray : TIntegerArray;
begin
MarkTime(Waiting);
While TimeFromMark(Waiting) <= TWait do
begin
Shifts := PixelShift(TTBox, 500);
CombineIntArray(ShiftsArray, [Shifts]);
Wait(RandomRange(50,75));
end;
FinalCount := AverageTIA(ShiftsArray);
Result := (FinalCount >= TCount);
end;
{******************************************************************************}
{ Procedure MSI_FishGear }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Detects fishing gear on the screen }
{******************************************************************************}
Function MSI_FishGear(TColour, TTol, TCount, TWait : Integer; THue, TSat : Extended; TTBox : TBox) : Boolean;
var
FinalCount, Waiting, cts : Integer;
ToolAmount : TIntegerArray;
Tools : TPointArray;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(THue, TSat);
MarkTime(Waiting);
While TimeFromMark(Waiting) <= TWait do
begin
FindColorsSpiralTolerance(MMCX, MMCY, Tools, TColour, TTBox.X1, TTBox.Y1, TTBox.X2, TTBox.Y2, TTol);
CombineIntArray(ToolAmount, [Length(Tools)]);
Wait(RandomRange(50,75));
end;
FinalCount := AverageTIA(ToolAmount);
Result := (FinalCount >= TCount);
ColorToleranceSpeed(cts);
end;
{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, i : Integer;
SearchBox : TBox;
script: TScript;
TColour, TTol, TCount, TWait : Integer;
THue, TSat : Extended;
TPixel, Fishing : Boolean;
begin
Flag;
Wait(RandomRange(300, 450));
if InvFull then
Exit;
SearchBox := IntToBox(270, 148, 296, 180);
MakeCompass(MSI_DetectSide);
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
TPixel := False;
case (script.Objects[i]) of
FISHSPOT_NET:
begin
TPixel := True;
TCount := 150;
TWait := 3300;
end;
FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 4000;
end;
FISHSPOT_LURE:
begin
TColour:= 859433;
TTol := 3;
THue := 0.19;
TSat := 1.11;
TCount := 50;
TWait := 4000;
end;
FISHSPOT_CAGE:
begin
TPixel := True;
TCount := 150;
TWait := 3600;
end;
FISHSPOT_HARPOON:
begin
TPixel := True;
TCount := 160;
TWait := 3000;
end;
end;
WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);
repeat
MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);
if InvFull then break;
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;
if TPixel then
Fishing := MSI_FishPixels(TWait, TCount, SearchBox)
else
Fishing := MSI_FishGear(TColour, TTol, TCount, TWait, THue, TSat, SearchBox);
if not Fishing then break;
Wait(RandomRange(200, 500));
until(WaitTime > GetSystemTime)
end;
{******************************************************************************}
{ Function MSI_Fish : Boolean }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Finds the fishing spot }
{******************************************************************************}
function MSI_Fish(Which: TIntegerArray): Boolean;
var
Fish: TMSObjectArray;
SearchBox: TBox;
Index: Integer;
begin
Fish := MSI_GetObjects(Which);
SearchBox := MSBox;
if MSI_FindObjectsIn(Fish, Index, SearchBox, ClickLeft) then
begin
Result := True;
MSI_WaitWhileFishing;
end;
end;
{******************************************************************************}
{ Function MSI_FishInvFull : Boolean }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Fishes until full inventory }
{******************************************************************************}
function MSI_FishInvFull(Which: TIntegerArray): Boolean;
var
t: Integer;
Begin
t := (GetSystemTime + (10 * 60000));
while (not InvFull) and (LoggedIn) and (GetSystemTime < T) do
begin
if MSI_Fish(Which) then
t := (GetSystemTime + (5 * 60000));
Wait(RandomRange(300, 800));
end;
Result := InvFull;
end;
The crash happens during MSI_WaitWhileFishing, but I'm not sure what part. During the repeat loop is my guess. It makes it past the changing compass angle part, so it must be during the waiting. It might be because of the Pixelshift part, but I can't be sure.