Log in

View Full Version : Script uses alot of resources



fre
01-07-2012, 09:44 AM
I made a simple air runner.
But the script uses alot of CPU and memory compared with other scripts.
I can't figure out why that is?
After few minutes script reaches 300mb memor usage.
After about an hour it reaches 500mb of memory usage.

Can someone take a look at it and telle me if there is some major memory leaking or something?

Thx

~Fre




program AirRunner;
{$DEFINE SMART}
{$i srl\srl.scar}
{$i sps/sps.simba}

{
Have the rune essence in 3rd slot of your bank.
PlayerStarTime
Integers[0] : Ammount of runes a player craft in 1 run
Integers[01]: Ammount of runes a player craft in this script runtime.
Integers[1] : Time a player can run before it goes inactive (failsafe) (In minutes)
Integers[2] : Loads To Do
Integers[3] : Loads Done
Integers[4] : Total loads done
Integers[5] : Total time a player run
Integers[6] : Total ammount of runes made
InactiveP : Ammount of inactive players
Booleans[0] : Swich player after time or loads done? true for loads.
}
const

{---SMART Setup Constants---}
WORLD = 135;
MEMBERS = false;
SIGNED = true;
{---------------------------}
var
Path, Path1,Path2,Path3: TPointArray;
ACols: TIntegerArray;
StartTime,InactiveP:Integer;

Procedure DeclarePlayers;
var
i: integer;
begin


end;

Procedure Proggy;
var
I: Integer;
begin

ClearDebug;
IncEx(Players[CurrentPlayer].Integers[5], TimeFromMark(StartTime));
IncEx(Players[CurrentPlayer].Integers[4], Players[CurrentPlayer].Integers[3]);
IncEx(Players[CurrentPlayer].Integers[6], Players[CurrentPlayer].Integers[0]);

Writeln('|**************************************** *********************************************|');
Writeln(Padr('| SRL Junior Competion script, By Fre | Currently Running: ' + Players[CurrentPlayer].Name, 74) +
'|');
Writeln('|**************************************** *********************************************|');
Writeln('| Nick | Total Loads | Loads This Round| Total Time Ran | Runes made | ');
Writeln('|********* ************* ***************** **************** ************|');
for I := 0 to HowManyPlayers - 1 do
Writeln('|' + Padr(Players[I].Nick, 9)
+ '|' + Padr(inttostr(Players[i].Integers[4]), 13)
+ '|' + Padr(inttostr(Players[i].Integers[3]), 17)
+ '|' + Padr(MsToTime((Players[i].Integers[5]),Time_bare), 15)
+ '|' + Padr(inttostr(Players[i].Integers[6]), 11)
+ '|' );
Writeln('This script has been running for ' + TimeRunning + '.')
Writeln('There are ' + (inttostr(InactiveP)) + ' players inactive.')
Writeln('|**************************************** ********************************************|');
Writeln('|Wow that is amazing, Fre is the GodKing! |');
Writeln('|**************************************** ********************************************|');
end;

Function CheckRunTime:String;
var
Time:Integer;
begin
writeln('checking time');
Result:= MsToTime(TimeFromMark(StartTime), Time_Bare);
If (TimeFromMark(StartTime) > ((Players[CurrentPlayer].Integers[1])*60*1000)) then
begin
NextPlayer(True);
Inc(InactiveP);
end;
end;



Function IsMoving_F: Boolean;
begin
Result := PixelShift(IntToBox(MMCX-30, MMCY-30, MMCX+30, MMCY+30), 200) > 200;
end;







Function InBank: Boolean;
begin
Result := CountDots('npc') > 12;
If Result then
writeln('we are in the bank');
end;




Function Bank: Boolean;
begin
Players[CurrentPlayer].Integers[0] := GetAmount(578,227);
Players[CurrentPlayer].Integers[01]:= Players[CurrentPlayer].Integers[01] + Players[CurrentPlayer].Integers[0];
writeln(' made ' + tostr(Players[CurrentPlayer].Integers[0]) + ' air runes in this round.');
writeln(' made ' + tostr(Players[CurrentPlayer].Integers[0]) + ' air runes with this script.');
While Not BankScreen do
While Not ExistsBankTab(2) do
begin
CheckRunTime;
OpenBankNpc;
end;
DepositAll;
Result:=WithdrawEx(1,0,0,['ess','une']);
Wait(RandomRange(400,800));
Case random(5) of
0:CloseBank;
end;
end;

