SRL Archive - Senior Scripts and Snippets

Oak larder maker


Boreas

2008-12-15 00:13:40

My attempt at getting back on the horse. Far from done, watch it! Anyone want to help?


ver 0.0000000000000002 :p
Start in build mode, with money, with a larder already in place, with at least 16 free spaces. Ask you butler to get you 16 oak planks, then go stand to the left of the larder before he gets back. When he gets back, accept the goods, and then click on him before walks away. Then run the script.
program New;
{.include srl\srl.scar}
function FindNPCChatText2(txt: string; Action: fnct_ActionOptions): Boolean;
var
tx, ty, S: Integer;
begin
Result := False;
if txt = '' then
begin
srl_Warn('FindNPCChatText2', 'txt is empty', warn_AllVersions);
Exit;
end;
S := CreateBitmapMaskFromText(txt, UpChars);
if FindBitmapMaskTolerance(S, tx, ty, 9, 348, 523, 471, 50, 10) then
begin
Result := True;
case Action of
Move: MMouse(tx, ty + 2, Random(Length(txt) * 5), 4);
ClickLeft: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, True);
ClickRight: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, False);
end;
end;
FreeBitmap(S);
end;

var t:integer;

function ClickButler:boolean;
begin
result:=true;
end;

function TalkToButler:boolean;
var t:integer;
begin
t:=getsystemtime;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
end;
if FindNPCChatText('Your goods, sir',Nothing) then
begin
ClickToContinue;
ClickButler;
end;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
end;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('sir',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Go to the bank', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Bring something from', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('fetch something',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Certainly',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Oak planks', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText2('Enter amount',Nothing); typesend('16');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Very good, sir',Nothing); ClickToContinue;
result:=true;
end;

function ClickWhiteLarder:boolean;
begin
MouseBox(313,120,341,145, 2);
result:=true;
end;

function ClickBrownLarder:boolean;
begin
MouseBox(313,120,341,145, 2);
result:=true;
end;


function BuildIt:boolean;
var t,x,y:integer;
begin
t:=getsystemtime;
ClickBrownLarder;
ChooseOption('Remove');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Yes', ClickLeft);
wait(300+random(100));
ClickWhiteLarder;
wait(100+random(50));
ChooseOption('uild');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
MouseBox(40,180,60,200,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until not FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
result:=true;
end;

begin
setupsrl;
TalkToButler;
BuildIt;
BuildIt;
repeat wait(50); until FindNPCChatText('your goods sir',Nothing); ClickToContinue;
end.
To do: ClickButler, ClickLarder, failsafes including for when he gets back too soon, arrange for start from anywhere, loop, declareplayers login etc.




Yoho: this should work for any house as long as you turn compass so that larder is in bottom right corner of the kitchen. For tab maker however, you need to have it like this:
………………………..- Dining room (bell)
Stairs room (glory)- Study(lectern)
and those 3 have to not be connected to any other rooms with internal doors.

Wizzup?

2008-12-15 06:44:13

Standards! :p

n3ss3s

2008-12-15 07:23:16

The irony is ironic, YOU were the one complaining about my standards for the first time <3

function BuildIt:boolean;
var t,x,y:integer;
begin
t:=getsystemtime;
ClickBrownLarder;
ChooseOption('Remove');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Yes', ClickLeft);
wait(300+random(100));
ClickWhiteLarder;
wait(100+random(50));
ChooseOption('uild');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until
FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
MouseBox(40,180,60,200,1);
result:=true;
end;



and then the funky standards of my first application -

procedure randoms;
begin
findtalk;
findpick;
if(findfight) then
begin
runawaydirection(runawaydir);
wait(8500+random(400));
runback;
end;
if(loggedin = False) then
loginplayer;
end;

Boreas

2008-12-15 11:18:42

K I fixed some of the spacing. But I'm not changing the repeats, cuz each line is one thing to me. I would make a giant function for them, to keep to 1 line, but it would just be a bunch of cases and ifs.

Edit:
v0.0.3 First version that you can actually let run and watch for bugs. I was worried about the butler getting back too soon, but that probably won't happen, as BuildIt is pretty fast. TalkToButler is the slow one.
program New;
{.include srl\srl.scar}
function FindNPCChatText2(txt: string; Action: fnct_ActionOptions): Boolean;
var
tx, ty, S: Integer;
begin
Result := False;
if txt = '' then
begin
srl_Warn('FindNPCChatText2', 'txt is empty', warn_AllVersions);
Exit;
end;
S := CreateBitmapMaskFromText(txt, UpChars);
if FindBitmapMaskTolerance(S, tx, ty, 9, 348, 523, 471, 50, 10) then
begin
Result := True;
case Action of
Move: MMouse(tx, ty + 2, Random(Length(txt) * 5), 4);
ClickLeft: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, True);
ClickRight: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, False);
end;
end;
FreeBitmap(S);
end;

//ACA
function FindButler(var fx, fy: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2: Integer;
P: TPoint;
H, S, L: Extended;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);

if not(FindColorsTolerance(arP, 725851, MSX1, MSY1, MSX2, MSY2, 41)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToHSL(arC[i], H, S, L);

if (H >= 1.43) and (H <= 1.76) and (S >= 78.16) and (S <= 79.82) and (L >= 11.35) and (L <= 28.45) then
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.54) and (X <= 9.71) and (Y >= 0.94) and (Y <= 5.59) and (Z >= 0.26) and (Z <= 1.04) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;
end;

SortTPAFrom(arAP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 10) then Continue;
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(100 + Random(100));
if (IsUpText('utler')) then
begin;
Result := True;
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);

