SRL Archive - RS3 Help

How do i keep my player in a certain area?


beefman

2014-07-06 11:17:36

I've tried different ways to keep my player in a certain area in sps. I'd run my bot and within a few hours or sometime minutes i will look back at my bot to see that his wondered of to a different location..

This is the location i want my script to stay in:

This is the map without the red box:

This is my sps code at the moment:
 
procedure Coords();
begin
if timer.getTime() > randomRange(15000,30000) then // if timer been running > 15s - 30s
begin
WriteLn('Walking to coords');
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));
timer.reset(); // reset timer back to 0
timer.start() // start it again
end;
end;

If anyone has any knowledge that they think could help me, i would appreciated if you could help me out. Thanks :) I'm going to get a repetition from posting on this help forum soon!

masterBB

2014-07-06 11:28:33

function isInCorrectArea(): Boolean;
var
myPos: TPoint;
correctArea: TBox;
begin
myPos := sps.getPlayerPos();
correctArea := IntToBox(164, 197, 174, 210);
result := PointInBox(myPos, correctArea);
end;

function correctPosition(): Boolean;
begin
if(not(isInCorrectArea())) then
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

result := isInCorrectArea();
end;

then in your loops something like this:

if(not(correctPosition())) then
begin
writeln('position couldn''t be corrected');
Exit;
end;

beefman

2014-07-06 11:32:58

From: masterBB
function isInCorrectArea(): Boolean;
var
myPos: TPoint;
correctArea: TBox;
begin
myPos := sps.getPlayerPos();
correctArea := IntToBox(164, 197, 174, 210);
result := PointInBox(myPos, correctArea);
end;

function correctPosition(): Boolean;
begin
if(not(isInCorrectArea())) then
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

result := isInCorrectArea();
end;

then in your loops something like this:

if(not(correctPosition())) then
begin
writeln('position couldn''t be corrected');
Exit;
end;


Thank you for the quick reply. But i don't want it to end if it can't find the correct location?

masterBB

2014-07-06 11:53:45

From: beefman
Thank you for the quick reply. But i don't want it to end if it can't find the correct location?


It is a technique called failsafing. This one has no secundaire means of failsafing. If it can't position itself back to the middle, wouldn't it be better if the bot stopped and logged in another account if avaible? This ensures the end user the script never screws up so bad that it gets you banned(walking circles in the wildy for example ;) ).

If you want to make it more stable you can think of a secundaire mean of walking back to the area. I wrote all of this in browser btw. It is more a concept than a working code snippet.


function correctPosition(): Boolean;
var
myPos: TPoint;
begin
if not(isInCorrectArea()) then
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if not(isInCorrectArea()) then
begin
//second mean of walking (Radial walk? blind walk?)
end;

result := isInCorrectArea();
end;

beefman

2014-07-06 12:07:48

From: masterBB
It is a technique called failsafing. This one has no secundaire means of failsafing. If it can't position itself back to the middle, wouldn't it be better if the bot stopped and logged in another account if avaible? This ensures the end user the script never screws up so bad that it gets you banned(walking circles in the wildy for example ;) ).

If you want to make it more stable you can think of a secundaire mean of walking back to the area. I wrote all of this in browser btw. It is more a concept than a working code snippet.


function correctPosition(): Boolean;
var
myPos: TPoint;
begin
if not(isInCorrectArea()) then
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if not(isInCorrectArea()) then
begin
//second mean of walking (Radial walk? blind walk?)
end;

result := isInCorrectArea();
end;


Thanks. Coming up with a failsafe suggestion. I had a conversation similar with the mayor the other day and he mentioned about teleporting to edgeville as it's only a 30 second walk to the location. Would that be suitable for my script? But, i don't want to have keep teleporting to edgeville if the scripts only out of the sps walk range by a few clicks.

Element17

2014-07-06 12:22:27

Well what do you want the script to do if it isn't in the right area? What MasterBB said was a good idea. Also if you don't want to teleport to Edgeville then don't but its going to ensure that you don't end up somewhere else.

beefman

2014-07-06 12:29:00

Would this work?


function isInCorrectArea(): Boolean;
var
myPos: TPoint;
correctArea: TBox;
begin
myPos := sps.getPlayerPos();
correctArea := IntToBox(164, 197, 174, 210);
result := PointInBox(myPos, correctArea);
end;

function correctPosition(): Boolean;
begin
if(not(isInCorrectArea())) then
SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if not(isInCorrectArea()) then
begin
//second mean of walking (Radial walk? blind walk?)
end;

result := isInCorrectArea();
end;


if isInCorrectArea = false then
begin
correctPosition()
end;


How would i then add the teleport?

if isInCorrectArea = false then
begin
teleport;

Something along that line?

beefman

2014-07-06 13:27:14

When i used what i quoted up there, it just clicks on the mini map every few seconds :/