Function Mysteriousruinzone: Boolean; //Checks for the multicombat sign.
var
x, y: integer;
begin
if FindColorTolerance(x, y, 10855845, 467, 280, 504, 303, 5) then
Result := FindColorTolerance(x, y, 4836862, 467, 280, 504, 303, 5);
end;





Function InAltar: Boolean;
var
x, y: Integer;
begin
writeln('checking if in altar');
Result:= false;
if ((countdots('npc') < 3) and (not Mysteriousruinzone)) then
Result:= true;
If Result then
writeln('we are in altar');
end;



Procedure HumanMMouse(eX, eY, ranX, ranY: Integer);
var
randSpeed: extended;
X,Y,X2,Y2,A,Dist,MP: integer;
begin
A := MouseSpeed;
GetMousePos(X, Y);
Dist := Distance(X, Y, eX, eY);
MP := Round(Dist/150);
if MP < 0 then
MP := 1;

randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
X2 := RandomRange(eX-(A*MP), eX+(A*MP));
Y2 := RandomRange(eY-(A*MP), eY+(A*MP));
WindMouse(X, Y, X2, Y2, 11, 8, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed);
GetMousePos(X, Y);
MMouse(eX, eY, ranX, ranY);
MouseSpeed := A;
end;

Function FindObjSimple_F(Colors: TIntegerArray; TheUpText: TStringArray; midx, midy: integer): Boolean;
Var
T,i,X,Y: Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
Begin
MarkTime(T);
Repeat
SetArrayLength(ATPA, Length(Colors));
for i := 0 to High(Colors) do
FindColorsSpiralTolerance(midx, midy, ATPA[i], Colors[i], MSX1, MSY1, MSX2, MSY2, 15);
TPA := MergeATPA(ATPA);
ATPA := TPAtoATPAEx(TPA, 15, 15);
SortATPAFrom(ATPA, Point(MSCX, MSCY));
if (Length(ATPA) = 0) then
Exit;

MiddleTPAEx(ATPA[0], x, y);

if (TimeFromMark(T) > 5000) then
Exit;

HumanMMouse(x, y, 10, 10);
Wait(randomrange(75,125));
If(IsUpTextMultiCustom(TheUpText)) then
begin
ClickMouse2(True);
if DidRedClick then
begin
Result := True;
Break;
end;
end;
Until(Result)
end;

Function EnterAltar: Boolean;
var
DTM3, x, y, c: Integer;
begin
CheckRunTime;
writeln('Entering altar');
Result:= FindObjSimple_F([16629134,12948335,14460028], ['nter','Myst','erious','ruins'], MSCX, MSCY);
Wait(2000+random(1000));
end;


function LeaveAltar: Boolean;
var
x, y: Integer;
begin
writeln('leaving altar');

if FindObjEx(x,y,['nter','ortal','ter','rta'],[6462877,5804947],10,50,MSX1,MSY1,MSX2,MSY2) then
begin
GetMousePos(x,y);
Mouse(x,y,0,0,true);
end else
begin
Mouse(131,248,10,10,true);
end;
Wait(5000+random(1000));
end;

Function CraftRunes:Boolean;
var
x,y:Integer;
Begin
CheckRunTime;
Repeat
if not InAltar then
Exit;
MMouse(307,4,100,80);
wait(200+random(100));
until(IsUpTextMultiCustom(['raft','rune','ltar']));
GetMousePos(x,y);
Mouse(x,y,0,0,true);
Wait(4000+random(1000));
end;



Function ToAltar:Boolean;
begin
writeln('Going to altar');
Result:=SPS_WalkPath(Path);
While ISMoving_F do
Wait(100+random(100));
end;






Procedure ToBank;
var
RoadColor, x, y, RR, Xm, Ym: Integer;
t: String;

