SRL Archive - OSR Help

Error: Out Of Range at line 234. D:<


Zota

2010-12-03 23:32:41

K so, I'm using this:

if ((not(TileOnMS(Farmer.Tile, 0))) and (Farmer.ID = 2234)) then

As you can see I'm checking if the Farmer is on the MS or not. Also checking whether the farmer is actually around us at all.

Most of the time this works, and it'll then continue on to walk to the farmer who may have walked off the MS using the minimap.
My only problem is.. sometimes I'll get an out of range error.
Error: Out Of Range at line 234

Line 234 is the one I showed you above. What's up with this?

cheers o-0

Luke-

Train

2010-12-04 00:49:16

Where are you handling I?

Zota

2010-12-04 01:00:36

I'm not, I'm simply declaring it as an integer. I have no idea what it is used for, but without it, the statement wont work.

Luke-


edit:
Just checked what it was storing. It's storing '0'. Lol.

Sex

2010-12-04 01:06:51

You know if you posted the whole script It'd help a whole lot.

Zota

2010-12-04 01:14:34

Ye it probably would lol XD

Here:

program MasterFiever;

{$i SRL/SRL/Misc/SMART.scar}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}

var
x, y, stop, startexp: Integer;

const
SMARTWORLD = 72;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := ''; //Your username
Players[0].Pass := ''; //Your password
Players[0].Nick := 'own'; //3-4 letters from your username
Players[0].Active := true;
end;

procedure Antiban;
begin
case Random(400) of
3: HoverSkill('thieving', false);
end;
end;

{ getxpof (broken gametab 2)
function GetXPof(skill: string; t:integer): integer; // From narcle's autofighter
var
p: TPoint;
i, tx, ty, x, y, l, II, WaitT: Integer;
xp, Nums, text2, xpis, typeis : string;
begin
Result := -1;
case t of
1: typeis := 'urrent';
2: typeis := 'level';
3: typeis := 'ainder';
end;
if (not LoggedIn) or (not TabExists(2)) then Exit;
GameTab(2);
if (GetCurrentTab <> 2) then Exit;
p := SkillToCoords(Skill);
if (p.x < 1) then Exit;
MMouse(p.x, p.y+7, 12, 4);
repeat
WaitT := WaitT+1;
wait(100);
if WaitT >= 300 then exit;
until findcolor(x, y, 10551295, 554, 205, 743, 465);
wait(300 + Random(100))
if (not FindColor(x, y, 10551295, MIX1, MIY1, MIX2, MIY2)) then Exit;
if IsTextInAreaEx(x, y, x + 60, y + 60, tx, ty, typeis, 0, SmallChars, False, False, 0, 1, 0) then
xp := GetTextAtEx(tx, ty, 0, SmallChars, False, True, 0, 1, 0, 50, False, tr_AllChars);
for l := 1 to Length(xp) do
begin
if (xp[l] = 'O') then text2 := text2 + '0' else text2 := text2+ xp[l];
end;
Nums := '01234567890';
for I := 1 to Length(Text2) do
begin
for II := 1 to 10 do
begin
if (Copy(text2, I, 1) = Copy(Nums, II, 1)) then
xpis := xpis + Copy(Text2, I, 1);
end;
end;
try
result := strtoint(xpis);
Status(skill+' = ' +xpis);
except
result := 0;
status('Failed to get XP');
end;
end;
}

Procedure Login;
begin
LoginPlayer;
wait(1000+random(1000));
MakeCompass('N');
SetAngle(true);
GetAllLevels;
FindNormalRandoms;
Startexp := GetXP('thieving');
end;

Function Health : integer; //VeryBigKitty's ;p
begin
result := (R_GetMMLevels('hp'));
end;

procedure Bank;
var
food, inventory : TInvItemArray;
monkfish : TIntegerArray;
i : Integer;