masterBB

2014-07-06 13:28:07

An easier way to read would be:

function correctPosition(): Boolean;
begin
result := true;

if(isInCorrectArea()) then Exit;

SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if(isInCorrectArea()) then Exit;

//blindwalk code

if(isInCorrectArea()) then Exit;

//teleport code

result := isInCorrectArea();
end;

beefman

2014-07-06 14:26:48

From: masterBB
An easier way to read would be:

function correctPosition(): Boolean;
begin
result := true;

if(isInCorrectArea()) then Exit;

SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if(isInCorrectArea()) then Exit;

//blindwalk code

if(isInCorrectArea()) then Exit;

//teleport code

result := isInCorrectArea();
end;


okay thanks. What do you mean by blind walk? Also, when i use that code is clicks on the mini map pretty much every time it clicks a tree.

Here's the script:

program scriptTemplate;

{$DEFINE SMART} // Always have this to load smart
{$I SRL-6/SRL.simba} // To load the SRL include files
{$I SPS/lib/SPS-RS3.Simba} // To load the SPS include files

procedure declarePlayers();
begin
setLength(players, 1);
with players[0] do
begin
loginName := '';
password := '';
isActive := true;
isMember := false;
end
currentPlayer := 0;
end;

var
TreeCount: integer; //global variable
CraftCount: integer;
timer: TTimeMarker; //declared it here
ShaftCount: integer;



procedure ChopTree();
var
x, y: integer;
begin // colour, tol CTS, hue, sat
if mainscreen.findObject(x, y, 1455914, 11, colorSetting(2, 0.17, 0.58), mainscreen.playerPoint, 72, 131, 100, ['down Ever','last','ever'], MOUSE_LEFT) then
writeLn('Clicking Tree') //this is the exception for the semicolon because it is followed by an else statement
else
SPS.walkToPos(point(randomRange(153, 161), randomRange(231 ,250)));

if tabBackPack.waitForShift(randomRange(3000,5000)) then
begin
writeLn('Tree cut. We got a log.');
TreeCount := TreeCount + 1 ;
end;

if (TreeCount > 3) and (TreeCount < 7) then
begin
writeLn('rotating camera angle');
randomCompass(0, 360, false);
TreeCount := 0;
end;
end;


procedure Shaft_antiBan();
begin
Case Random(6) of
0 : hoverSkill(SKILL_WOODCUTTING);
1 : mouseOffClient(OFF_CLIENT_RANDOM);
2 : randomGameTab(true);
3 : randomRClickItem();
4 : sleepAndMoveMouse(1000 + random(2000));
5 : randomCompass(10, 30, true);
end;
end;


procedure CutShafts();
begin
tabBackpack.Open;
writeLn('Crafting logs into shafts.')
if tabBackpack.isFull() then
begin
tabBackpack.mouseSlot(RandomRange(2 ,5), MOUSE_LEFT);
CraftCount := CraftCount + 1 ;
ShaftCount := ShaftCount + 405;
end;

if (CraftCount = 1) then
begin
wait(randomRange(700,1400));
Mouse(285, 209, 20, 20, MOUSE_LEFT);
wait(randomRange(700,1400));
productionScreen.clickStart();
mouseOffClient(OFF_CLIENT_RANDOM);
Shaft_antiBan();
wait(randomRange(46000,50000));
end;

if (CraftCount > 1) then
begin
wait(randomRange(700,1400));
productionScreen.clickStart();
Shaft_antiBan();
wait(randomRange(46000,50000));
end;
end;

function isInCorrectArea(): Boolean;
var
myPos: TPoint;
correctArea: TBox;
begin
myPos := sps.getPlayerPos();
correctArea := IntToBox(164, 197, 174, 210);
result := PointInBox(myPos, correctArea);
end;

function correctPosition(): Boolean;
begin
result := true;

if(isInCorrectArea()) then Exit;

SPS.walkToPos(point(randomRange(174, 164), randomRange(210,197)));

if(isInCorrectArea()) then Exit;

//blindwalk code

if(isInCorrectArea()) then Exit;

//teleport code

result := isInCorrectArea();
end;



// main loop
begin
disableSRLDebug := true;
smartEnableDrawing := false;
setupSRL();
SPS.setup('Maps', RUNESCAPE_OTHER);
spsAnyAngle := true;
declarePlayers();

if not isLoggedIn() then
begin
players[currentPlayer].login();

minimap.setAngle(MM_DIRECTION_NORTH);
mainScreen.setAngle(MS_ANGLE_HIGH);
mainScreen.setZoom(true)
end;

timer.start(); // start the timer initially here

repeat
repeat
isInCorrectArea();
correctPosition();
chopTree();
until tabBackpack.isFull();
CutShafts();
writeln(msToTime(getTimeRunning(), TIME_FORMAL));
until false;
end.