begin
CheckRunTime;
writeln('walking to musician');

SPS_WalkPath(Path2);
While ISMoving_F do
Wait(100+random(100));
if FindObjEx(x,y,['alk','usic'],[2771773,7891509,4619379],10,50,MSX1,MSY1,MSX2,MSY2) then
begin
Mouse(x,y,0,0,false);
ChooseOption('isten');
wait(15000+random(5000));
end;


SPS_WalkPath(Path3);
While ISMoving_F do
Wait(100+random(100));
end;



Procedure SetupScript;
begin
Smart_Members := MEMBERS;
Smart_Server := WORLD;
Smart_Signed := SIGNED;
SetupSRL;
DeclarePlayers;
SPS_Setup(RUNESCAPE_SURFACE, ['11_7', '10_7']);
SPS_Continue := true;
//Path to altar
Path := [Point(4573, 2904), Point(4573, 2918), Point(4566, 2933),
Point(4530, 2940), Point(4496, 2970), Point(4461, 2982), Point(4436, 2987),
Point(4419, 2995), Point(4397, 3003), Point(4375, 3016), Point(4348, 3030)];
//path to musician
Path2 := [Point(4365, 3028), Point(4383, 3016), Point(4401, 3009),
Point(4414, 2994), Point(4433, 2982), Point(4446, 2969)];
//path to bank
Path3 := [Point(4462, 2964), Point(4477, 2964), Point(4493, 2958),
Point(4504, 2948), Point(4515, 2940), Point(4528, 2936), Point(4548, 2936),
Point(4565, 2935), Point(4574, 2927), Point(4578, 2914), Point(4572, 2898)];
end;

Procedure SetupPlayer;
begin
if not LoggedIn then
LoginPlayer;
SetAngle(True);
MarkTime(StartTime);



end;

Procedure MainLoop;
var
Check: Integer;
begin
while InvFull do
begin
writeln('inv is full we go to altar or craft some runes');
if ToAltar then
EnterAltar;
if InAltar then
CraftRunes;
end;
if (InvCount = 1) then
while InAltar do
LeaveAltar;
if (not InBank) then
ToBank;
if not Bank then
begin
NextPlayer(True);
writeln('we are out of rune essence');
end else
Inc(Players[CurrentPlayer].Integers[3]);
end;



Function SwichPlayers: Boolean;
begin
if Players[CurrentPlayer].Booleans[0] then
begin
Result := Players[CurrentPlayer].Integers[3] > Players[CurrentPlayer].Integers[2]
end else
writeln('still need to make timer');

end;





begin
SetupScript;
repeat
SetupPlayer;
Repeat
MainLoop;
Proggy;
If SwichPlayers then
Break;
until(false)
CloseBank;
NextPlayer(true);
until(false)
end.

Brandon
01-07-2012, 10:17 AM
I have not found anything that can cause a memory leak in your script.. if you don't mind uploading your other one so I can compare them and check what functions you used then by all means go ahead but for as of now, I have not found a single leak :S


I would note that CountDots('NPC') is fairly new since a jagex update but I've been using it and testing it and it has no problems.. Also noticed two of flight's functions but those are fine as they don't lag his nature script or livid farmer at all.
Last suspect would be SPS as it's outdated pretty badly but I've still be getting it to work on this Sorceress garden script without noticeable lag..

Thus if I may say, your problem may actually be a Java problem as Java 7 Cannot even Compile Smart without bitching at me about classes being private when their public.. Nor does it allow smart to run and it creates a massive lag that causes smart to crash and complain.. ControlPanel -> Uninstall Programs -> Java 7.. if it shows anything more than Java 6u29/6u30 aka Java 7u2 or whatever.. remove it..

Re-install java.. Maybe someone else can check n see if there is a leak or something I missed?

fre
01-07-2012, 11:32 AM
Thx for the reply.
I use java 2 TM 29.

FinObj does work for me. I use failsafe in case it don't work.
But like i said. It is a simple script. So i wan't to keep functions and procedure simple too.

I could run 6 smarts at once.
Now i am having trouble running 3 at once :s

I have the feeling that it is sps who is lagging the script after a while.
is this possible?