SRL Archive - OSR Help

Need a little advice on GateFinding Proc.


rotchy1

2013-06-06 11:39:25

So I've been working on this for 2 days now and it's about finished however the player always gets stuck trying to find the gate if it walks to close to it and I'm constantly having to update the colors. Is there a better way for doing this?

Heres the full code (It compiles and will probly run through 3 successful runs or so before messing up at the gate)

program RotchysPotatoPicker;

{$DEFINE SMART}
{$DEFINE CSMART}
{$I SRL/SRL.simba}
{$I SPS/SPS.simba}

var
PotatosPicked, PotatosPerHour, TimeGone: Integer;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := '';
Pass := '';
Active := True;
WorldInfo := [true, 7];
end;
end;

procedure Setup;
begin
Smart_FixSpeed := True;
SRL_SixHourFix := True;
ClearDebug;
SetupSRL;
DeclarePlayers;
LogInPlayer;
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
CloseAllScreens;
FindNormalRandoms;
ToggleActionBar(False);
Wait(RandomRange(200, 500));
ToggleMoneyPouch(False);
Wait(RandomRange(200, 500));
ToggleXPBar(False);
Wait(RandomRange(200, 500));
Retaliate(True);
Wait(RandomRange(200, 500));
end;

procedure ProgressReport;

begin
ClearDebug;
TimeGone := (GetTimeRunning / 1000);
PotatosPerHour :=(3600*(PotatosPicked)) / ((TimeGone));
begin
Writeln('|------------------- Rotchy1' + 's ' + 'Potato Looter -------------------');
Writeln('|###############################################################');
Writeln('|' + ' We have looted ' + IntToStr(PotatosPicked) + ' Raw Potatos so far ');
Writeln('|' + ' ' + IntToStr(PotatosPerHour) + ' Raw Potatos per hour ')
Writeln('|' + ' We have been collecting Raw Potatos for ' + TimeRunning + ' ');
Writeln('|' + ' Simple, yet effective. ' + '');
Writeln('|###############################################################');
end;
end;

procedure AntiBan;
begin
case Random(80) of
0: begin BoredHuman; end;
10: begin RandomRClick; end;
20: begin RandomMovement; end;
30: begin HoverMovingObject; end;
39: begin ExamineInv; end;
end;
end;

procedure TeleVarrock;

var T: Integer;

begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
MarkTime(T);
ProgressReport;
AntiBan;
FindNormalRandoms;
OpenLodeStoneScreen;
Lodestoneteleport('Varrock');
Wait(RandomRange(15000, 16000));
if TimeFRomMark(T) > 30000 then
begin
TeleVarrock;
end
else
if TimeFromMark(T) > 60000 then
begin
Writeln('error 1');
Logout;
TerminateScript;
end
else
end;

procedure WalkToPotatos;

var status: string;
ToPotatos: TPointArray;

begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
FindNormalRandoms;
SPS_Setup(RUNESCAPE_SURFACE,['11_7','12_7','12_8']);

ToPotatos:= [Point(4655, 3101), Point(4668, 3111), Point(4690, 3126), Point(4708, 3136), Point(4730, 3149), Point(4752, 3157), Point(4771, 3160), Point(4792, 3169), Point(4800, 3189), Point(4802, 3209), Point(4807, 3233), Point(4823, 3243), Point(4838, 3254), Point(4854, 3271), Point(4859, 3287), Point(4850, 3300), Point(4843, 3310)];
if SPS_WalkPath(ToPotatos) then
begin
Status := 'ToPotatos'
WaitNotMoving(True);
end else
begin
Status :='ToPotatos';
WaitNotMoving(True);
end;
AntiBan;
end;

procedure WalkIntoPatch;

var status: string;
ToPotatos: TPointArray;

begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
FindNormalRandoms;
SPS_Setup(RUNESCAPE_SURFACE,['12_8']);

ToPotatos:= [Point(4843,3317),Point(4841,3335)];
if SPS_WalkPath(ToPotatos) then
begin
Status := 'ToPotatos'
WaitNotMoving(True);
end else
begin
Status :='ToPotatos';
WaitNotMoving(True);
end;
AntiBan;
end;

function FindColorsSpiralMulti(Sx, Sy: Integer; Colors, Tolerance: TIntegerArray; X1, Y1, X2, Y2: Integer): TPointArray;
var
i: Integer;
ATPA: T2DPointArray;
CombTPA: TPointArray;
begin
FindNormalRandoms;
if (High(Colors) <> High(Tolerance)) then
begin
Writeln('Invalid number of parameters');
TerminateScript;
end;
for i := 0 to High(Colors) do
begin
SetLength(ATPA, i + 1);
FindColorsSpiralTolerance(Sx, Sy, ATPA[i], Colors[i], x1, y1, x2, y2, Tolerance[i]);
end;
CombTPA := MergeATPA(ATPA);
SortTPAFrom(CombTPA, Point(sx, sy));
Result := CombTPA;
end;

