edggy
2009-01-24 00:49:20
This is my first script
I would like some constructive advice
I don't know why but every so often when it tries to bank SCAR crashes
Thank you,
Edggy
Proggys:
I would like some constructive advice
program EdggyGETreeChopper;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.include D-Include\DInclude.scar}
Const
Loads = 100;
TotalLogs = 2000;
Members = False;
Var
LoadsSoFar, Chopped, LogsInBank, Should, TimeA, TimeB, AvgCount: Integer;
Avg: Array of Extended;
Filled: Boolean;
type
TBS = record
ID, Stack : Integer;
Name : String;
end;
procedure SetupSmart;
begin
SMARTSetupEx(2, False, True, False);
Wait(5000);
SetTargetDC(SmartGetDC);
repeat
wait(100);
until(SmartGetColor(253, 233)<>1118604);
end;
Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name :='Username';
Players[0].Pass :='Password';
Players[0].Nick :='rna';
Players[0].Active:=True;
end;
Function Average(ToBe: Array of Extended): Extended;
Var
I: Integer;
Begin
For I:= 0 To Length(ToBe) - 1 Do
Begin
Result:= Result + ToBe[I];
End;
If Filled Then Result:= Result/Length(ToBe)
Else Result:= Result/(AvgCount-1);
End;
Procedure PrintProggy;
Var
I, Hours, Mins: Integer;
Secs: Extended;
Begin
ClearDebug;
MarkTime(TimeB);
for I:= 0 to (HowManyPlayers) - 1 do
Begin
Avg[AvgCount]:= Chopped / ((TimeB - TimeA)/60000);
Hours:= ((TimeB - TimeA)*3600000);
Mins:= ((TimeB - TimeA)*60000);//%60;
Secs:= ((TimeB - TimeA)*1000);//60;
Writeln('Player : '+ Players[I].Name);
//Writeln('Level : '+ IntToStr( GetMySkill(18,True) );
Writeln('Chopped : '+ IntToStr(Chopped)+' Trees');
Writeln('Banked : '+ IntToStr(LoadsSoFar)+' Loads');
Writeln('TotalLogs : '+ IntToStr(LogsInBank)+' Logs');
Writeln('TotalTime : '+ TimeRunning);//IntToStr(Hours)+' Hours, ' + IntToStr(Mins)+' Minutes, ' + IntToStr(Secs) + 'Seconds');
Writeln('LogsPerMinute : '+ FloatToStr(Avg[AvgCount]) + '');
AvgCount:= AvgCount + 1;
If AvgCount >= 100 Then
Begin
AvgCount:= 0;
Filled:= True;
End;
Writeln('Active : '+ BoolToStr(Players[I].Active));
End;
End;
Function GoToTPoint(Spot: TPoint): Boolean; Forward;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Function HandlePlant: Boolean;
By: Nicbaz
Description: Finds Plant
Status: Good
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Function HandlePlant: Boolean;
var
xx: TNPC;
P: Tpoint;
begin
if Not Members then
Exit;
if FindNPC('Strange Plant',XX) then
begin
Wait(200+Random(100));
P:= TileToMS(xx.Tile, Round(xx.Height / 2));
if Xx.Infight or GetMe.InFight then
begin
Writeln(' Poisoned');
Logout;
Exit;
end;
Mouse(p.X,p.Y,3,3,false);
Result:= ChooseOption('ick')
if result then
Writeln('Solved Plant');
end;
end;
procedure HandleFight;
var
Z :Tme;
Center: TPoint;
begin
Z:= GetMe;
if z.infight then
begin
SetRun(true);
Center:= Point(3164, 3490);
GoToTPoint(Center);
Writeln('In A Fight');
Logout;
Exit;
end;
end;
Function FindDeads: boolean;
var
Tilesz: Tpoint;
begin
Tilesz:= Point(3219, 3217);
Result:= False;
Result:= (DistanceFrom(Tilesz) < 5);
end;
Function FNR: Boolean;
begin
R_findrandoms;
FindNormalRandoms;
FindReflectionRandoms;
HandlePlant;
HandleFight;
if FindDeads then
begin
Nextplayer(false);
Exit;
end;
end;
function GetBA : array of TBS;
var
Main, ItemObj, TheBytes : Integer;
I, RL, X : Integer;
begin
if not R_BankScreen then
begin
SRL_Warn('GetBankArray', 'Bank Screen not open!', -2);
Exit;
end;
Main := GetInterface(762, 73);
for I := 0 to 495 do
begin
ItemObj := SmartGetFieldArrayObject(Main, InterfaceChildren, I);
X := SmartGetFieldInt(ItemObj, BankItemID);
if X > 0 then
begin
SetLength(Result, RL + 1);
Result[RL].ID := X;
Result[RL].Stack := SmartGetFieldInt(ItemObj, BankItemStackSize);
TheBytes := SmartGetFieldObject(ItemObj, BankItemName+'.'+StringBytes);
Result[RL].Name := StringFromBytes(TheBytes);
Delete(Result[RL].Name, 1, Pos('>', Result[RL].Name));
SmartFreeObject(TheBytes);
Inc(RL);
end else
begin
SmartFreeObject(ItemObj);
Break;
end;
SmartFreeObject(ItemObj);
end;
SmartFreeObject(Main);
end;
procedure Bank;
var
Bankers: array of TNPC;
Center, MyTPoint: TPoint;
Time1, Time2, I: Integer;
BankI: array of TBS;
begin
SetRun(True)
WriteLn('Banking');
MyTPoint:= GetMyPos;
Center:= Point(3164, 3490);
//WriteLn('I Am At: ' + IntToStr(MyTPoint.x) + ', ' + IntToStr(MyTPoint.y));
//WriteLn('Walking To Banker At: ' + IntToStr(Center.x) + ', ' + IntToStr(Center.y));
While Not TileOnMS(Center, 0) Do
Begin
GoToTPoint(Center);
End;
//While ((Center.x <> 3164) And (Center.y <> 3490)) Do
//Center:= Point(3164+(Random(3)-1)*4, 3490+(Random(3)-1)*4);
MarkTime(Time1);
MarkTime(Time2);
while Not R_BankScreen And (Time2 - Time1 < 10000) Do
begin
Bankers:= GetNPCsByName('Banker');
Bankers:= SortNPCs(Bankers);
Mouse(Bankers[0].MS.x, Bankers[0].MS.y, 0, 0, False);
//ClickNPC('Banker', 'Bank ', False)
Wait(150);
Mouse(Bankers[0].MS.x, Bankers[0].MS.y+35, 50, 0, True);
//ChooseOption('Bank ');
FFlag(0);
Wait(100);
//If Not R_BankScreen Then CloseBank;
MarkTime(Time2);
end;
If Not R_InvEmpty Then
Begin
Deposit(2,28,True);
End;
If R_InvEmpty Then
Begin
BankI:= GetBA;
for I := 0 to Length(BankI)-1 do
begin
If BankI[I].ID = 1511 Then
LogsInBank:= BankI[I].Stack;
End;
Should:= R_InvCount+1
//LogsInBank:= 1511;
LoadsSoFar:= LoadsSoFar + 1;
End;
CloseBank;
SetRun(False)
End;
Function GoToTPoint(Spot: TPoint): Boolean;
Var
Me: TMe;
begin
Me := GetMe;
// while (Me.Tile.x > Spot.x) AND (Me.Tile.y <> Spot.y) Do
// begin
Result:= False;
If TileOnMM(Spot) Then
Begin
WalkToTile(Spot, 2, 5);
//WriteLn('Found The Point');
Result:= True
end
Else If TileOnMM(Point(Spot.x, Spot.y-20)) Then
begin
WalkToTile(Point(me.Tile.x, me.Tile.y+10),1,5);
end
Else If TileOnMM(Point(Spot.x-20, Spot.y-20)) Then
begin
WalkToTile(Point(me.Tile.x+10, me.Tile.y+10),1,5);
end
Else If TileOnMM(Point(Spot.x+20, Spot.y-20)) Then
begin
WalkToTile(Point(me.Tile.x-10, me.Tile.y+10),1,5);
end
Else If TileOnMM(Point(Spot.x+20, Spot.y+20)) Then
begin
WalkToTile(Point(me.Tile.x-10, me.Tile.y-10),1,5);
end
Else If TileOnMM(Point(Spot.x-20, Spot.y+20)) Then
begin
WalkToTile(Point(me.Tile.x+10, me.Tile.y-10),1,5);
end
Else If TileOnMM(Point(Spot.x, Spot.y+20)) Then
begin
WalkToTile(Point(me.Tile.x, me.Tile.y-10),1,5);
end
Else If TileOnMM(Point(Spot.x+20, Spot.y)) Then
begin
WalkToTile(Point(me.Tile.x-10, me.Tile.y),1,5);
end
Else If TileOnMM(Point(Spot.x-20, Spot.y)) Then
begin
WalkToTile(Point(me.Tile.x+10, me.Tile.y),1,5);
end;
end;
function LoadTPoints: Array of TPoint;
begin
SetLength(Result, 28);
Result[0] := Point(3153, 3471);
Result[1] := Point(3147, 3472);
Result[2] := Point(3143, 3471);
Result[3] := Point(3143, 3477);
Result[4] := Point(3142, 3482);
Result[5] := Point(3142, 3495);
Result[6] := Point(3144, 3498);
Result[7] := Point(3140, 3500);
Result[8] := Point(3144, 3502);
Result[9] := Point(3141, 3505);
Result[10] := Point(3142, 3508);
Result[11] := Point(3141, 3511);
Result[12] := Point(3146, 3515);
Result[13] := Point(3148, 3512);
Result[14] := Point(3149, 3509);
Result[15] := Point(3154, 3515);
Result[16] := Point(3164, 3511);
Result[17] := Point(3176, 3514);
Result[18] := Point(3192, 3509);
Result[19] := Point(3192, 3505);
Result[20] := Point(3188, 3502);
Result[21] := Point(3183, 3503);
Result[22] := Point(3187, 3499);
Result[23] := Point(3186, 3493);
Result[24] := Point(3187, 3485);
Result[25] := Point(3184, 3470);
Result[26] := Point(3181, 3472);
Result[27] := Point(3175, 3471);
end;
Function FindNearestTPoint(Point: TPointArray; TreeID1, TreeID2: Integer): TPoint;
Var
I, IMin, Dist, DistMin: Integer;
Temp, Me: TPoint;
TempID: UID;
Begin
DistMin:= 100000;
for I := 0 to Length(Point)-1 do
Begin
Temp:= Point[I];
Me:= GetMyPos;
Dist:= (Temp.x - Me.x)*(Temp.x - Me.x) + (Temp.y - Me.y)*(Temp.y - Me.y);
TempID:= GetObjectAt(Temp.x, Temp.y)
If ((Dist < DistMin) And ((TempID.objType = TreeID1) Or (TempID.objType = TreeID2))) Then
Begin
DistMin:= Dist;
IMin:= I;
End;
End;
Result:= Point[IMin];
End;
Function TreeChopped(Tree: TPoint; TreeID1, TreeID2: Integer): Boolean;
Var
TreeUID: UID;
Begin
TreeUID:= GetObjectAt(Tree.x, Tree.y);
Result:= False;
If ((TreeUID.objType <> TreeID1) And (TreeUID.objType <> TreeID2)) Then Result:= True;
End;
Function OnScreen(Square:TPoint; Height :Integer): Boolean;
Begin
Result:= False
If TileOnMS(Point(Square.x-2, Square.y), Height) Then
Begin
If TileOnMS(Point(Square.x+2, Square.y), Height) Then
Begin
If TileOnMS(Point(Square.x, Square.y-2), Height) Then
Begin
If TileOnMS(Point(Square.x, Square.y+2), Height) Then Result:= True;
End;
End;
End;
End;
Procedure ChopTree;
Var
Tree, TreeMS, MyTPoint, Temp: TPoint;
Time1, Time2: Integer;
Continues: Boolean;
Begin
Continues:= True;
Tree:= FindNearestTPoint(LoadTPoints, 1276, 1278);
MyTPoint:= GetMyPos;
//WriteLn('I Am At: ' + IntToStr(MyTPoint.x) + ', ' + IntToStr(MyTPoint.y));
//WriteLn('Walking To Tree At: ' + IntToStr(Tree.x) + ', ' + IntToStr(Tree.y));
//515, 337
{Temp:= TileToMS(Tree,0);
If Temp.x > 500 Then Tree.x:= Tree.x + 600;
If Temp.y > 500 Then Tree.y:= Tree.y + 600; }
If Not OnScreen(Tree, 0) Then
Begin
MarkTime(Time1);
MarkTime(Time2);
While Not GoToTPoint(Tree) And (Time2 - Time1 > 30000) Do
Begin
Wait(100);
MarkTime(Time2);
End;
If TimeFromMark(Time1) > 30000 Then
Begin
WriteLn('Took Too Long To Get To Tree');
Continues:= False;
End;
End;
If Continues Then
Begin
//WriteLn('Finding Tree');
MarkTime(Time1);
MarkTime(Time2);
While (((GetAnimation <> 879) And Not TreeChopped(Tree, 1276, 1278)) And (Time2 - Time1 < 8000)) Do
Begin
TreeMS:= TileToMS(Tree, 0);
Mouse(TreeMS.x+30, TreeMS.y-10, 0, 5, True);
FNR;
Wait(1000+Random(500));
MarkTime(Time2);
End;
If Time2 - Time1 > 8000 Then
Begin
WriteLn('Took Too Long To Find The Tree');
End
Else
Begin
//WriteLn('Chopping Tree');
While Not TreeChopped(Tree, 1276, 1278) Do
Begin
FNR;
Wait(10);
End;
Wait(300+Random(1000));
If R_InvCount >= Should Then
Begin
Should:= R_InvCount + 1;
Chopped:= Chopped+1;
End;
End;
End;
//WriteLn('Tree Chopped');
End;
Procedure ChopTrees;
Var
Time1, Time2: Integer;
Begin
MarkTime(Time1);
MarkTime(Time2);
While Not InvFull Or (Time2 - Time1 > 6000*28) Do
Begin
FNR;
ChopTree;
PrintProggy;
MarkTime(Time1);
End;
End;
Begin
SetupSRL;
SetupSmart;
// SetupReflection;
RvUpdateReflection;
DeclarePlayers;//Calls the DeclarePlayers procedure
//LoginPlayer;// This will log your player in.
//FindMeTool;
//While Not GoToTPoint(Point(3165, 3484)) Do Wait(150);
LogsInBank:= 0;
Should:= R_InvCount+1;
LoadsSoFar:= 0;
Chopped:= 0;
SetLength(Avg, 100);
AvgCount:= 0;
Filled:= False;
ClearDebug;
MarkTime(TimeA);
While (LoadsSoFar < Loads) And (LogsInBank < TotalLogs) Do
Begin
LoginPlayer;
R_SetAngle(100);
FNR;
ChopTrees;
FNR;
Bank;
PrintProggy;
End;
If LoadsSoFar >= Loads Then WriteLn('Done ' + IntToStr(LoadsSoFar) + ' Loads');
If LogsInBank < TotalLogs Then WriteLn('There Are ' + IntToStr(LogsInBank) + ' Logs In Your Bank');
Logout; //This will log your player out!
end.
I don't know why but every so often when it tries to bank SCAR crashes
Thank you,
Edggy
Proggys:
Player : yggde
Chopped : 56 Trees
Banked : 1 Loads
TotalLogs : 28 Logs
TotalTime : 15 Minutes and 7 Seconds
LogsPerMinute : 3.7269354275161