begin
monkfish := ([7946, 7947]);
if ((InvFull()) and ((not(R_ItemIDExistsEx(monkfish, inventory)))) or (Health < 160) and ((not(R_ItemIDExistsEx(monkfish, inventory))))) then
begin
writeln('Inventory full. Banking.');
repeat
MakeCompass('n');
wait(500 + random(250));
RadialWalk(7368054, 60, 100, 40, -1, 0);
R_Flag;
until findsymbol(x,y,'bank');
begin
writeln('found bank');
Mouse(x,y,2,3,true);
R_Flag;
wait(1000+random(500));
end;
OpenBankFast('db');
if (BankScreen) then
begin
Wait(30+random(65));
DepositAll;
SearchBank('Monkfish');
Wait(1500 + random(1220));
Withdraw(0, 0, 10);
CloseBank;
food := GetInventoryItems;
if (food[i].Name = 'Monkfish') then
begin
writeln('we have food');
RadialWalk(7105650, 310, 280, 70, -1, 0);
R_Flag;
end else
Bank;
end;
end;
end;

procedure CheckHealth;
var
x, y, monkfishDTM : Integer;
inventory : TInvItemArray;
monkfish : TIntegerArray;
begin
monkfish := ([7946, 7947]);
monkfishDTM := DTMFromString('mrAAAAHic42BgYHBggmAvIA4CYm8gdgZiMyA2BeLnQD' +
'X3ofgOED8D4rdA/AKIHwJxoLsdkGTCg/EDRgIYBgAQ1Ao3');
if ((Health < 160) and (R_ItemIDExistsEx(monkfish, inventory))) then
begin
repeat
if FindDTM(monkfishDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
WriteLn('Health is dangerously low!');
MMouse(x, y, 1, 1);
GetMousePos(x, y);
if (pos('Eat', rs_GetUpText) > 0) then
begin
Mouse(x, y, 1, 1,true);
wait(1500+random(500));
end;
end;
until Health > 160
FreeDTM(monkfishDTM);
end else
FreeDTM(monkfishDTM);
Bank;
end;

{*******************************************************************************
function Stunned: Boolean;
By: NCDS
Description: Return's True if stunned by NPC.
*******************************************************************************}
function Stunned: Boolean;
var
P : TPoint;
Search : TBox;

begin
P.x := MSCx;
P.y := MSCy;
Search.x1 := P.x - 30;
Search.y1 := P.y - 30;
Search.x2 := P.x + 30;
Search.y2 := P.y + 30;
Result := FindColorTolerance(P.x, P.y, 5106941, Search.x1, Search.y1,
Search.x2, Search.y2, 5) and
IsChatBoxTextBetween('stunned', 0, 7, 8);
end;

procedure CheckInv;
var
monkfishDTM : Integer;
inventory : TInvItemArray;
monkfish : TIntegerArray;

begin
monkfish := ([7946, 7947]);
monkfishDTM := DTMFromString('mrAAAAHic42BgYHBggmAvIA4CYm8gdgZiMyA2BeLnQD' +
'X3ofgOED8D4rdA/AKIHwJxoLsdkGTCg/EDRgIYBgAQ1Ao3');
if InvFull() and R_ItemIDExistsEx(monkfish, inventory) then
begin
if FindDTM(monkfishDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
WriteLn('Inventory full. Eating food to clear space.');
MMouse(x, y, 1, 1);
wait(200+Random(121));
GetMousePos(x, y);
if (pos('Eat', rs_GetUpText) > 0) then
begin
Mouse(x, y, 1, 1,true);
wait(1500+random(500));
end;
end;
FreeDTM(monkfishDTM);
end else
FreeDTM(monkfishDTM);
Bank;
end;

function ThieveFarmer: Boolean;
var
i : Integer;
Farmer : TNPCArray;
FarmerPos : TPoint;

begin
if InvFull() then CheckInv;
begin
CheckHealth;
Farmer := GetNPCsBy(2234);
if Stunned then
begin
writeln('Stunned...');
Wait(RandomRange(3000, 500));
end;
if((not(TileOnMS(Farmer[i].Tile, 0))) and (Farmer[i].ID = 2234)) then
begin
FarmerPos := TileToMM(Farmer[i].Tile);
Mouse(FarmerPos.x, FarmerPos.y, 4, 4, True);
if(R_FlagExists)then
R_Flag;
end;
if(TileOnMS(Farmer[i].Tile, 0))and(Farmer[i].ID = 2234) then
begin
FarmerPos := TileToMS(Farmer[i].Tile, 0);
MMouse(FarmerPos.x, FarmerPos.y, 1, 1);
if(OptionExists('Pickpocket') and (R_IsUpText('Master Farmer'))) then
begin
Mouse(FarmerPos.x, FarmerPos.y, 1, 1, true);
wait(50+random(100));
R_Flag;
end;
end;
end;
end;

begin
Smart_Server := SMARTWORLD;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;

SetupSRL;
DeclarePlayers;
Wait(500);
Login;
repeat
if not(loggedin) then login;
FindNormalRandoms;
repeat
ThieveFarmer;
FindNormalRandoms;
CheckHealth;
Antiban;
until(stop = 1);
stop := 0;
until(false);
end.

Luke-


edit:
just realised I missed out a result on one of the functions (thieverfarmer). Added it in and retesting..

edit edit:
just got the error again.. lol. Took a bit longer this time :P
(the script works completely fine, better than expected actually. It will just randomly stop)

edit edit edit:
ok basically.. I just tried it on a f2p world where the farmer obviously wouldn't be there. The thievefarmer procedure resulted in instant error. It'd give that error just as soon as the script had finished the post-login stuff like antiban checking stats etc. So basically… somehow the farmer in the p2p world is either: completely vanishing for a split second like some badass ninjamasterfarmer. Or the function isn't searching far enough (the farmer goes too far away)

possibility: I was just messing with the (not(TileOnMS(Farmer.Tile, 0))) and found that the last digit (which is stated as 'height' in the tileonms function) is the distance at which the farmer should be before it clicks the minimap to get closer. Setting it to 50000 pretty much made it click him everytime, even when standing next to him, lol. I think I just need to adjust this until I get the right distance.


can't get it to work S_S head hurts XD

TomTuff

2010-12-04 01:36:26

you'll need a for..to..do loops.

example:

function ForToDoLoopExample: TTile;
var
NPCs: TNPCArray;
i: Integer;
begin
if not LoggedIn then
Exit;
NPCs := SortNPCs(GetNPCs);
for i := 0 to High(NPCs) do //<-- call the loop like this
begin
if (NPCs[i].Name = 'Man') then
begin
Result := NPCs[i].Tile;
Break;
end;
end;
end;

Zota

2010-12-04 01:53:14

This is going to take me ages X'D

Do you mean have a seperate function just to sortNPCs ?
or do you mean integrate the fortodo loop into my thieving function

Luke-

TomTuff

2010-12-04 02:05:58

From: Zota

This is going to take me ages X'D

Do you mean have a seperate function just to sortNPCs ?
or do you mean integrate the fortodo loop into my thieving function

Luke-


No, that can go in your thieving function. it was just an example of how to call the loop.

Zota

2010-12-04 02:18:41

Oh damn.. well I already did it the other way X'D (Didn't see your post)
Integrating it with my thieving function would confuse me (nub scripter =P)

It seems to be working now. I tested it on f2p and far away too, which before resulted in instant errors. So fingers crossed it'll stay away now lol!


Fixed:

program MasterFiever;

{$i SRL/SRL/Misc/SMART.scar}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}