function GateIsOpen: Boolean;
var
MMx, MMy, T, i: Integer;
MSPC: TPoint;
TPA: TPointArray;
begin
MarkTime(T);
FindNormalRandoms;
while True do
begin
FFlag(0);
TPA := FindColorsSpiralMulti(MMx, MMy, [197874, 3951706], [10, 10], MMX1 - 5, MMY1 - 5, MMX2 + 5, MMY2 + 5);
MSPC := MMToMS(TPA[0]);
if FindObj(MMx, MMy, 'Gate', 3688533, 9) then //FindOBj automatically moves the mouse to the point when checking for uptext
begin
if WaitUptext('Close Gate', RandomRange(400, 650)) then
begin
Result := True;
Break;
end else
Result := False;
Break;
end;
Inc(i);
if (i = 5) or (TimeFromMark(T) > 30000) then
Exit;
end;
AntiBan;
Result := True;
end;

function OpenGateIfClosed : Boolean;

var
MMx, MMy, T, i: Integer;
MSPC: TPoint;
TPA: TPointArray;

begin
MarkTime(T);
FindNormalRandoms;
while True do
begin
FFlag(0);
TPA := FindColorsSpiralMulti(MMx, MMy, [197874, 3951706], [10, 10], MMX1 - 5, MMY1 - 5, MMX2 + 5, MMY2 + 5);
MSPC := MMToMS(TPA[0]);
if FindObj(MMx, MMy, 'Gate', 3688533, 9) then
begin
if WaitUptext('pen', RandomRange(400, 650)) then
begin
ClickMouse2(True);
FFlag(0);
Break;
end else
Break;
end;
Inc(i);
if (i = 5) or (TimeFromMark(T) > 30000) then
Exit;
end;
AntiBan;
Result := True;
end;

procedure Gate;
begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
FindNormalRandoms;
if not OpenGateIfClosed then
WalkToPotatos;
end;

Function FindPotato : Boolean; //Credits to Kasi for making this procedure
//and at the same time teaching how to split
//TPAs to reduce the amount of total points
//and find the point closest to player first.
//This makes the script look much more human
//like and increased the speed a good bit. I
//really appreciate it!
var
I, T, TimesFailed : integer;
PotatoTPA : TPointArray;
Potato2DTPA : T2DPointArray;
TB : TBox;
begin
FindNormalRandoms;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.08, 0.16);
FindColorsTolerance(PotatoTPA, 4091995, MSX1, MSY1, MSX2, MSY2, 3);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);
SplitTPAExWrap(PotatoTPA, 12, 12, Potato2DTPA);
SetLength(PotatoTPA, 0);
for I := 0 to High(Potato2DTPA) do
begin
TB := GetTPABounds(Potato2DTPA[I]);
if ((iAbs(TB.X1 - TB.X2) > 10) and (iAbs(TB.Y1 - TB.Y2) > 10) and
(iAbs(TB.X1 - TB.X2) < 50) and (iAbs(TB.Y1 - TB.Y2) < 50))
then
CombineTPAWrap(PotatoTPA, [MiddleTPA(Potato2DTPA[I])], PotatoTPA);
end;
SortTPAFrom(PotatoTPA, Point(MSCx, MSCy));
MarkTime(T);
for i := 0 to High(PotatoTPA) do
begin
MMouse(PotatoTPA[I].x, PotatoTPA[I].y, 0, 0);
if waituptext('Pick', 100) and RBoolEx(2) then
begin
ClickMouse2(mouse_Left);
Inc(PotatosPicked);
ProgressReport;
Result := WaitNotMoving(True);
Break;
end else
begin
if waituptext('Pick', 500) then
begin
ClickMouse2(Mouse_Right);
if WaitOption('Pick', 600) then
begin
WaitNotMoving(true);
Inc(PotatosPicked);
ProgressReport;
Result := True;
Break;
end;
end else
begin
if TimeFromMark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
AntiBan;
TimesFailed := 0;
end;
end;
if TimeFromMark(T) > 30000 then
begin
Gate;
end;
end;
end;
end;
end;

procedure BankTheLootFailsafe;

var T, x, y: Integer;

