SRL Archive - RS3 Help

Weird Access Violation


o0Matthius0o

2014-08-30 00:34:42

When the bot is ran it will only stay going for about 5 mins. Then i will get an access violation. Here is a snippet from the debug.

isMouseOverText(): True
—- TRSChooseOption.optionsExist(): Succesfully found option "ttack" in "Attack Fire giant -"
– TRSChooseOption._select():
—- Options found: [Attack Fire giant -, Walk here, Examine Fire giant ,, Cancel]
—- Found option "ttack Fire giant" in "Attack Fire giant -"
– TRSChooseOption.select() result = true

Can someone help me out? kinda stumped. Im pretty sure its in my clickEnemy() procedure and i have tried sorting the if statements in different ways. Here is my code. It fights fire giants. Preferable start location is in the chaos tunnels.

Please look over most of the comments. I know its messy but its a work in progress.

program new;
{$DEFINE SMART}
{$I SRL-6/SRL.simba}
{$I SPS/LIB/SPS-RS3.simba}


const
//-------Login Settings-------//
PLAYER_FILE = 'Godlist';
NICKNAME = 'Main';
LOGIN_WORLD = 0;
//ENABLE_DEBUG = False;
//----------------------------//
//-------Break settings-------//
ENABLE_BREAKS = True;

MIN_PLAY_TIME = 45; //45
MAX_PLAY_TIME = 180; //180

MIN_BREAK_TIME = 5;
MAX_BREAK_TIME = 45;
//----------------------------//

var
//-------Global Variables-------//
TotalBreakTime, StatsTime : TTimeMarker; //Timers Here

BreakTimeTotal, BreakTime, Breaked, XpGained : integer; //Stats Here

//-------------------------------------------------------------------------------------------------------------------------------//
procedure resetBreakTimer();
begin
BreakTime := getSystemTime() + gaussRangeInt(MIN_PLAY_TIME * 60000, MAX_PLAY_TIME * 60000);
end;

//-------------------------------------------------------------------------------------------------------------------------------//



//-------------------------------------------------------------------------------------------------------------------------------//
procedure setup();

begin
smartEnableDrawing := true;
//disableSRLDebug := not ENABLE_DEBUG;
setupSRL();

players.Setup([NICKNAME], PLAYER_FILE);
currentPlayer := 0;
players[currentPlayer].world := LOGIN_WORLD;

exitTreasure();

resetBreakTimer();
TotalBreakTime.start();
TotalBreakTime.pause();
end;
//-------------------------------------------------------------------------------------------------------------------------------//

procedure healthEat();
var
heartBar, x, y : integer;
begin
heartBar := DTMFromString('mlwAAAHicY2dgYJjACMHTgbgLyp4CxD1AfBWILyDhO0B8HYpnKMky/Lp9geH3wgUM9/KCGOp1jRhiGJgYOiWlGPABRjwYCgB+9BMr');
if actionBar.getHPPercent() <= 75 and actionBar.getAdrenalinePercent() > 20 then
begin
repeat
findDTM(heartBar, x, y, mainScreen.getBounds()); //Looks for the pink heart in your actionBar
until(True);
sendKeys('0', 250, 40);
end;
if actionBar.getHPPercent() <= 50 then
begin
repeat
sendKeys('z', 250, 40);
until actionBar.getHPPercent() > 50;
end;

end;


//-------------------------------------------------------------------------------------------------------------------------------//
function antiBan(): boolean;
var
antiBanNum : integer;
begin
antiBanNum := random(1500);
if antiBanNum <= 100 then
begin
writeLn('Antiban Time!');

case antiBanNum of
1..10: boredHuman(false);
11..25: hoverRandomSkill();
26..31: hoverOnlineFriend();
32..52: mouseMovingObject();
53..69: mouseOffClient(4);
70..80: randomCameraAngle(MS_ANGLE_HIGH);
81..90: randomCompass(10, 40, True);
91..100: wait(randomRange(3000, 5000));