var
x, y, stop, startexp: Integer;

const
SMARTWORLD = 72;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := ''; //Your username
Players[0].Pass := ''; //Your password
Players[0].Nick := 'own'; //3-4 letters from your username
Players[0].Active := true;
end;

procedure Antiban;
begin
case Random(400) of
3: HoverSkill('thieving', false);
end;
end;

{ getxpof (broken gametab 2)
function GetXPof(skill: string; t:integer): integer; // From narcle's autofighter
var
p: TPoint;
i, tx, ty, x, y, l, II, WaitT: Integer;
xp, Nums, text2, xpis, typeis : string;
begin
Result := -1;
case t of
1: typeis := 'urrent';
2: typeis := 'level';
3: typeis := 'ainder';
end;
if (not LoggedIn) or (not TabExists(2)) then Exit;
GameTab(2);
if (GetCurrentTab <> 2) then Exit;
p := SkillToCoords(Skill);
if (p.x < 1) then Exit;
MMouse(p.x, p.y+7, 12, 4);
repeat
WaitT := WaitT+1;
wait(100);
if WaitT >= 300 then exit;
until findcolor(x, y, 10551295, 554, 205, 743, 465);
wait(300 + Random(100))
if (not FindColor(x, y, 10551295, MIX1, MIY1, MIX2, MIY2)) then Exit;
if IsTextInAreaEx(x, y, x + 60, y + 60, tx, ty, typeis, 0, SmallChars, False, False, 0, 1, 0) then
xp := GetTextAtEx(tx, ty, 0, SmallChars, False, True, 0, 1, 0, 50, False, tr_AllChars);
for l := 1 to Length(xp) do
begin
if (xp[l] = 'O') then text2 := text2 + '0' else text2 := text2+ xp[l];
end;
Nums := '01234567890';
for I := 1 to Length(Text2) do
begin
for II := 1 to 10 do
begin
if (Copy(text2, I, 1) = Copy(Nums, II, 1)) then
xpis := xpis + Copy(Text2, I, 1);
end;
end;
try
result := strtoint(xpis);
Status(skill+' = ' +xpis);
except
result := 0;
status('Failed to get XP');
end;
end;
}