if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;

GetMousePos(fx, fy);
end;

function ClickButler:boolean;
var x,y:integer;
begin
if FindButler(x,y) then
begin
Mouse(x,y,2,2,true);
result:=true;
end;
end;

function TalkToButler:boolean;
var t:integer;
begin
t:=getsystemtime;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
end;
if FindNPCChatText('Your goods, sir',Nothing) then
begin
ClickButler;
end;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
end;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('sir',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Go to the bank', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Bring something from', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('fetch something',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Certainly',Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Oak planks', ClickLeft);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText2('Enter amount',Nothing); typesend('16');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Very good, sir',Nothing); ClickToContinue;
result:=true;
end;

function ClickWhiteLarder:boolean;
begin
MouseBox(313,120,341,145, 2);
result:=true;
end;

function ClickBrownLarder:boolean;
begin
MouseBox(313,120,341,145, 2);
result:=true;
end;


function BuildIt:boolean;
var t,x,y:integer;
begin
t:=getsystemtime;
repeat
wait(300+random(100));
ClickBrownLarder;
until ChooseOption('Remove');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Yes', ClickLeft);
wait(300+random(100));
ClickWhiteLarder;
wait(100+random(50));
ChooseOption('uild');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until
FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
MouseBox(40,180,60,200,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until
not FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
result:=true;
end;

begin
setupsrl;
repeat
ClickButler;
TalkToButler;
BuildIt;
BuildIt;
repeat wait(50); until (FindNPCChatText('our goods',Nothing) or FindNPCChatText('you do not pay',Nothing));
until isfkeydown(12);
end.

v0.0.5
Made TalkToButler faster. Put pics from .7z attached into SCAR folder.
program New;
{.include srl\srl.scar}
//butler stuck right of wall, timer click butler

function FindNPCChatText2(txt: string; Action: fnct_ActionOptions): Boolean;
var
tx, ty, S: Integer;
begin
Result := False;
if txt = '' then
begin
srl_Warn('FindNPCChatText2', 'txt is empty', warn_AllVersions);
Exit;
end;
S := CreateBitmapMaskFromText(txt, UpChars);
if FindBitmapMaskTolerance(S, tx, ty, 9, 348, 523, 471, 50, 10) then
begin
Result := True;
case Action of
Move: MMouse(tx, ty + 2, Random(Length(txt) * 5), 4);
ClickLeft: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, True);
ClickRight: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, False);
end;
end;
FreeBitmap(S);
end;

//ACA
function FindButler(var fx, fy: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2: Integer;
P: TPoint;
H, S, L: Extended;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);

if not(FindColorsTolerance(arP, 791643, MSX1, MSY1, MSX2, MSY2, 44)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToHSL(arC[i], H, S, L);

if (H >= 1.50) and (H <= 1.84) and (S >= 76.60) and (S <= 79.82) and (L >= 10.76) and (L <= 29.43) then
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.39) and (X <= 10.23) and (Y >= 0.86) and (Y <= 5.93) and (Z >= 0.25) and (Z <= 1.15) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;
end;

SortTPAFrom(arAP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 10) then Continue;
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(100 + Random(100));
if (IsUpText('utler')) then
begin;
Result := True;
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);

if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;

GetMousePos(fx, fy);
end;

function ClickButler:boolean;
var x,y:integer;
begin
if FindButler(x,y) then
begin
Mouse(x,y,2,2,true);
result:=true;
end;
end;


