Well Flight you captured my interest. Needed some epic farming xp so decided to try out your script. I came across a couple of issues.
First, as stated above, it couldn't decide if I was on the correct tile so it kept moving me one space back and for from the correct spot to one spot south and back. Since I was just doing the garden section only I took out that check.
Second, I noticed that most of the time when a diseased plant it on the closest spot directly north of the player, the script would ignore it. I just decreased the no no zone around the player you put in and now it works everytime.
Third, sometimes the diseased plants were found and the mouse would go to it, but it would not be able to detect which type it was and would thus loop for the next few minutes until the spots reset (goto jump). What I did for this was to instead of just retrying to find which type it was, I had it guess 1, then if that was wrong, try to identify again, if still no identify - guess 2, so on until it has guessed all 4 options.
Fourth, there were some random misidentifications and failure to identify soil spots. I am too dumb for how you identified them so I came up with my own method. Pretty much what it does is breaks each spot up into a box and it searches each box for the green color, if it doesn't find the green color it searches for a dtm I made of the empty patch that is pretty general, but it won't misidentify the diseased plants either. If it finds the dtm it will go to the spot and check for it. It will randomly mix up the order in which it searches the boxes so it won't always go left to right top to bottom.
I also prefer a custom progress report so i put in one of mine too. For the progress report to work accurately, your first counter must be set to magic and your second set to farming.
I took out all the functions I wasn't using so this code is only good if you are in the designated spot in the OP. You are more than welcome to take whatever suggestions or code from here! If you would prefer I take it down, no problem!
Simba Code:
{/////////////////////////////////////////
// LividFarmer //
// (by Flight) //
// //
// Version: 1.41 //
/////////////////////////////////////////}
Program LividFarmer;
{$DEFINE SMART}
{$i SRL/srl.simba}
{$i SRL/SRL/misc/MouseHandler.simba}
///////////////////////////////////////////////////////////////////////
// //
// Begin of user setup //
// Fill in the fields below //
// //
///////////////////////////////////////////////////////////////////////
Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
With Players[0] Do
Begin
Name := '';
Pass := '';
BoxRewards := ['XP','xp','lamp'];
LampSkill := Skill_Farming;
WorldInfo := [96,96];
Active := True;
End;
End;
///////////////////////////////////////////////////////////////////////////////////////////
// //
// End of user setup //
// Don't touch below this line unless you know what you're doing!! //
// //
///////////////////////////////////////////////////////////////////////////////////////////
Var
Version: String;
SoilDTM,SX1,SY1,SX2,SY2: Integer;
FarmXP,MageXP,ReportTime,StartFarm,StartMagic: Integer;
afound: Extended;
Box1,Box2,Box3,Box4,Box5,Box6,Box7,Box8,Box9,Box10,Box11,Box12,Box13,Box14,Box15: TBox;
FarmGrid: TBoxArray;
Procedure LoadVars;
begin
Version := '1.41';
MouseSpeed := 14;
Box1 :=IntToBox(131,102-50,164,142-50);
Box2 :=IntToBox(180,102-50,214,142-50);
Box3 :=IntToBox(236,102-50,276,142-50);
Box4 :=IntToBox(288,102-50,328,142-50);
Box5 :=IntToBox(343,102-50,395,142-50);
Box6 :=IntToBox(104,162-50,157,225-50);
Box7 :=IntToBox(168,162-50,217,225-50);
Box8 :=IntToBox(230,162-50,273,225-50);
Box9 :=IntToBox(293,162-50,341,225-50);
Box10:=IntToBox(350,162-50,396,225-50);
Box11:=IntToBox(106,261-50,144,310-50);
Box12:=IntToBox(159,261-50,214,310-50);
Box13:=IntToBox(229,261-50,283,310-50);
Box14:=IntToBox(294,261-50,344,310-50);
Box15:=IntToBox(359,261-50,426,310-50);
FarmGrid:= [Box1,Box2,Box3,Box4,Box5,Box6,Box7,Box8,Box9,Box10,Box11,Box12,Box13,Box14,Box15];
SoilDTM := DTMFromString('m6wAAAHic42ZgYLBkZGCwB2JrILYAYlMgtgFiWyC2AmJDIDYBYhcgbgCqr0bCdUDcBMT1QFwOxSB+KxDHhLkzNJaGMUQEuTCUZvkxFGdHwNnlOf4M5fnRDFEhrgyF6d4MXED1xGJGEjASAACcIRSr');
end;
Procedure FreeGlobals;
begin
FreeDTM(SoilDTM);
end;
Procedure Report;
Var
FXPH,MXPH: Integer;
begin
ClearDebug;
FarmXP:=GetXPBar(2) - StartFarm;
MageXP:=GetXPBar(1) - StartMagic;
FXPH := Round(FarmXP * (3600.0 / (GetTimeRunning / 1000.0)));
MXPH := Round(MageXP * (3600.0 / (GetTimeRunning / 1000.0)));
Writeln('=========Flights LividFarmer=========');
Writeln('============Version: '+Version+'============');
Writeln('Time Running: ' + TimeRunning);
Writeln('Magic XP: ' + IntToStr(MageXP));
Writeln('Magic XP/H: ' + IntToStr(MXPH));
Writeln('Farming XP: ' + IntToStr(FarmXP));
Writeln('Farming XP/H: ' + IntToStr(FXPH));
Writeln('=====================================');
MarkTime(ReportTime);
end;
Procedure Shutdown(Reason: String);
begin
WriteLn('{{{==Script shutdown==}}}');
Writeln('----Reason: '+Reason+'----');
Wait(RandomRange(1000, 1300));
Logout;
FreeGlobals;
TerminateScript;
end;
Procedure ReturnValues(colors: TIntegerArray; var HueMods, SatMods: Extended; var color, Tolerance: Integer);
Var
h, s, t: Extended;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL : Array[0..1] of Array[1..3] of Extended;
begin;
For I:= 1 to 3 do
begin;
HSL[0][i] := 255;
end;
For I:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[i],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;
H := (HSL[1][1] - HSL[0][1]);
S := (HSL[1][2] - HSL[0][2]);
T := (HSL[1][3] - HSL[0][3]);
try
HueMods := (H/T);
SatMods := (S/T);
Tolerance := Round(t);
except
HueMods := 0;
SatMods := 0;
Tolerance := Round(0.0);
end;
Color := HSLToColor((HSL[1][1] + HSL[0][1]) / 2,(HSL[1][2] + HSL[0][2]) / 2,(HSL[1][3] + HSL[0][3]) / 2);
end;
Procedure SortFarmGrid;
Begin
Case RandomRange(0,5) Of
0: Begin FarmGrid:= [Box1,Box2,Box3,Box4,Box5,Box6,Box7,Box8,Box9,Box10,Box11,Box12,Box13,Box14,Box15]; End;
1: Begin FarmGrid:= [Box2,Box1,Box4,Box3,Box6,Box5,Box8,Box7,Box10,Box9,Box12,Box11,Box14,Box13,Box15]; End;
2: Begin FarmGrid:= [Box15,Box14,Box13,Box12,Box11,Box10,Box9,Box8,Box7,Box6,Box5,Box4,Box3,Box2,Box1]; End;
3: Begin FarmGrid:= [Box2,Box4,Box6,Box8,Box10,Box12,Box14,Box1,Box3,Box5,Box7,Box9,Box11,Box13,Box15]; End;
4: Begin FarmGrid:= [Box14,Box4,Box7,Box8,Box13,Box12,Box11,Box5,Box10,Box15,Box1,Box3,Box9,Box6,Box2]; End;
5: Begin FarmGrid:= [Box2,Box5,Box13,Box7,Box4,Box10,Box8,Box9,Box3,Box12,Box11,Box1,Box14,Box6,Box15]; End;
End;
End;
Function FindLivid(Var X,Y: Integer): Boolean;
var
B: TBox;
MBP: TPoint;
TBA: TBoxArray;
i,h,CTS,i2,h2: Integer;
ATPA: T2DPointArray;
TPA,PAr: TPointArray;
begin
Result := False;
if not LoggedIn then Exit;
CTS := GetColorToleranceSpeed;
CombineTPAWrap(TPAFromBox(IntToBox(245, 150, 275, 190)), TPAFromBox(IntToBox(430, 20, 515, 230)), PAr);
SortFarmGrid;
H2:=High(FarmGrid);
For I2:=0 To H2 Do
Begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(4.17, 0.56);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 1447447, FarmGrid[I2].X1,FarmGrid[I2].Y1,FarmGrid[I2].X2,FarmGrid[I2].Y2, 4);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
ClearTPAFromTPAWrap(TPA, PAr, TPA);
if (Length(TPA) < 1) then
Continue;
SplitTPAExWrap(TPA, 10, 10, ATPA);
GetMousePos(X,Y);
SortATPAFromFirstpoint(ATPA, Point(X, Y));
for i := 0 to High(ATPA) do
begin
if (GetArrayLength(ATPA[I]) > 10) then
begin
B := GetTPABounds(ATPA[i]);
B := IntToBox(B.X1-10,B.Y1-10,B.X2+10,B.Y2+10);
with B do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.46, 0.11);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 9012621, B.X1, B.Y1, B.X2, B.Y2, 13);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
if (Length(TPA) > 0) then
begin
SetArrayLength(TBA, Length(TBA)+1);
TBA[High(TBA)] := B;
end;
end;
end;
end;
for h := 0 to High(TBA) do
begin
MBP := MiddleBox(TBA[h]);
HumanMMouse(MBP.X, MBP.Y,4,4);
if WaitUptextMulti(['Cure', 're-p', '-pl', 'lant', 'Dise', 'seas', 'd li'], 500) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end else
Result := False;
end;
End;
end;
Function FindSoil: Boolean;
Var
CTS,X,Y,I,H: Integer;
Begin
Result := False;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.40, 0.80);
SortFarmGrid;
H:=High(FarmGrid);
For I:=0 To H Do
Begin
If (CountColorTolerance(3557184,FarmGrid[I].X1,FarmGrid[I].Y1,FarmGrid[I].X2,FarmGrid[I].Y2,8) = 0) Then
Begin
SX1:=FarmGrid[I].X1;
SY1:=FarmGrid[I].Y1;
SY2:=FarmGrid[I].Y2;
SX2:=FarmGrid[I].X2;
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
if finddtmrotated(soildtm,x,y,SX1,SY1,SX2,SY2,-Pi,Pi,Pi/30,aFound) then
begin
HumanMmouse(X,y,4,4);
if Waituptextmulti(['Fertilise', 'Empty', 'patch'],500) then
begin
FastClick(mouse_right);
if WaitOption('Empty', 500) then
Begin
Result:=True;
Wait(randomRange(2215, 2570));
Exit;
End;
end;
end Else
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.40, 0.80);
End;
End;
End;
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
Function GetLividType(X, Y: Integer): Integer;
var
R1C1,R1C2,R1C3,R1C4,R1C5,
R2C1,R2C2,R2C3,R2C4,R2C5,
R3C1,R3C2,R3C3,R3C4,R3C5: TBox;
begin
Result := 0;
//Top row
R1C1 := IntToBox(100, 20, 150, 70);
R1C2 := IntToBox(165, 20, 220, 70);
R1C3 := IntToBox(235, 20, 290, 70);
R1C4 := IntToBox(300, 20, 355, 70);
R1C5 := IntToBox(370, 20, 440, 70);
//Middle row
R2C1 := IntToBox(70, 100, 135, 160);
R2C2 := IntToBox(155, 100, 220, 160);
R2C3 := IntToBox(230, 100, 290, 160);
R2C4 := IntToBox(305, 100, 365, 160);
R2C5 := IntToBox(380, 100, 440, 160);
//Bottom row
R3C1 := IntToBox(60, 210, 125, 270);
R3C2 := IntToBox(140, 210, 215, 270);
R3C3 := IntToBox(225, 210, 295, 270);
R3C4 := IntToBox(305, 210, 375, 270);
R3C5 := IntToBox(400, 210, 470, 270);
if (IntInBox(X, Y, R1C1) or IntInBox(X, Y, R1C2) or //Type 1
IntInBox(X, Y, R1C3) or IntInBox(X, Y, R1C5)) then
Result := 1
else if (IntInBox(X, Y, R1C4) or IntInBox(X, Y, R2C3) or //Type 2
IntInBox(X, Y, R2C4) or IntInBox(X, Y, R2C5)) then
Result := 2
else if (IntInBox(X, Y, R2C2) or IntInBox(X, Y, R3C1) or //Type 3
IntInBox(X, Y, R3C5)) then
Result := 3
else if (IntInBox(X, Y, R2C1) or IntInBox(X, Y, R3C2) or //Type 4
IntInBox(X, Y, R3C3) or IntInBox(X, Y, R3C4)) then
Result := 4;
end;
Function LividMenu: Boolean;
var
X,Y: Integer;
begin
Result := FindText(x, y, 'train', SmallChars, MIX1, MIY1, MIX2, MIY2);
end;
Procedure QuickLow;
begin
KeyDown(40);
Wait(850 + Random(100));
KeyUp(40);
end;
Procedure QuickHigh(Click: Boolean);
begin
if Click then
Mouse(542, 24, 15, 15, mouse_left);
KeyDown(38);
Wait(950 + Random(100));
KeyUp(38);
end;
Procedure CureLivid(Strain: Integer);
var
SPoint: TPoint;
begin
if (Strain = 1) then
SPoint := Point(590, 280)
else if (Strain = 2) then
SPoint := Point(680, 280)
else if (Strain = 3) then
SPoint := Point(590, 400)
else if (Strain = 4) then
SPoint := Point(680, 400);
MissMouse2(SPoint.X, SPoint.Y, 10, 10);
if WaitUpText('Continue', 500) then
begin
FastClick(mouse_left);
end;
end;
Procedure HandleLivids;
var
X,Y,Tries: Integer;
label
Start;
begin
Tries:=0;
Start:
if (not LoggedIn) then
Exit;
FindNormalRandoms;
if FindLivid(X, Y) then
begin
FastClick(mouse_right);
if WaitOptionMulti(['Cure', 're-p', '-pl', 'lant', 'Dise', 'seas', 'd li'], 500) then
BrakeMMouse(635, 310, 65, 70);
if (not WaitFunc(@LividMenu, 50, 3000)) then
Exit;
if LividMenu then
begin
if (GetLividType(X, Y) = 0) then
Begin
Inc(Tries);
If Tries=5 Then
Exit;
CureLivid(Tries);
End Else
CureLivid(GetLividType(X, Y));
Wait(randomRange(1915, 2570));
GoTo Start;
end;
end;
end;
Procedure HandleSoil;
label
Start;
begin
Start:
if (not LoggedIn) then
Exit;
FindNormalRandoms;
If FindSoil Then
GoTo Start;
end;
Procedure FoundARandom;
begin
Writeln('Found a random!');
PlaySound(ScriptPath+'evilaugh.wav');
Wait(RandomRange(10000, 20000));
end;
//by Home
function AreaToBoxArray(const AreaX1, AreaY1, AreaX2, AreaY2, Width, Height: Integer): TBoxArray;
var
AreaW, AreaH: Integer;
BoxX, BoxY: Integer;
x, y, i: Integer;
begin
// Calculate the area dimensions
AreaW := AreaX2 - AreaX1 + 1;
AreaH := AreaY2 - AreaY1 + 1;
// Calculate the number of boxes in each dimension
BoxX := AreaW div Width;
if AreaW mod Width <> 0 then Inc(BoxX);
BoxY := AreaH div Height;
if AreaH mod Height <> 0 then Inc(BoxY);
// Set the number of boxes
SetLength(Result, BoxX * BoxY);
// Calculate the boxes
i := 0;
for y := 0 to BoxY - 1 do
for x := 0 to BoxX - 1 do
begin
Result[i] := IntToBox(AreaX1 + x * Width,
AreaY1 + y * Height,
Min(AreaX2, AreaX1 + (x + 1) * Width - 1),
Min(AreaY2, AreaY1 + (y + 1) * Height - 1));
Inc(i);
end;
end;
Procedure CheckMovingObjs(RClick: Boolean);
var
TBA: TBoxArray;
MidBox: TPoint;
TIA: TIntegerArray;
H,I,J,X,Y,T: Integer;
TPA,PBox: TPointArray;
RCOpts: Array of TOptions;
begin
if not LoggedIn then Exit;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
PBox := TPAFromBox(IntToBox(240, 130, 275, 185));
TBA := AreaToBoxArray(MSX1, MSY1, MSX2, MSY2, 35, 35);
TIA := PixelShiftMulti(TBA, 300);
for H := 0 to High(TBA) do
begin
if (TIA[H] > 100) then
begin
MidBox := MiddleBox(TBA[H]);
SetArrayLength(TPA, Length(TPA)+1);
TPA[High(TPA)] := MidBox;
end;
end;
ClearTPAFromTPAWrap(TPA, PBox, TPA);
if (Length(TPA) < 1) then Exit;
I := Random(Length(TPA));
MissMouse2(TPA[I].X, TPA[I].Y, 5, 5);
if RClick then
begin
FastClick(Mouse_Right);
RCOpts := GetChooseOptions('All');
J := Length(RCOpts);
Wait(RandomRange(J*75, J*120));
MarkTime(T);
repeat
GetMousePos(X, Y);
BrakeMMouse(X-10,Y-10,15,5);
if (TimeFromMark(T) > 5000) then
break;
until(not FindTextEx(X,Y,['Choose','Option'],['UpCharsEx'],MSX1,MSY1,MSX2,MSY2))
if FindTextEx(X,Y,['Choose','Option'],['UpCharsEx'],MSX1,MSY1,MSX2,MSY2) then
MMouse(RandomRange(MIX1,MIX2),RandomRange(MIY1,MIY2),0,0);
end;
end;
Function DoAntiban: Boolean;
var
i: Integer;
begin
i := Random(300);
case i of
1..3:
begin
RandomRClick;
Result := True;
end;
4,5:
begin
HoverSkill('Farming', False);
Result := True;
end;
6,7:
begin
HoverSkill('Magic', False);
Result := True;
end;
8..11:
begin
CheckMovingObjs(True);
Result := True;
end;
12..300:
begin
Wait(RandomRange(250, 350));
Exit;
end;
end;
Wait(RandomRange(250, 350));
end;
begin
{$IFDEF SIMBAMAJOR980}
SMART_SERVER := 10;
SMART_MEMBERS := TRUE;
SMART_SIGNED := TRUE;
SMART_SUPERDETAIL := FALSE;
{$ELSE}
SRL_SIXHOURFIX := TRUE;
SMART_FIXSPEED := TRUE;
{$ENDIF}
SetupSRL();
DeclarePlayers;
AddOnTerminate('FreeGlobals');
LoadVars;
if (not LoggedIn) then
LogInPlayer;
QuickHigh(True);
SRL_Procs[SRL_OnFindRandom] := @FoundARandom;
StartFarm:= GetXPBar(2);
StartMagic:= GetXPBar(1);
Repeat
If (not LoggedIn) then
begin
LoginPlayer;
QuickHigh(True);
end;
If FindNormalRandoms Then
Begin
LoginPlayer;
QuickHigh(True);
End;
HandleLivids;
HandleSoil;
if (TimeFromMark(ReportTime)>=20000) then
Report;
DoAntiban;
Wait(RandomRange(800, 1200));
Until(AllPlayersInactive)
end.