end;
end;
end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
function timeUntilBreak() : string;
var
breakFromNow, H, M, S : integer;
begin
if ENABLE_BREAKS then
begin
breakFromNow := BreakTime - getSystemTime();
convertTime(breakFromNow, H, M, S);
result := (toStr(H) + 'h ' + toStr(M) + 'm ' + toStr(S) + 's');
end else
result := ('Breaking disabled');
end;
//-------------------------------------------------------------------------------------------------------------------------------//



//-------------------------------------------------------------------------------------------------------------------------------//
procedure takeBreak();
var
H, M, S, HH, MM, SS, breakFor, timeLeft : integer;
breakStartTimer : TTimeMarker;

begin
if not ENABLE_BREAKS then
exit;

if (getSystemTime() >= BreakTime) then
begin
TotalBreakTime.start();
writeLn('Taking a break');

if random(2) = 0 then
players[currentPlayer].logout()
else
players[currentPlayer].exitToLobby();

breakFor := gaussRangeInt(MIN_BREAK_TIME * 60000, MAX_BREAK_TIME * 60000);
convertTime(breakFor, H, M, S);
writeLn('You are taking a break for: ' + toStr(H) + 'h ' + toStr(M) + 'm ' + toStr(S) + 's');

breakStartTimer.start();

repeat
timeLeft := breakFor - breakStartTimer.getTime();
convertTime(timeLeft, HH, MM, SS);
writeLn('Ending break in: ' + toStr(HH) + 'h ' + toStr(MM) + 'm ' + toStr(SS) + 's');
wait(25000 + random(4000));
until breakFor < breakStartTimer.getTime();

inc(Breaked);
resetBreakTimer();
TotalBreakTime.pause();
players[currentPlayer].login();
wait(gaussRangeInt(1500, 3500));
exitTreasure();
minimap.clickCompass();
end;
end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
procedure doAbilities();
var
i : integer;
keyStr : string;

begin
for i := 9 downto 1 do
begin
if (actionBar.getAbilityCooldown(i) = 1) then
begin
case i of
0..9: keyStr := intToStr(i);
10: keyStr := '0';
11: keyStr := '-';
12: keyStr := '=';
end;

SendKeys(keyStr[1], 60 + Random(60), 60 + Random(60));

exit;
end;
end;
end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
function clickEnemy(): boolean;
var
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
hpDTM, hBarDTM, fightDTM: integer;
isMobDead : boolean;
misClick : TTimeMarker;
begin
if isLoggedIn() then
begin
fightDTM := DTMFromString('mbQAAAHicY2VgYLgCxLqMDAxGQKwGxNpAfBgodgiITwPxJSA+A8SXJ0ky3Ll+ieHh3RsM0WYKDBUFsQzYACMWDAYAtIEOEA==');
hBarDTM := DTMFromString('mKgEAAHic42NgYFBhZGDwB+IgIP4J5P8GYkkgW5sRQmsBsQUQOwIxGxC/Bcp7AelzDBB8EYgvAPEZJHwJis8g0YeB+CgQ2wgLM2hzcsJpRTY2MI0L84lIMvCJSjFIgtxFBmYkE6MCAFnIFUE=');
hpDTM := DTMFromString('mbQAAAHicY2VgYFBhZWBQBmI1IFYFYiUg3gwUXw/EG4B4GxTbCAsz/D/NynB3AwuYDtMRZJAEiqNjRiwYDADI8wr3');
isMobDead := false;
repeat

if findDTM(fightDTM, x, y, mainscreen.getBounds()) = True then
begin
writeLn('You are in a fight');
exit;
end;
findColorsSpiralTolerance(x, y, TPA, 2571108, mainScreen.getBounds(), 14, colorSetting(2, 0.20, 0.82));
if length (TPA) < 1 then //If there are no monsters found it will terminate and rerun.
begin
exit;
end;
ATPA := TPA.toATPA(50, 50);
ATPA.sortFromMidPoint(mainscreen.playerPoint); //Chooses the closest monster to you.