var
TextTPAs: T2DPointArray;

function LoadTextTPAs(HowMany:integer):T2DPointArray;
var OldHandle,i,tmpbmp:integer;
begin
OldHandle:= GetClientWindowHandle;
SetArrayLength(result,HowMany);
for i:=0 to HowMany-1 do
begin
tmpbmp:= LoadBitmap(AppPath+'\Bmptext'+inttostr(i)+'.bmp');
SetTargetBitmap(tmpbmp);
FindColorsTolerance(result[i],0,mcx1,mcy1,mcx2,mcy2,0);
end;
SetClientWindowHandle(OldHandle);
FreeBitmap(tmpbmp);
end;

function FindChatTextTPA(TheTPA: TPointArray; Action: fnct_ActionOptions): Boolean;
var TPA,tmpTPA,tmpTPA1,tmpTPA2: TPointArray;
tmpAL,i:integer;
tmpbox: TBox;
begin
TPA:=TheTPA;
FindColorsTolerance(tmpTPA1,0,mcx1,mcy1,mcx2,mcy2,0);
FindColorsTolerance(tmpTPA2,16777215,mcx1,mcy1,mcx2,mcy2,0);
if getarraylength(tmpTPA2)>5 then
MouseBox(MSX1,msy1,msx2,msy2,3);
tmpTPA:={CombineTPA(}tmpTPA1{,tmpTPA2)};
tmpAL:=getarraylength(tmpTPA);
{SortTPAFrom(tmpTPA, Point(0,0));}
if tmpAL <> getarraylength(TPA) then exit;
for i:=0 to tmpAL-1 do
begin
if TPA[i].x<>tmpTPA[i].x then exit;
if TPA[i].y<>tmpTPA[i].y then exit;
end;
result:=true;
case Action of
Move: MMouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0);
ClickLeft: Mouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0, True);
ClickRight: Mouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0, False);
end;
end;

function TalkToButler:boolean;
var t:integer;
begin
t:=getsystemtime;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
wait(100+random(50));
end;
if FindChatTextTPA(TextTPAs[0],Nothing) then
begin
ClickButler;
end;
if FindNPCChatText('you do not pay me',Nothing) then
begin
ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Pay servant', ClickLeft);
ClickButler;
end;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[8],Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[2], Nothing); MouseBox(210,403,302,410,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[3], Nothing); MouseBox(165,432,363,438,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[4],Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[5],Nothing); ClickToContinue;
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[9], Nothing); MouseBox(229,403,291,410,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[6],Nothing); typesend('16');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindChatTextTPA(TextTPAs[7],Nothing); ClickToContinue;
result:=true;
end;

function ClickWhiteLarder:boolean;
begin
MouseBox(228,80,262,114, 2);
result:=true;
end;

function ClickBrownLarder:boolean;
begin
MouseBox(228,80,262,114, 2);
result:=true;
end;


function BuildIt:boolean;
var t,x,y:integer;
begin
t:=getsystemtime;
repeat
wait(300+random(100));
ClickBrownLarder;
until ChooseOption('Remove');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Yes', ClickLeft);
wait(300+random(100));
ClickWhiteLarder;
wait(100+random(50));
ChooseOption('uild');
repeat wait(50); if (getsystemtime-t)>60000 then exit; until
FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
MouseBox(40,180,60,200,1);
repeat wait(50); if (getsystemtime-t)>60000 then exit; until
not FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
result:=true;
end;
var t:integer;
begin
setupsrl;
t:=getsystemtime;
TextTPAs:=LoadTextTPAs(10);
writeln(inttostr(getsystemtime-t));
repeat
ClickButler;
TalkToButler;
BuildIt;
BuildIt;
repeat wait(50); until (FindNPCChatText('our goods',Nothing) or FindNPCChatText('you do not pay',Nothing));
until isfkeydown(12);
end.

The Claw

2009-01-08 07:41:48

Updated some stuff, fixed the paying Boreas. Still needs support for the demon butler, for when the butler gets stuck and when he gets back too early, so it still needs to be watched. Otherwise, its pretty stable :p

—–Oak Larder Maker by Boreas and The Claw—–
Time Running: 20 Minutes and 40 Seconds
Oak Larders Made: 72
Experience gained: 34560
So currently making 209 larders and gaining 100271 xp per hour.


program New;
{.include srl\srl.scar}
//butler stuck right of wall, timer click butler

const
ButlerType = 'butler';

var
Removed, Built: Integer;
UpTo: String;
LastChance: Boolean;

