You could have checks for stuff in each procedure that clicks something, like below, but you end up with a lot of ifs.
function nearbank:boolean;
begin
if FindSymbol{In}(x,y,'bank'{,620,67,669,115}) then
begin
result:=true;
exit;
end;
if not (findsymbol(x,y,'quest') or(findsymbol(x,y,'fish'))) then
exit;
result:=true;
end;
Function GetCompassAngle: Extended; //Wizzup?
Var
Compass: TPointArray;
tmpPoint: TPoint;
Begin
FindColorsTolerance(Compass, 1911089, 540, 2, 590, 40, 0);
If Length(Compass) < 1 Then
Exit;
tmpPoint := MiddleTPA(Compass);
Result := Degrees(ArcTan2(tmpPoint.Y - 20, tmpPoint.X - 561)) + 90;
If (Result < 0) Then
Result := 90 - (Result * -1) + 270
End;
Function FindFourBankers(Direction:string):Tpoint;
var myy,myx,dist,DTMBankers:integer;
angle:extended;
begin
DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A98A16AFEFC6102D38C503E6323116ABA885053' +
'4D580D005F4D15F0'); //3 akbank4
{
DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A98A06AFEFC81B018A17CC64622D47411A1A69A' +
'B01A005E1515EC'); //2}
{ DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A18A16AFEFC6142E1333612A1A68B0835D584D5' +
'00005CDD15E8'); }
if not FindDTMRotated(DTMBankers,myx,myy,mmx1,mmy1,mmx2,mmy2,0,180,2.0,angle) then
begin
freedtm(DTMBankers);
exit;
end;
freedtm(DTMBankers);
angle:=GetCompassAngle;
case lowercase(Direction[1]) of
'e': angle:=angle-270.0;
'w': angle:=angle-90.0;
's': angle:=angle-180.0;
end;
dist:=5+random(7);
result.x:=myx+round((dist)*sin(radians(angle)));
result.y:=myy-round((dist)*cos(radians(angle)));
end;
function TanScreen: Boolean;
var TanText, Tx, Ty:Integer;
begin
TanText := BitmapFromString(29, 1, 'z78DA7373B3B430747303' +
'930660E04684888985B1ABB131A6384EF5962606C626101259169' +
'344568F290E0045F426A7');
Result := FindBitMapToleranceIn(TanText, Tx, Ty, 127, 28, 180, 48 ,40);
FreeBITMap(TanText);
end;
Function NPCFindNClick( NPCColor1, NPCColor2:integer; UpText1,UpText2, COption:string;RepeatUntil, RightOrLeft:boolean;
HMTolerance:integer):boolean;
var
TMT :Integer;
Coord123X :Integer;
Coord123Y :Integer;
T:integer;
begin
TMT:=0;
repeat
if repeatuntil then
begin
result:=true;
exit;
end;
FindTalk;
TMT:=TMT + 1
Wait(50+random(10));
if FindObjCustom(Coord123X, Coord123Y, [Uptext1, Uptext2], [NPCColor1, NPCColor2],HMTolerance) then//Thanks killerDou!:)
begin
T := GetSystemTime;
Wait(50+random(10));
Mouse(Coord123X, Coord123Y, 1, 1, RightOrLeft);
Wait(50+random(10));
if (RightOrLeft=False) then
begin
if ChooseOption(COption) then
begin
Result:=True;
WriteLn('Found Npc');
fflag(0);
ftwait(3);
if repeatuntil then Break;
end;
end;
end;
until (RepeatUntil) or (TMT>5)
if RepeatUntil then Result:=true;
Writeln(IntToStr(GetSystemTime - T));
end;
var HideDTM:integer;
procedure SetupScript;
begin
SetUpSRL;
symbolaccuracy:=0.6;
DeclarePlayers;
activateclient;
if (not(LoggedIn)) then
LoginPlayer;
MouseSpeed:=15;
makecompass('w');
HideDTM:= DTMFromString('78DA63FCC1C8C090CA800618914820FD87083' +
'5EC4C0C0CD904D47000D5E411A1269F801A36A09A72026A58806A' +
'6A89F057030135DF80AC3A026A3E00595504D4BC6724EC2F90398' +
'4C2F02D90558C5F0D0017680DC8');
end;
function HaveHides:boolean;
var tmpx,tmpy:integer;
begin
gametab(4);
if not FindDTM(HideDTM,tmpx,tmpy,mix1,miy1,mix2,miy2) then
exit;
if getcolor(tmpx+2,tmpy+4)<>getcolor(tmpx+2,tmpy+5) then
result:=true;
end;
function HaveLeathers:boolean;
var tmpx,tmpy:integer;
begin
gametab(4);
if not FindDTM(HideDTM,tmpx,tmpy,mix1,miy1,mix2,miy2) then
exit;
if getcolor(tmpx+2,tmpy+4)=getcolor(tmpx+2,tmpy+5) then
result:=true;
end;
function ToTanShop:boolean;
var tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToTanShop-Start');
if (not HaveHides) and (not HaveLeathers) then
begin
writeln('ToTanShop-No hides/leathers, false');
result:=false;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,660,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
if HaveLeathers or TanScreen then
begin
writeln('ToTanShop-Already done tanning, true')
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'quest',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx+56,tmpy+35) then
begin
writeln('ToTanShop- clicking NW of quest');
mouse(tmpx+56,tmpy+35,3,3,true);
SetRun(true);
fflag(2);
end;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,667,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
if {FindSymbol(tmpx,tmpy,'cook')
or }FindSymbol(tmpx,tmpy,'kebab shop') then
begin
if rs_OnMinimap(tmpx,tmpy+35) then
begin
writeln('ToTanShop- clicking E of cook/kebab');
mouse(tmpx,tmpy+35,3,7,true);
fflag(5);
end;
end;
if FindSymbolIn(tmpx,tmpy,'minigame',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx+32,tmpy-7) then
begin
writeln('ToTanShop- clicking NW of minigame');
mouse(tmpx+32,tmpy-7,3,3,true);
fflag(2);
end;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,667,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
end;
function ToEllis:boolean;
var yellows,yellows3:tpointarray;
var tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToEllis-Start');
if HaveLeathers or TanScreen then
begin
writeln('ToEllis-Already done tanning, true')
result:=true;
exit;
end;
if not FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
if not FindSymbolIn(tmpx,tmpy,'furnace',mmx1,53,mmx2,mmy2) then
begin
writeln('ToEllis-Cant find tannery or furnace, false');
result:=false;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
begin
FindColorsTolerance(yellows,195836,mmx1,mmy1,mmx2,mmy2,0);
writeln(inttostr(getarraylength(yellows))+' yellow pixels');
yellows3:=ReArrangeandShortenArrayEx(yellows,4,4);
writeln(inttostr(getarraylength(yellows3))+' yellow dots');
SortTPAFrom(yellows3,IntToPoint(tmpx,tmpy));
setarraylength(yellows3,2);
SortTPAFrom(yellows3,IntToPoint(mmx2,mmcy));
Mouse(yellows3[0].x,yellows3[0].y,1,1,true);
highestangle;
fflag(0);
end;
if HaveLeathers or TanScreen then
begin
writeln('ToEllis-Already done tanning, true')
result:=true;
exit;
end;
result:=true;
end;
function FindEllis:boolean;
begin
if not loggedin then exit;
writeln('FindEllis-Start');
if HaveLeathers or TanScreen then
begin
writeln('FindEllis-Already done tanning, true')
result:=true;
exit;
end;
if (not HaveHides) and (not HaveLeathers) then
begin
writeln('FindEllis-No hides/leathers, false');
result:=false;
exit;
end;
NPCFindNClick(5208281,4747209,'alk-to Ellis','Ellis','Trade',TanScreen,false,13);
if TanScreen then
writeln('FindEllis-Tanscreen, true')
else
writeln('FindEllis-Failed to find Ellis, false');
result:=tanscreen;
end;
function TanHides:boolean;
begin
writeln('TanHides-Start');
if not loggedin then exit;
if HaveLeathers then
begin
result:=true;
writeln('TanHides-Already got leathers, true');
exit;
end;
if (Players[CurrentPlayer].Booleans[0]) then
begin
writeln('TanHides-Tanning all your hides to green leather.');
//MMouse(93, 237{105},5,5);
ftwait(1);
Mouse(93, 237{105},5,5,false);
Wait(500+random(300));
ChooseOption('All');
Ftwait(4);
result:=HaveLeathers;
end;
if not(Players[CurrentPlayer].Booleans[0]) then
begin
Status('Tanning all your hides to hard leather.');
// MMouse(208, 104,5,5);
Mouse(208, 104,5,5,false);
Wait(500+random(300));
ClickOption('All', 1);
FindNormalRandoms;
Wait(1000+random(250));
end;
end;
function ToBank:boolean;
var i,tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToBank-Start');
if (HaveHides and (not HaveLeathers)) or TanScreen then
begin
writeln('ToBank- Not done tanning yet, false');
result:=false;
exit;
end;
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
if findsymbol(tmpx,tmpy,'kebab shop') then
begin
writeln('ToBank-heading SW of kebab shop');
mouse(tmpx-(15+random(10)),tmpy+10+random(5),0,0,true);
fflag(5);
end;
if nearbank then
begin
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'minigame',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx-21,tmpy-40) then
begin
writeln('ToBank- clicking NE of minigame');
mouse(tmpx-21,tmpy-40,3,3,true);
fflag(2);
end;
end;
if nearbank then
begin
result:=true;
exit;
end;
repeat
i:=i+1;
Mouse(590,100,5,5,True);
FindNormalRandoms;
fflag(5);
until (nearbank) or (i>4);
result:=nearbank;
end;
function FindBankers:boolean;
var pt:tpoint;
begin
writeln('FindBankers-Start');
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
if FindSymbol(x,y,'bank') then
begin
writeln('FindBankers-clicking near bank symbol');
Mouse(x,y,3,3,true);
fflag(5);
end;
pt:=FindFourBankers('e');
if (pt.x<>0) and (pt.y<>0) then
begin
writeln('FindBankers-Found DTM, true');
mouse(pt.x,pt.y,0,0,true);
lowestangle;
fflag(0);
result:=true;
end;
end;
function MyOpenBank:boolean;
var i:integer;
begin
if not loggedin then exit;
writeln('OpenBank-Start');
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
repeat
i:= + 1;
mousespeed:=10;
mmouse(88+random(160),80+random(50),0,0);
OpenBankGlass('akb', false, false);
mousespeed:=15;
if (not BankScreen) and (i >=2) then
begin
FindBankers;
end
until (GetColor(238, 43) = 2070783) or (i >= 4) or (BankScreen);
if BankScreen then
begin
writeln('OpenBank-Opened bank, true');
result:=true;
exit;
end;
if not BankScreen then
begin
writeln('OpenBank-failed to find bank, false');
result:=false;
exit;
end;
end;
function DepositLeathers:boolean;
begin
if not loggedin then exit;
writeln('DepositLeathers-Start');
if HaveLeathers then
begin
getmousepos(x,y);
if not( ((y>221)and(y<239)) and ((x>611)and(x<634)) ) then
Mmouse(665,227,5,5)
getmousepos(x,y);
mouse(x,y,0,0,false);
ClickOption('All', 2);
mmouse(35+49,27+38,1,1);
repeat
Wait(100+random(50));
until (not Bankscreen) or (Not Haveleathers);
TannedLeather:= TannedLeather + 27;
Progress;
end;
FixBank;
Withdraw(1, 1, 0);
CloseBank;
repeat
Wait(100+random(50));
until (not Bankscreen) or (HaveHides);
result:=HaveHides;
end;
procedure Reset;
begin
writeln('Reset');
Logout;
wait(1000);
LoginPlayer;
MouseSpeed:=15;
makecompass('w');
end;
var errors:integer;
begin
SetupScript;
repeat
//yea i know, not indented, but it looks neater this way
if ToTanShop then
if ToEllis then
if FindEllis then
if TanHides then
if ToBank then
if FindBankers then
if MyOpenBank then
if DepositLeathers then
errors:=0;
errors:=errors+1;
if errors>4 then
Reset;
until(Players[CurrentPlayer].Integers[0]<(TannedLeather));
end.
You could also have a main loop like this
repeat
Status := GetStatus;
case Status of
1: do this
2: do that
etc
end;
until
Where GetStatus looks at inventory and location and decides what to do.
You could also layer the decision making and have a very simple main loop (the top layer).
repeat
if HaveMaterials then
DoActivity
else
DoBank
until
Where in DoBank you would have more decision making. If not at bank, then go to bank. Deposit anything that isn't a part of HaveMaterials. Withdraw stuff needed for HaveMaterials. In DoActivity you also have more logic. If not at location, then go to location. If at location, then DoSomething. The third layer is the logic in GoToBank and GoToLocation, which is easy with reflection. just have a TPA path, and instead of starting at one end or another, start at the closet point to your current position (which will be one end or another when everything is normal). If the closest point to your current position is out of sight, blind click towards it. If you aren't getting closer with each click, then you are lost so set player false (unless you have a world walker with a node near you and a node near the location).