begin
MarkTime(T);
begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
FindNormalRandoms;
GameTab(26);
if WearingItem(11) then
MouseEquippedItem('ring', MOUSE_RIGHT);
ChooseOption('aemon');
Wait(RandomRange(9000,11000));
end;
Writeln('RadialBankWalk');
repeat
RadialWalkTolerance(15985378, 356, 359, 45, -1, 0, 15);
wait(RandomRange(2000,2500));
until (FindObj (x, y, 'remennik', 8673603, 25)) or (TimeFromMark(T) > 30000)
begin
Mouse(x, y, 2, 2, false);
ChooseOption('Bank');
wait(Randomrange(1500,2000));
if BankScreen then
DepositAll;
wait(RandomRange(500,1000));
CloseBank;
end;
If (TimeFromMark(T) > 35000) or (InvFull) then
begin
BankTheLootFailsafe;
end
else
if TimeFromMark(T) > 60000 then
begin
Writeln('error 18');
Logout;
TerminateScript;
end
else
end;

procedure WalkToBanker;

var
T: Integer;
status: string;
ToBank: TPointArray;

begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
MarkTime(T);
begin
FindNormalRandoms;
GameTab(26);
if WearingItem(11) then
begin
MouseEquippedItem('ring', MOUSE_RIGHT);
ChooseOption('aemon');
Wait(RandomRange(9000,11000));
end;
end;
begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
SPS_Setup(RUNESCAPE_SURFACE,['13_4']);
ToBank:=[Point(5576, 1811), Point(5587, 1802), Point(5590, 1792), Point(5591, 1777), Point(5592, 1763), Point(5591, 1748), Point(5590, 1735), Point(5589, 1723)];
if SPS_WalkPath(ToBank) then
Status := 'ToBank'
else
begin
Status :='WalkToBanker';
WalkToBanker;;
end;
end;
end;

Function BankBanker : Boolean; //Credits to Kasi for making this procedure
//and at the same time teaching how to split
//TPAs to reduce the amount of total points
//and find the point closest to player first.
//This makes the script look much more human
//like and increased the speed a good bit. I
//really appreciate it!
var
I, T, TimesFailed: integer;
BankerTPA : TPointArray;
Banker2DTPA : T2DPointArray;
TB : TBox;
begin
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
FindNormalRandoms;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.11, 0.07);
FindColorsTolerance(BankerTPA, 8079669, MSX1, MSY1, MSX2, MSY2, 10);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);
SplitTPAExWrap(BankerTPA, 12, 12, Banker2DTPA);
SetLength(BankerTPA, 0);
for I := 0 to High(Banker2DTPA) do
begin
TB := GetTPABounds(Banker2DTPA[I]);

if ((iAbs(TB.X1 - TB.X2) > 10) and (iAbs(TB.Y1 - TB.Y2) > 10) and
(iAbs(TB.X1 - TB.X2) < 50) and (iAbs(TB.Y1 - TB.Y2) < 50)) then

CombineTPAWrap(BankerTPA, [MiddleTPA(Banker2DTPA[I])], BankerTPA);
end;
SortTPAFrom(BankerTPA, Point(MSCx, MSCy));
MarkTime(T);
for i := 0 to High(BankerTPA) do
begin
MMouse(BankerTPA[I].x, BankerTPA[I].y, 0, 0);
if waituptext('remennik', 100) then
begin
ClickMouse2(Mouse_Right);
if WaitOption('Bank', 600) then
begin
WaitNotMoving(true);
ProgressReport;
if BankScreen then
DepositAll;
wait(RandomRange(500,1000));
CloseBank;
end;
Result := True;
Break;
end else
begin
if TimeFromMark(T) > 10000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
AntiBan;
BankBanker;
end;
if TimesFailed >= 6 then
begin
AntiBan;
BankTheLootFailsafe;
end;
if TimesFailed >= 9 then
begin
AntiBan;
Break;
Logout;
TerminateScript;
end;
end;
end;
end;
end;


procedure BankTheLoot;
begin
WalkToBanker;
BankBanker;
end;


procedure MainLoop;
begin
if (InvFull = True) then
begin
BankTheLoot;
ProgressReport;
end;
repeat
TeleVarrock;
WalkToPotatos;
repeat
Gate;
until (GateIsOpen = True)
WalkIntoPatch;
repeat
FindPotato;
until (InvFull = True)
BankTheLoot;
ProgressReport;
until (LoggedIn = False)
end;

Begin
Setup;
MainLoop;
End.

EDIT: Updated colors for BankBanker as they seemed to have changed again…

Element17

2013-06-06 12:01:26

NKN has a gate opening function that works pretty darn good. It is in the snippet section I believe. Try using that, but be sure to give credits.

rotchy1

2013-06-06 12:07:08

From: Element17
NKN has a gate opening function that works pretty darn good. It is in the snippet section I believe. Try using that, but be sure to give credits.


I will look for it, thanks!