function FindNPCChatText2(txt: string; Action: fnct_ActionOptions): Boolean;
var
tx, ty, S: Integer;
begin
Result := False;
if txt = '' then
begin
srl_Warn('FindNPCChatText2', 'txt is empty', warn_AllVersions);
Exit;
end;
S := CreateBitmapMaskFromText(txt, UpChars);
if FindBitmapMaskTolerance(S, tx, ty, 9, 348, 523, 471, 50, 10) then
begin
Result := True;
case Action of
Move: MMouse(tx, ty + 2, Random(Length(txt) * 5), 4);
ClickLeft: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, True);
ClickRight: Mouse(tx, ty + 2, Random(Length(txt) * 5), 4, False);
end;
end;
FreeBitmap(S);
end;

//ACA
function FindButler(var fx, fy: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2: Integer;
P: TPoint;
H, S, L: Extended;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);

// FindColorsSpiralTolerance(arP.x, Ar; var Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer);

if not(FindColorsTolerance(arP, 791643, MSX1, MSY1, MSX2, MSY2, 44)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToHSL(arC[i], H, S, L);

if (H >= 1.50) and (H <= 1.84) and (S >= 76.60) and (S <= 79.82) and (L >= 10.76) and (L <= 29.43) then
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.39) and (X <= 10.23) and (Y >= 0.86) and (Y <= 5.93) and (Z >= 0.25) and (Z <= 1.15) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;
end;

SortTPAFrom(arAP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 10) then Continue;
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(400 + Random(100));
if (IsUpText('utler')) then
begin;
Result := True;
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);

if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;

GetMousePos(fx, fy);
end;

function ClickButler:boolean;
var x,y:integer;
begin
if FindButler(x,y) then
begin
Mouse(x,y,2,2,true);
result:=true;
end;
end;


var
TextTPAs: T2DPointArray;

function LoadTextTPAs(HowMany:integer):T2DPointArray;
var OldHandle,i,tmpbmp:integer;
begin
OldHandle:= GetClientWindowHandle;
SetArrayLength(result,HowMany);
for i:=0 to HowMany-1 do
begin
tmpbmp:= LoadBitmap(AppPath+'\Bmptext'+inttostr(i)+'.bmp');
SetTargetBitmap(tmpbmp);
FindColorsTolerance(result[i],0,mcx1,mcy1,mcx2,mcy2,0);
end;
SetClientWindowHandle(OldHandle);
FreeBitmap(tmpbmp);
end;

function FindChatTextTPA(TheTPA: TPointArray; Action: fnct_ActionOptions): Boolean;
var TPA,tmpTPA,tmpTPA1,tmpTPA2: TPointArray;
tmpAL,i:integer;
tmpbox: TBox;
begin
TPA:=TheTPA;
FindColorsTolerance(tmpTPA1,0,mcx1,mcy1,mcx2,mcy2,0);
FindColorsTolerance(tmpTPA2,16777215,mcx1,mcy1,mcx2,mcy2,0);
if getarraylength(tmpTPA2)>5 then
MouseBox(MSX1,msy1,msx2,msy2,3);
tmpTPA:={CombineTPA(}tmpTPA1{,tmpTPA2)};
tmpAL:=getarraylength(tmpTPA);
{SortTPAFrom(tmpTPA, Point(0,0));}
if tmpAL <> getarraylength(TPA) then exit;
for i:=0 to tmpAL-1 do
begin
if TPA[i].x<>tmpTPA[i].x then exit;
if TPA[i].y<>tmpTPA[i].y then exit;
end;
result:=true;
case Action of
Move: begin end;//AAAMMouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0);
ClickLeft: Mouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0, True);
ClickRight: Mouse(tmpbox.x1+1+random((tmpbox.x2-tmpbox.x1)-2),tmpbox.y1+1+random((tmpbox.y2-tmpbox.y1)-2),0,0, False);
end;
end;