Procedure Login;
begin
LoginPlayer;
wait(1000+random(1000));
MakeCompass('N');
SetAngle(true);
GetAllLevels;
FindNormalRandoms;
Startexp := GetXP('thieving');
end;

Function Health : integer; //VeryBigKitty's ;p
begin
result := (R_GetMMLevels('hp'));
end;

procedure Bank;
var
food, inventory : TInvItemArray;
monkfish : TIntegerArray;
i : Integer;

begin
monkfish := ([7946, 7947]);
if ((InvFull()) and ((not(R_ItemIDExistsEx(monkfish, inventory)))) or (Health < 160) and ((not(R_ItemIDExistsEx(monkfish, inventory))))) then
begin
writeln('Inventory full. Banking.');
repeat
MakeCompass('n');
wait(500 + random(250));
RadialWalk(7368054, 60, 100, 40, -1, 0);
R_Flag;
until findsymbol(x,y,'bank');
begin
writeln('found bank');
Mouse(x,y,2,3,true);
R_Flag;
wait(1000+random(500));
end;
OpenBankFast('db');
if (BankScreen) then
begin
Wait(30+random(65));
DepositAll;
SearchBank('Monkfish');
Wait(1500 + random(1220));
Withdraw(0, 0, 10);
CloseBank;
food := GetInventoryItems;
if (food[i].Name = 'Monkfish') then
begin
writeln('we have food');
RadialWalk(7105650, 310, 280, 70, -1, 0);
R_Flag;
end else
Bank;
end;
end;
end;