smartImage.debugATPA(ATPA);
for i := 0 to 4 do//high(ATPA) do //Finds and draws all the monsters a debug box.
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['ttack'], 500) then
begin
fastClick(MOUSE_RIGHT);
if chooseOption.optionsExist(['ttack']) then // attacks mob
begin
chooseOption.select(['ttack Fire giant']);
wait(randomRange(4000, 4500));
end;
end;
end;
until findDTM(fightDTM, x, y, mainscreen.getBounds()) = True;
clearDebug();
writeLn('You are in a Fight');
result := True;


//misClick.start();
//repeat
//writeLn(misClick.getTime());
(* if findDTM(hpDTM, x, y, mainScreen.getBounds()) then //Will keep fighting the monster til their health reaches 0
begin
writeLn('DTM found, Moster hp 0');
clearDebug();
if findDTM(hBarDTM, x, y, mainScreen.getBounds()) then
begin
writeLn('DTM found, Monster Healthbar empty');
isMobDead := True;
break;
end;
end;
writeLn(misClick.getTime()); *)
//doAbilities();
// healthEat();
//until isMobDead = True or misClick.getTime() > randomRange(3,5) * 60000;//180000;
//if misClick.getTime() > randomRange(3, 5) * 60000 then
//begin
// writeLn('Failed to find enemy');
// end;
smartImage.clear();
//antiBan();
//takeBreak();
//wait(randomRange(5000, 8000));
End else
if not isLoggedIn() then
begin
writeLn('You are not logged in');
exit;
end;

end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
function isMonsterDead(): boolean;
var
hpDTM, hBarDTM, x, y : integer;
isMobDead : boolean;
misClick : TTimeMarker;
begin
hBarDTM := DTMFromString('mKgEAAHic42NgYFBhZGDwB+IgIP4J5P8GYkkgW5sRQmsBsQUQOwIxGxC/Bcp7AelzDBB8EYgvAPEZJHwJis8g0YeB+CgQ2wgLM2hzcsJpRTY2MI0L84lIMvCJSjFIgtxFBmYkE6MCAFnIFUE=');
hpDTM := DTMFromString('mbQAAAHicY2VgYFBhZWBQBmI1IFYFYiUg3gwUXw/EG4B4GxTbCAsz/D/NynB3AwuYDtMRZJAEiqNjRiwYDADI8wr3');
isMobDead := false;
misClick.start();
if misClick.getTime() > 1 * 60000 then
begin
exit;
end;
//repeat
if findDTM(hpDTM, x, y, mainScreen.getBounds()) then //Will keep fighting the monster til their health reaches 0
begin
writeLn('DTM found, Moster hp 0');
clearDebug();
if findDTM(hBarDTM, x, y, mainScreen.getBounds()) then
begin
writeLn('DTM 2 found, Monster Healthbar empty');
isMobDead := True;
result := True;
end;
end;
//until isMobDead = True;
//result := True
end;

//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
procedure pickUpBones();
var
x, y, i : integer;
TPA: TPointArray;
ATPA: T2DPointArray;

begin
if IsLoggedIn() then
begin

findColorsSpiralTolerance(x, y, TPA, 9015205, mainScreen.getBounds(), 21, colorSetting(2, 0.08, 0.43));
if length (TPA) < 1 then //If there are no bones found it will terminate and rerun.
begin
exit;
end;
ATPA := TPA.toATPA(20, 20);
ATPA.sortFromMidPoint(mainscreen.playerPoint); //Chooses the closest drop to you.

smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
wait(1000);
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['ake'], 500) then
begin
mouse(middleTPA(ATPA[i]), MOUSE_RIGHT); // picks up the bones at the closest point to you.
chooseOption.select(['ake Bones']);
tabBackPack.waitForShift(10000);
smartImage.clear();
break;
end;
end;
end;
end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
procedure buryBones();
var
slotNum, i : integer;
begin
if isLoggedIn() then
begin