function TalkToButler:boolean;
var t:integer;
begin
case ButlerType of
'butler':
begin
//support for paying him, and when he holds items for you
if FindChatTextTPA(TextTPAs[0],Nothing) then
begin
ClickButler;
end;
t:=getsystemtime;
repeat
if FindNPCChatText('you do not pay me',Nothing) then
begin
Writeln('you do not pay');
ClickToContinue;
repeat wait(200); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('ay servant', ClickLeft);
//Wait(500 + Random(500));
ClickButler;
ClickButler;
end;
while ClickContinue(True, True) do
wait(50);
if FindChatTextTPA(TextTPAs[2], Nothing) then
MouseBox(210,403,302,410,1);
if FindChatTextTPA(TextTPAs[3], Nothing) then
MouseBox(165,432,363,438,1);
if FindChatTextTPA(TextTPAs[8], Nothing) then
MouseBox(229,403,291,410,1);
if FindChatTextTPA(TextTPAs[9], Nothing) then
MouseBox(229,403,291,410,1);
if FindChatTextTPA(TextTPAs[6], Nothing) then
begin
TypeSend('16');
repeat Wait(100) until GetColor(361, 458) = 16711680;
ClickToContinue;
Result := True;
Exit;
end;
until (getsystemtime-t)>60000;
end;
'demon'://and other butler types
begin
end;
end;
end;

function ClickWhiteLarder:boolean;
begin
MouseBox(330, 81, 404, 167, 2);
result:=true;
end;

function ClickBrownLarder:boolean;
begin
MouseBox(330, 81, 404, 167, 2);
result:=true;
end;

procedure Proggy;
var LPh, XPPh: Integer;
begin
LPh := Round((Built * 3600.0) / (GetTimeRunning / 1000.0));
XPPh := Round(((Built * 8 * 60) * 3600.0) / (GetTimeRunning / 1000.0));
Writeln('-----Oak Larder Maker by Boreas and The Claw-----')
Writeln(' Time Running: ' + TimeRunning);
Writeln(' Oak Larders Made: ' + IntToStr(Built));
Writeln(' Experience gained: ' + IntToStr(Built * 8 * 60));
Writeln(' So currently making ' + IntToStr(LPh) + ' larders and gaining ' +
IntToStr(XPPh) + ' xp per hour.');
end;

Function Remove: Boolean;
var brownclicks:integer;
begin
BrownClicks := 0;
repeat
wait(300+random(100));
ClickBrownLarder;
Inc(BrownClicks);
if BrownClicks > 5 then Exit;
until ChooseOption('Remove');
Result := True;
end;

Function Build: Boolean;
var WhiteClicks: Integer;
begin
WhiteClicks := 0;
repeat
wait(300+random(100));
ClickWhiteLarder;
Inc(WhiteClicks);
if WhiteClicks > 5 then Exit;
until ChooseOption('Build');
Result := True;
end;

function BuildIt:boolean;
var t,x,y, brownclicks, currentdone:integer;
begin
t:=getsystemtime;
CurrentDone := 0;
repeat
Writeln(UpTo);
Inc(CurrentDone);
case UpTo of
'removing': begin
if Remove then
begin
repeat wait(200); if (getsystemtime-t)>60000 then exit; until FindNPCChatText('Yes', ClickLeft);
wait(600+random(300));
Inc(Removed);
UpTo := 'building';
Result := True;
LastChance := False;
end else
begin
Writeln('Failed to remove');
If LastChance then
begin
Writeln('Last chance failed, dunno, logging');
//Logout;
TerminateScript;
end;
UpTo := 'building'
Writeln('Switching to build but last chance');
LastChance := True;
end;
end;
'building': begin
if Build then
begin
repeat wait(200); if (getsystemtime-t)>60000 then exit; until
FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
MouseBox(40,180,60,200,1);
repeat wait(200); if (getsystemtime-t)>60000 then exit; until
not FindTextTpaEx(2070783,0,66,168,140,210,x,y,'Oak',statchars,Nothing);
result:=true;
LastChance := False;
Inc(Built);
UpTo := 'removing';
end else
begin
Writeln('Failed to build');
If LastChance then
begin
Writeln('Last chance failed, dunno, logging');
//Logout;
TerminateScript;
end;
UpTo := 'removing';
Writeln('Switching to removing but last chance');
LastChance := True;
end;
end;

end;
until CurrentDone >= 4;
end;

var t, tries:integer;
begin
setupsrl;
UpTo := 'removing';
t:=getsystemtime;
TextTPAs:=LoadTextTPAs(10);
writeln(inttostr(getsystemtime-t));
ClickButler;
TalkToButler;
repeat
Tries := 0;
BuildIt;
//BuildIt;
Proggy;
repeat
wait(750 + Random(500));
if not ClickButler then Inc(Tries);
If Tries >= 20 then
begin
Writeln('Failed at finding butler');
//LogOut;
TerminateScript;
end;
until (FindNPCChatText('our goods',Nothing) or FindNPCChatText('you do not pay',Nothing) or FindNPCChatText('es, sir?',Nothing) or FindNPCChatText('will hold these',Nothing));
TalkToButler;
until isfkeydown(12);
end.