procedure CheckHealth;
var
x, y, monkfishDTM : Integer;
inventory : TInvItemArray;
monkfish : TIntegerArray;
begin
monkfish := ([7946, 7947]);
monkfishDTM := DTMFromString('mrAAAAHic42BgYHBggmAvIA4CYm8gdgZiMyA2BeLnQD' +
'X3ofgOED8D4rdA/AKIHwJxoLsdkGTCg/EDRgIYBgAQ1Ao3');
if ((Health < 160) and (R_ItemIDExistsEx(monkfish, inventory))) then
begin
repeat
if FindDTM(monkfishDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
WriteLn('Health is dangerously low!');
MMouse(x, y, 1, 1);
GetMousePos(x, y);
if (pos('Eat', rs_GetUpText) > 0) then
begin
Mouse(x, y, 1, 1,true);
wait(1500+random(500));
end;
end;
until Health > 160
FreeDTM(monkfishDTM);
end else
FreeDTM(monkfishDTM);
Bank;
end;

{*******************************************************************************
function Stunned: Boolean;
By: NCDS
Description: Return's True if stunned by NPC.
*******************************************************************************}
function Stunned: Boolean;
var
P : TPoint;
Search : TBox;

begin
P.x := MSCx;
P.y := MSCy;
Search.x1 := P.x - 30;
Search.y1 := P.y - 30;
Search.x2 := P.x + 30;
Search.y2 := P.y + 30;
Result := FindColorTolerance(P.x, P.y, 5106941, Search.x1, Search.y1,
Search.x2, Search.y2, 5) and
IsChatBoxTextBetween('stunned', 0, 7, 8);
end;

procedure CheckInv;
var
monkfishDTM : Integer;
inventory : TInvItemArray;
monkfish : TIntegerArray;

begin
monkfish := ([7946, 7947]);
monkfishDTM := DTMFromString('mrAAAAHic42BgYHBggmAvIA4CYm8gdgZiMyA2BeLnQD' +
'X3ofgOED8D4rdA/AKIHwJxoLsdkGTCg/EDRgIYBgAQ1Ao3');
if InvFull() and R_ItemIDExistsEx(monkfish, inventory) then
begin
if FindDTM(monkfishDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
WriteLn('Inventory full. Eating food to clear space.');
MMouse(x, y, 1, 1);
wait(200+Random(121));
GetMousePos(x, y);
if (pos('Eat', rs_GetUpText) > 0) then
begin
Mouse(x, y, 1, 1,true);
wait(1500+random(500));
end;
end;
FreeDTM(monkfishDTM);
end else
FreeDTM(monkfishDTM);
Bank;
end;

function CheckNPC: TTile;
var
Farmer: TNPCArray;
i: Integer;
begin
if not LoggedIn then
Exit;
Farmer := GetNPCsBy('Master Farmer');
if high(Farmer) > -1 then
begin
for i:=0 to high(Farmer) do // Fixed!
begin
if (Farmer[i].Name = 'Master Farmer') then
begin
result := Farmer[i].Tile;
end;
end;
end;
end;

function ThieveFarmer: Boolean;
var
i : Integer;
Farmer : TNPCArray;
FarmerPos : TPoint;

begin
if InvFull() then CheckInv;
begin
CheckHealth;
CheckNPC;
if Stunned then
begin
writeln('Stunned...');
Wait(RandomRange(3000, 500));
end;
if((not(TileOnMS(CheckNPC, 0)))) then
begin
FarmerPos := TileToMM(CheckNPC);
Mouse(CheckNPC.x, CheckNPC.y, 4, 4, True);
if(R_FlagExists)then
R_Flag;
end;
if(TileOnMS(CheckNPC, 0)) then
begin
FarmerPos := TileToMS(CheckNPC, 0);
MMouse(FarmerPos.x, FarmerPos.y, 1, 1);
if(OptionExists('Pickpocket') and (R_IsUpText('Master Farmer'))) then
begin
Mouse(FarmerPos.x, FarmerPos.y, 1, 1, true);
wait(50+random(100));
R_Flag;
end;
end;
end;
result := true;
end;

begin
Smart_Server := SMARTWORLD;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;

SetupSRL;
DeclarePlayers;
Wait(500);
Login;
repeat
if not(loggedin) then login;
FindNormalRandoms;
repeat
ThieveFarmer;
FindNormalRandoms;
CheckHealth;
Antiban;
until(stop = 1);
stop := 0;
until(false);
end.

NPC detection seems to have slowed down a bit though, probably because I'm calling on an external function :P?

Luke-
7:24am zzzzZzzzzZZZzz time to sleep I think -_-