slotNum := 28;
for i := 1 to slotNum do //for every time "i" is not equal to slotNum
begin //keep clicking the bones in the next box over.
tabBackPack.mouseSlot(i, MOUSE_LEFT);
wait(randomRange(1500, 2300)); //wait until the bones are out of the inventory
i + 1;
end;
end;
end;
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
procedure checkAngle();
var
angle : extended;

begin
angle := minimap.getAngleRadians();

if angle <> MM_DIRECTION_NORTH and MS_ANGLE_HIGH then // checks to see if the camera is in the correct position. If its not it will put it there.
begin
mainScreen.setAngle(MS_ANGLE_HIGH);
minimap.setAngle(MM_DIRECTION_NORTH);
end;

end;
//-------------------------------------------------------------------------------------------------------------------------------//



//-------------------------------------------------------------------------------------------------------------------------------//
(*
procedure checkHealthAndEat();

var
hp: integer;

begin
if (healthTimer.getTime() < 8000) then
exit;

hp := actionbar.getHPPercent();
{$IFDEF DEBUG_ON}
writeln('***** Health check returning ', hp, ' percent');
{$ENDIF}

if (hp < healthPercentToEatAt) then
sendKeys('z', 250, 40);

if (hp < healthPercentToQuit) then
begin
writeln('***** Terminating script due to low health');
terminateScript();
end;

healthTimer.start();
end;
*)
//-------------------------------------------------------------------------------------------------------------------------------//


//-------------------------------------------------------------------------------------------------------------------------------//
procedure monsterHealthDTM();
var
hpDTM: integer;
isMobDead : boolean;
begin
hpDTM := DTMFromString('mbQAAAHicY2VgYFBhZWBQBmI1IFYFYiUg3gwUXw/EG4B4GxTbCAsz/D/NynB3AwuYDtMRZJAEiqNjRiwYDADI8wr3');
end;
//-------------------------------------------------------------------------------------------------------------------------------//



begin
setup();
repeat
if not isLoggedIn() then
begin
players[currentPlayer].login();
end;
until isLoggedIn();
mainScreen.setAngle(MS_ANGLE_HIGH);
minimap.setAngle(MM_DIRECTION_NORTH);
repeat
clickEnemy();
repeat
doAbilities();
isMonsterDead();
until isMonsterDead() = True;
healthEat();
antiBan();
takeBreak();
wait(randomRange(3000, 3500));
until(false);
end.

riwu

2014-08-30 01:20:11

Didn't check the whole script but since u said it's in your clickEnemy() procedure:
for i := 0 to 4 do//high(ATPA) do //Finds and draws all the monsters a debug box.
why comment out the high(ATPA)? if the length of atpa is higher than 5 then u will get access violation?
also u shd probably break out of the for loop if succeeded.

o0Matthius0o

2014-08-30 01:28:48

From: riwu
Didn't check the whole script but since u said it's in your clickEnemy() procedure:
for i := 0 to 4 do//high(ATPA) do //Finds and draws all the monsters a debug box.
why comment out the high(ATPA)? if the length of atpa is higher than 5 then u will get access violation?
also u shd probably break out of the for loop if succeeded.


I had it commented out so it wouldnt search through more than 5. When it sorts through High then it draws waaaayy to many debug boxes. And it will check each one even if there is nothing in them.

Thank you though! Your solution actually explains alot of issues i have been having with it. I will let you know if it works.

riwu

2014-08-30 02:32:33

From: o0Matthius0o
I had it commented out so it wouldnt search through more than 5. When it sorts through High then it draws waaaayy to many debug boxes. And it will check each one even if there is nothing in them.

Thank you though! Your solution actually explains alot of issues i have been having with it. I will let you know if it works.

Then you could do

for i := 0 to Min(4, High(ATPA)) do
this will make sure it will go to at most 4, but less if there's less than 4.
You could also do a length at start of the for loop

if Length(ATPA[i]) < x then //x is the length to skip
Continue;
That would ensure it skips over tpas with low lengths.