{
 +-----------------------+
 +-- Scripters Include --+
 +-----------------------+
}

{.include boxbreaker2.txt}

const
{  +----------------+
   +-- User Setup --+
   +----------------+
{+--------------------+}
  User1='';
  Pass1='';
{+--------------------+}
  User2='';
  Pass2='';
{+--------------------+}
  User3='';
  Pass3='';
{+--------------------+}
  User4='';
  Pass4='';
{+--------------------+}
  User5='';
  Pass5='';
{+--------------------+}

{  +--------------+
   +-- Si Setup --+
   +--------------+
                    }
  MouseEase     = 4;
  MouseSpeed    = 5;
  SendTextTime  = 100;
  SendTextRan   = 100;
  SiVersion     = '1.4.5';

type
  RandomType = (rtText, rtLamp, rtLogout, rtAttack, rtLeveled, rtBox, rtDead, rtMod, rtPlant);
  RandomTypeSet = set of RandomType;

var
  Updt: TForm;
  MskUseQuick, MskFive, MskTen, MskAll, MskX, MskCancel:Integer;
  dtmLamp, dtmPlant, bmpMod, bmpAdmin, bmpBank, bmpFlag:Integer;
  chrUpChars, chrChatChars, chrFont3: Integer;
  gSiSt, gSiAxeH, gSiAxeS, gSiABT, gSiPickH:Integer;
  gSiRandoms:array[0..6] of Integer;
  gSiUser, gSiPass:array[0..5] of string;
  gSiSay  :array[1..30] of string;
  gSiUpdateIt:boolean;
  srtAll: RandomTypeSet;

{-----------------------------------------------------------------------+
  Returns the Distance between x1,y1 and x2,y2
+-----------------------------------------------------------------------}

function Dist(x1,y1,x2,y2:Integer):Integer;
begin
 result:=Trunc(Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+0.999999);
end;

{-----------------------------------------------------------------------+
  Moves the mouse human-like and undetectably to the specified Location
+-----------------------------------------------------------------------}

procedure MMouse(dx,dy,rx,ry:Integer);
var
  fx, fy, x, y:Integer;
  step:Extended;
begin
 step:=MouseEase;
 fx:=random(rx); fy:=random(ry);
 dx:=dx+fx-rx/2; dy:=dy+fy-ry/2;
 GetMousePos(x,y);
 repeat
  if(Dist(x,y,dx,dy)<100)then
  begin
   if(not(Dist(x,y,dx,dy)=0))then
    step:=step-(10/Dist(x,y,dx,dy));
  end;
  if(step<1)then step:=1;
  x:=x+Round((dx-x)/step);
  y:=y+Round((dy-y)/step);
  MoveMouse(x,y);
  Wait(15-MouseSpeed);
 until(Dist(x,y,dx,dy)=0);
end;

{-----------------------------------------------------------------------+
  Moves the mouse then clicks it at the specified location
+-----------------------------------------------------------------------}

procedure Mouse(x,y,rx,ry:Integer; left:Boolean);
var a:Integer;
begin
  MMouse(x,y,rx,ry);
  Wait(10);
  GetMousePos(x,y);
  Wait(50+random(25));
  HoldMouse(x-1,y+1,left);
  repeat
    Wait(10+Random(1));
    a:=a+1;
  until(a>4);
  GetMousePos(x,y);
  ReleaseMouse(x,y,left);
  Wait(100+random(250));
  MMouse(x,y,2,2);
  Wait(50+random(200));
end;

{-----------------------------------------------------------------------+
  Switches between game tabs (1-7)
+-----------------------------------------------------------------------}

procedure GameTab(tabnumber:Integer);
begin
 case tabnumber of
  1:if(GetColor(559,179)=5531511)then Mouse(559,186,5,5,true);
  2:if(GetColor(591,176)=5531511)then Mouse(585,186,5,5,true);
  3:if(GetColor(618,176)=5531511)then Mouse(614,186,5,5,true);
  4:if(GetColor(636,174)=5531511)then Mouse(650,186,5,5,true);
  5:if(GetColor(682,174)=5531511)then Mouse(683,186,5,5,true);
  6:if(GetColor(683,175)=5531511)then Mouse(711,186,5,5,true);
  7:if(GetColor(734,177)=5531511)then Mouse(738,186,5,5,true);
  8:if(GetColor(705,495)=5531511)then Mouse(710,480,5,5,true);
 end;
  Wait(450);
end;

{-----------------------------------------------------------------------+
  Moves mouse to specified inventory spot
+-----------------------------------------------------------------------}

procedure MMouseItem(invin:Integer);
var
  sx,sy,row,col:Integer;
begin
  GameTab(4);
  row:=trunc(invin div 4)
  col:=invin-(row*4)-1
  if col<0 then
  begin
    col:=3
    row:=row-1
  end;
    sx:=562+col*42+25
    sy:=208+row*37+23
    mmouse(sx,sy,8,8)
    Wait(400+random(200));
end;

{-----------------------------------------------------------------------+
  Moves mouse to invin spot then clicks left or right
+-----------------------------------------------------------------------}

procedure MouseItem(invin:Integer;left:Boolean);
var
  sx,sy,row,col:Integer;
begin
  GameTab(4);
  row:=trunc(invin div 4)
  col:=invin-(row*4)-1
  if col<0 then
  begin
    col:=3
    row:=row-1
  end;
    sx:=562+col*42+25
    sy:=208+row*37+23
    Mouse(sx,sy,8,8,left)
    Wait(400+random(200));
end;

{-----------------------------------------------------------------------+
  Left clicks specified invin spot
+-----------------------------------------------------------------------}

procedure UseItem(invin:Integer);
begin
   MouseItem(invin,true);
end;

{-----------------------------------------------------------------------+
  Drags Item from first position Inv1 to Inv2 (Inventory Slots)
+-----------------------------------------------------------------------}

procedure DragItem(inv1, inv2:Integer);
var
  x, y:Integer;
begin
  MMouseItem(Inv1);
  GetMousePos(x, y);
  HoldMouse(x, y, true);
  MMouseItem(Inv2);
  GetMousePos(x, y);
  ReleaseMouse(x, y, true);
  MMouse(x, y, 2, 2);
end;

{-----------------------------------------------------------------------+
  Results true if an item is equiped at i
+-----------------------------------------------------------------------}

function WearingItem(i: Integer):boolean;
begin
  GameTab(6);
  case i of
    1: result:= (GetColor(650,215)<>2304814);
    2: result:= (GetColor(610,280)<>2304814);
    3: result:= (GetColor(655,265)<>2304814);
    4: result:= (GetColor(695,260)<>2304814);
    5: result:= (GetColor(600,315)<>2304814);
    6: result:= (GetColor(655,305)<>2304814);
    7: result:= (GetColor(705,305)<>2304814);
    8: result:= (GetColor(650,340)<>2304814);
    9: result:= (GetColor(600,380)<>2304814);
    10:result:= (GetColor(645,375)<>2304814);
    11:result:= (GetColor(700,380)<>2304814);
  end;
end;

{-----------------------------------------------------------------------+
  UnEquips Item specified in i
+-----------------------------------------------------------------------}

procedure TakeOff(i: integer);
begin
  GameTab(5);
  case i of
    1: if (GetColor(650,215)<>2304814)then Mouse(650, 215, 5, 5, true);
    2: if (GetColor(610,280)<>2304814)then Mouse(610, 280, 5, 5, true);
    3: if (GetColor(655,265)<>2304814)then Mouse(655, 265, 5, 5, true);
    4: if (GetColor(695,260)<>2304814)then Mouse(695, 260, 5, 5, true);
    5: if (GetColor(600,315)<>2304814)then Mouse(600, 315, 5, 5, true);
    6: if (GetColor(655,305)<>2304814)then Mouse(655, 305, 5, 5, true);
    7: if (GetColor(705,305)<>2304814)then Mouse(705, 305, 5, 5, true);
    8: if (GetColor(650,340)<>2304814)then Mouse(650, 340, 5, 5, true);
    9: if (GetColor(600,380)<>2304814)then Mouse(600, 380, 5, 5, true);
    10:if (GetColor(645,375)<>2304814)then Mouse(645, 375, 5, 5, true);
    11:if (GetColor(700,380)<>2304814)then Mouse(700, 380, 5, 5, true);
  end;
end;

{-----------------------------------------------------------------------+
  Waits untill the flag on the minimap is gone
+-----------------------------------------------------------------------}

procedure Flag;
var
  x, y: Integer;
begin
 repeat
  Wait(250);
 until(not FindBitmapIn(bmpFlag, x, y, 570, 0, 725, 165));
end;

{-----------------------------------------------------------------------+
  Returns true if the flag is on the minimap
+-----------------------------------------------------------------------}

function FlagPresent:Boolean;
var
  x, y: Integer;
begin
 result:=(FindBitmapIn(bmpFlag, x, y, 570, 0, 725, 165));
end;

{-----------------------------------------------------------------------+
  Returns distance in pixels your char dot is from flag on mini-map
+-----------------------------------------------------------------------}

function FlagDist:Integer;
var
  fx, fy, value:Integer;
begin
  if(FlagPresent)then;
  begin
    if(FindBitmapIn(bmpFlag, fx, fy, 570, 0, 725, 165))then
      value:=Dist(648, 83, fx+2, fy+2)
    if(value>=651)then
      value:=0;
  end;
  result:=value;
end;

{-----------------------------------------------------------------------+
  Waits till your the specified distance in pixels from flag on mini-map
+-----------------------------------------------------------------------}

procedure HumanFlag(flagdis:Integer);
begin
 repeat
  Wait(150);
 until(FlagDist<=flagdis)
end;

{-----------------------------------------------------------------------+
  Waits until it finds the flag on the minimap
+-----------------------------------------------------------------------}

function WaitTillFlag:Boolean;
var
  FailSafe:Integer;
begin
 while(not FlagPresent)or(FailSafe<30)do
 begin
  Wait(150);
  FailSafe:=FailSafe+1;
 end;
 if(FailSafe>=30)then
  result:=false else result:=true;
end;

{-----------------------------------------------------------------------+
  Mouse and Flag combined into one easy procedure
+-----------------------------------------------------------------------}

procedure MouseFlag(cx,cy,rx,ry:Integer);
begin
 Mouse(cx,cy,rx,ry,true);
 Flag;
 Wait(500);
end;

{-----------------------------------------------------------------------+
 Mouse and Human Flag combined
+-----------------------------------------------------------------------}

procedure HumanMouseFlag(cx,cy,rx,ry,flagdis:Integer);
begin
 Mouse(cx,cy,rx,ry,true);
 HumanFlag(flagdis);
 Wait(500);
end;

{-----------------------------------------------------------------------+
  Turns mini-map to specified compass direction (N,S,E,W)
+-----------------------------------------------------------------------}

procedure MakeCompass(Direction:string);
var
   ah, angle:Integer;
begin
  angle:= round(DetectRS2MinimapCompassAngle*pi)
  case lowercase(direction) of
    'n': ah:=0;
    'e': ah:=15;
    's': ah:=10;
    'w': ah:=6;
  end;
  while(not(angle=ah))do
    begin
      angle:=round(DetectRS2MinimapCompassAngle*Pi)
      SendArrowSilentWait(1,random(20));
    end;
end;

{-----------------------------------------------------------------------+
  Align Map and Minimap north
+-----------------------------------------------------------------------}

procedure MakeNorth;
var
  arrow, waitTime, counter: Longint;
  i, times: Longint;
  angle: Extended;
  gotFromCompass:Boolean;
begin
  times := 50 + Random(50);
  for i := 1 to times do
  begin
    angle := DetectRS2MiniMapAngle(gotFromCompass);
    if gotFromCompass = True then
      WriteLn('Bah!')
    else
    begin
      if angle < Pi then begin
        arrow := 3;
        waitTime := Trunc(500 * (angle / Pi));
      end else
      begin
        arrow := 1;
        waitTime := Trunc(500 * ((2* Pi - angle) / Pi));
      end

      if waitTime > 250 then
        waitTime := 3 * waitTime;

      if waitTime = 0 then
        counter := counter + 1
      else
      begin
        SendArrowSilentWait(arrow, waitTime);
        counter := 0;
      end;

      if counter > 3 then
        Break;
    end;
  end;
end;

{-----------------------------------------------------------------------+
 Results true if gas is found , also handles it
+-----------------------------------------------------------------------}

function GasColors(gx,gy:Integer):Boolean;
var
  x, y: Integer;
begin
  if(FindColorTolerance(x,y,11056825,gx-15,gy-25,gx+15,gy+5,10))or
  (FindColorTolerance(x,y,9281445,gx-15,gy-25,gx+15,gy+5,10))or
  (FindColorTolerance(x,y,8492186,gx-15,gy-25,gx+15,gy+5,10))or
  (FindColorTolerance(x,y,7767947,gx-15,gy-25,gx+15,gy+5,10))then
   result:=true else result:=false;
end;

{-----------------------------------------------------------------------+
+-----------------------------------------------------------------------}

function GasFound(gx,gy:Integer):Boolean;
var FailSafe:Integer;
begin
 if(GasColors(gx,gy))then
 begin
  Result:=true;
  MouseFlag(648,84,2,2);
  repeat
   FailSafe:=FailSafe+1;
   Wait(250);
  until(FailSafe>=25)or(not(GasColors(gx,gy)))
 end;
end;

{-----------------------------------------------------------------------+
  Returns true if Text1, and Text2 are similar
+-----------------------------------------------------------------------}

function SimilarWords(text1,text2:string):Boolean;
var
  count, score, win:Integer;
  str1, str2:string;
begin
  if(Length(Text1)=Length(text2))then
    begin
    count:=0;
     win:=Length(Text1)-1
      repeat
        count:=count+1
        str1:=Lowercase(StrGet(Text1,count));
        str2:=Lowercase(StrGet(Text2,count));
          if(str1=str2)then
            begin
              score:=score+1
            end;
       until(count=Length(text1))
       if(Score>=win)then
        begin
         result:=true;
        end;
    end;
end;

{-----------------------------------------------------------------------+
  Results true and if found returns its position
+-----------------------------------------------------------------------}

function TextAt(x1,y1,x2,y2:Integer ; TextIt:string ; Font:Integer; var xy, yx: Integer):Boolean;
var
  Comparison:string;
  chars:Integer;
begin
  case Font of
  1: chars:= chrUpChars;
  2: chars:= chrChatChars;
  3: chars:= chrFont3;
  end;
  begin
    if(IsTextInAreaEx(x1,y1,x2,y2,xy,yx,StrGet(TextIt,1),150,Chars,False,True,0,1,-1))then
       begin
         Comparison:=GetTextAtEx(xy,yx,150,Chars,False,True,0,1,-1,Length(TextIt),True,Tr_AlphaNumericChars)
         if(SimilarWords(comparison,TextIt))then
           begin
             Result:=True;
           end;
       end
  end;
end;

{-----------------------------------------------------------------------+
  Checks if top-left corner text matches with the typed
+-----------------------------------------------------------------------}

function IsTextUp(text:string):Boolean;
begin
  result:= IsTextAt2(9,9,text,100)
end;

{-----------------------------------------------------------------------+
  Same as IsTextUp but uses different method
+-----------------------------------------------------------------------}

function IsUpText(s: string): Boolean;
begin
  Result:= IsTextAtEx(7, 7, s, 100, chrUpChars, True, False, 0, 1, -1);
end;

{-----------------------------------------------------------------------+
  Checks if last chat message matches the specified
+-----------------------------------------------------------------------}

function IsChatMessage(s: string) : Boolean;
begin
Result:= IsTextAtEx(20, 415, s, 35, chrChatChars, False, True, 0, 1, 0)
end;

{-----------------------------------------------------------------------+
  Searches for text in specified area if text is found then it clicks it
+-----------------------------------------------------------------------}

function ClickText(Text:String; x1,y1,x2,y2:Integer):Boolean;
var
  xy, yx: Integer;
begin
 if(IsTextInAreaEx(x1,y1,x2,y2,xy,yx,Text,150,chrUpChars,False,True,0,1,-1))then
 begin
  Result:=True;
  Mouse(xy+10+random(5),yx+3,7,3,true)
 end;
end;

{-----------------------------------------------------------------------+
  Right clicks cx,cy and then searches for text on a 400 pixels ratio
+-----------------------------------------------------------------------}

function ClickTextCoords(Text:string; cx,cy,r1,r2:Integer):Boolean;
var
  x, y: Integer;
begin
 Mouse(cx,cy,r1,r2,False)
 GetMousePos(x,y);
 Wait(450+random(100))
 if(ClickText(Text,x-200,y-200,x+200,y+200))then
  Result:=True;
end;


{-----------------------------------------------------------------------+
  Looks for DTM on MiniMap, if result is true and returns coords
+-----------------------------------------------------------------------}

function FindDtmMini(var cx,cy:integer; dtmname:integer):boolean;
var
  dx, dy:integer;
begin
 if(FindDTM(dtmname,dx,dy,570,5,725,155))then
  result:=true else result:=false;
 if(result)then
  begin
    cx:=dx;
    cy:=dy;
  end;
end;

{-----------------------------------------------------------------------+
  Finds on the mainscreen, if result is true and returns coords
+-----------------------------------------------------------------------}

function FindDtmMain(var cx,cy:Integer; dtmname:Integer):Boolean;
var
  x, y:Integer;
begin
 if(FindDTM(dtmname,x,y,1,1,514,336))then
  result:=true else result:=false;
 if(result)then
  begin
    cx:=x;
    cy:=y;
  end;
end;

{-----------------------------------------------------------------------+
   Takes a screenshot and saves as reason+event(event should be a number)
+-----------------------------------------------------------------------}

procedure TakeScreen(reason:string; event:Integer);
begin
 SaveScreenshot(apppath+'Scripts\'+reason+inttostr(event)+'.bmp');
 Writeln('Screenshot of: '+reason+' #'+inttostr(event));
end;

{-----------------------------------------------------------------------+
  Types text humanlike making mistakes
+-----------------------------------------------------------------------}

procedure SendText2(text:string);
var
  i, j, w:Integer;
  s:string;
begin
   for i :=1 to Length(Text) do
   begin
    s:=Text[i]
    if(random(5)+1=1)and(w<3)then
    begin
      w:= w+1
      j:= ord(s[1]);
      if(j <> 13)then
        s:= Chr(j+(random(5)+1))
      if(s=chr(13))then
        s:='l';
    end;
    SendKeys(s)
    Wait(SendTextTime+random(SendTextRan));
   end;
end;

{-----------------------------------------------------------------------+
  Types text humanlike
+-----------------------------------------------------------------------}

procedure SendText(text:string);
var  i:Integer;
begin
   for i :=1 to Length(Text) do
   begin
    SendKeys(StrGet(Text,i));
    Wait(SendTextTime+random(SendTextRan));
   end;
end;

{-----------------------------------------------------------------------+
  Returns time a script has run specified by i
+-----------------------------------------------------------------------}

function ScriptTime(i:integer):integer;
var
  ct, mn, sc, hr: LongInt;
begin
  ct:= GetTickCount - gSiSt;
  ct:= ct div 1000;
  sc:= (ct mod 60); //seconds
  ct:= ct div 60;
  mn:= (ct mod 60) + Result; //minutes
  ct:= ct div 60;
  hr:= ct;
  case i of
    1: result:= hr;
    2: result:= mn;
    3: result:= sc;
  end;
end;

{-----------------------------------------------------------------------+
  Returns time a script has run as a string
+-----------------------------------------------------------------------}

function ScriptTime2(mode: integer):string;
begin
  case mode of
    1: result:= inttostr(ScriptTime(1)) + ':' + inttostr(ScriptTime(2)) + ':' +inttostr(ScriptTime(3))
    2: begin
         if(ScriptTime(1)<>0)then
           result:= inttostr(ScriptTime(1)) +' Hours, ' + inttostr(ScriptTime(2)) + ' Minutes, and ' +inttostr(ScriptTime(3)) + ' Seconds'
         if(ScriptTime(2)<>0)then
           result:= inttostr(ScriptTime(2)) +' Minutes, and ' +inttostr(ScriptTime(3)) + ' Seconds'
         if(ScriptTime(1)+ScriptTime(2)=0)then
           result:= inttostr(ScriptTime(3)) + ' Seconds';
       end;
  end;
end;


{-----------------------------------------------------------------------+
  If true then sets run on, false set run off
+-----------------------------------------------------------------------}

procedure SetRun(run:Boolean);
begin
  GameTab(8);
  case run of
    True: if(GetColor(640,275)=5334129)then Mouse(620,265,5,5,true);
    False:if(GetColor(581,250)=5334129)then Mouse(580,265,5,5,true);
  end;
end;

{-----------------------------------------------------------------------+
  Checks if item in inventory at specified position exists
+-----------------------------------------------------------------------}

function ExistsItem(x, y: Integer): Boolean;
var
  xx, yy, f: Integer;
  Points: TPointArray;
begin
  FindColorsTolerance(Points, 3885652, 569 + x * 42, 228 + y * 36, 569 + x * 42 + 20, 228 + y * 36 + 15, 70)
  Result:= False;
  xx:= 0;
  yy:= 0;
  for f:= 0 to getarraylength(Points) - 1 do
  begin
    if(569 + x * 42 + xx <> Points[f].X)or(228 + y * 36 + yy <> Points[f].Y)then
    begin
      Result:= True;
      Exit;
    end;
    yy:= yy + 1;
    if(yy = 16)then
    begin
      xx:= xx + 1;
      yy:= 0;
    end;
  end;
end;

{-----------------------------------------------------------------------+
  Returns amount of items in your inventory
+-----------------------------------------------------------------------}

function InvinCount:integer;
var
  xx, yy, i: Integer;
begin
  GameTab(4);
  for yy:= 0 to 6 do
  begin
    for xx:= 0 to 3 do
    begin
      if(ExistsItem(xx, yy))then
        i:= i+1
    end;
  end;
    result:=i;
end;

{-----------------------------------------------------------------------+
  Closes any windows open in the rs client
+-----------------------------------------------------------------------}

function CloseWindow:Boolean;
var
  CloseLoginWindow:Integer;
  x, y: Integer;
begin
 CloseLoginWindow := DTMFromString('78DA635CC5C8C010C780021A1A1AC0342394C' +
       'FB89108357B80AC58026ACE00598904D4DC03B26208A8794CD81C' +
       '00EADB0FEE');
 if(FindDTM(CloseLoginWindow,x,y,1,1,514,336))then
 begin
   Mouse(x+5,y+2,1,1,true);
   Wait(800);
   Result:=true;
 end;
 FreeDTM(CloseLoginWindow);
end;

{-----------------------------------------------------------------------+
  Returns true if you are logged out
+-----------------------------------------------------------------------}

function LoggedOut:Boolean;
var
  ExistingUser,LoginButton:Integer;
  x, y: Integer;
begin
 ExistingUser := DTMFromString('78DA635CCAC8C0A004C448E0FFFFFF601A26C' +
       'AB89F0835F7802C555435300057F31DC8522660CE32204B838039' +
       '7B802C75026AAE0059DAF8ED02002C411286');
 LoginButton := DTMFromString('78DA635463646070026224F0FFFF7F300D136' +
       '5D407B29C51D5C0005C8D0DA61A23636B54350A4096030173E481' +
       '2C5722DCE38EAAC6C9C50F450D00800E0A1A');
 if(FindDTM(ExistingUser,x,y,415,281,511,301))or(FindDTM(LoginButton,x,y,283,313,328,333))then
  result:=true else result:=false;
end;

{-----------------------------------------------------------------------+
  Logs you out
+-----------------------------------------------------------------------}

procedure Logout;
begin
  while(not(LoggedOut))do
  begin
    Mouse(645,485,3,3,true);
    repeat
      Wait(250);
    until(GetColor(610,375)=16777215)
    Mouse(635,375,4,4,true);
    Wait(5000);
  end;
end;

{-----------------------------------------------------------------------+
  Loads Selected account to variables for Login usage
+-----------------------------------------------------------------------}

procedure LoadAccounts(acctset:Integer);
begin
 Case acctset of
   1: begin gSiUser[0]:=gSiUser[1]; gSiPass[0]:=gSiPass[1]; end;
   2: begin gSiUser[0]:=gSiUser[2]; gSiPass[0]:=gSiPass[2]; end;
   3: begin gSiUser[0]:=gSiUser[3]; gSiPass[0]:=gSiPass[3]; end;
   4: begin gSiUser[0]:=gSiUser[4]; gSiPass[0]:=gSiPass[4]; end;
   5: begin gSiUser[0]:=gSiUser[5]; gSiPass[0]:=gSiPass[5]; end;
  end;
end;

{-----------------------------------------------------------------------+
  Override constants with custom username/pass
+-----------------------------------------------------------------------}

procedure SetAccount(acctset: Integer; User, Pass: string);
begin
  case acctset of
     1: begin gSiUser[1]:= User; gSiPass[1]:= Pass; end;
     2: begin gSiUser[2]:= User; gSiPass[2]:= Pass; end;
     3: begin gSiUser[3]:= User; gSiPass[3]:= Pass; end;
     4: begin gSiUser[4]:= User; gSiPass[4]:= Pass; end;
     5: begin gSiUser[5]:= User; gSiPass[5]:= Pass; end;
  end;
  LoadAccounts(acctset);
end;

{-----------------------------------------------------------------------+
  Logs you in if you are logged out using specified account
+-----------------------------------------------------------------------}

procedure Login(Account:Integer);
var
 x, y:Integer;
begin
  LoadAccounts(Account);
  if(IsTextInAreaEx(412,281,512,303,x,y,'Existing User',150,chrUpChars,false,true,0,1,-1))then
    Mouse(x+random(70),y+5+random(5),2,2,true);
  if(IsTextInAreaEx(288,245,367,265,x,y,'Username',150,chrUpChars,false,true,0,1,-1))then
  begin
    Mouse(x+random(70),y+5+random(5),2,2,true);
    SendText(gSiUser[0]);
    SendKeys(chr(13));
    SendText(gSiPass[0]);
  end;
  if(IsTextInAreaEx(282,312,326,333,x,y,'Login',150,chrUpChars,false,true,0,1,-1))then
    Mouse(x+random(70),y+5+random(5),2,2,true);
  repeat
    Wait(100);
  until(CloseWindow)
end;

{-----------------------------------------------------------------------+
  Clicks specified color in the direction until stop color is found
+-----------------------------------------------------------------------}

procedure rdwalk(direction:string; roadcolour,stopcolour:Integer);
var
  x, y: Integer;
begin
 repeat
  Case direction of
   'N': findcolorspiral(x,y,roadcolour,570,3,721,54);
   'S': findcolorspiral(x,y,roadcolour,570,110,721,160);
   'E': findcolorspiral(x,y,roadcolour,680,3,721,160);
   'W': findcolorspiral(x,y,roadcolour,570,3,610,160);
  end;
  mouse(x,y,3,3,true);
  repeat
   Wait(500);
  until(Flagdist<20);
 until(FindColorspiral(x,y,stopcolour,570,3,720,160));
end;

{-----------------------------------------------------------------------+
  Finds all Itemd with that color, then verifies it with text
+-----------------------------------------------------------------------}

procedure UseColorText(color,numitem,tol:Integer; text:string);
var
  xi,yi,tx,ty,Used:Integer;
  x, y: Integer;
begin
 ty:=190; tx:=548;
 repeat
 yi:=yi+1;
 ty:=ty+37;
 xi:=0;
  repeat
   xi:=xi+1;
   tx:=tx+41;
   if(FindColorTolerance(x,y,color,tx-13,ty-13,tx+13,ty+13,tol))then
   begin
    MMouse(tx,ty,2,2);
    Wait(250);
    if(IsTextAt2(9,9,text,100))then
     begin
      Used:=Used+1;
      Mouse(tx,ty,3,3,true);
      Wait(150);
     end;
   end;
  until(xi=4)or(Used>=numitem)
  tx:=544;
 until(yi=7)or(Used>=numitem)
end;

{-----------------------------------------------------------------------+
  Same as UseColorText, just that right clicks and looks for Useoptext
+-----------------------------------------------------------------------}

procedure UseColorTextRcm(color,numitem,tol:Integer; text,useoptext:string);
var
  xi,yi,tx,ty,Used:Integer;
  x, y: Integer;
begin
 ty:=190; tx:=548;
 repeat
 yi:=yi+1;
 ty:=ty+37;
 xi:=0;
  repeat
   xi:=xi+1;
   tx:=tx+41;
   if(FindColorTolerance(x,y,color,tx-13,ty-13,tx+13,ty+13,tol))then
   begin
    MMouse(tx,ty,2,2);
    Wait(250);
    if(IsUpText(text))then
     begin
      Used:=Used+1;
      Mouse(tx,ty,3,3,false);
      Wait(350);
      ClickText(useoptext,588,203,739,463);
     end;
   end;
  until(xi=4)or(Used>=numitem)
  tx:=544;
 until(yi=7)or(Used>=numitem)
end;

{-----------------------------------------------------------------------+
  Same as FindColor function but searches right to left
+-----------------------------------------------------------------------}

function FindColorRight(var cx,cy:Integer; dacolor,ax1,ay1,ax2,ay2:Integer):Boolean;
var
  a,b,c,d:Integer;
  x, y: Integer;
begin
 a:=ax2-1; b:=ay1; c:=ax2; d:=ay2;
 repeat
  if(findcolor(x,y,dacolor,a,b,c,d))then
   result:=true;
  a:=a-1; c:=c-1;
 until(result)or(a<=ax1)
 if(result)then
 begin
  cx:= x;
  cy:= y;
 end;
end;

{-----------------------------------------------------------------------+
  Same as FindColorTolerance function but searches right to left
+-----------------------------------------------------------------------}

function FindColorRightTol(var cx,cy:Integer; dacolor,ax1,ay1,ax2,ay2,tol:Integer):Boolean;
var
  a,b,c,d:Integer;
  x, y: Integer;
begin
 a:=ax2-1; b:=ay1; c:=ax2; d:=ay2;
 repeat
  if(FindColorTolerance(x,y,dacolor,a,b,c,d,tol))then
   result:=true;
  a:=a-1; c:=c-1;
 until(result)or(a<=ax1)
 if(Result)then
 begin
  cx:= x;
  cy:= y;
 end;
end;

{-----------------------------------------------------------------------+
  Trys to find the object specified searching from the center out, if
  object is found it returns coords on cx, cy
+-----------------------------------------------------------------------}

function FindObj(var cx, cy:Integer; objtext:string; objcolor,tol:integer):boolean;
var
  a, b, c,
  d, x, y : Integer;
begin
  a:=257; b:=168; c:=257; d:=168;
  if(FindColorTolerance(x,y,objcolor,1,1,514,336,tol))then
  repeat
    a:=a-10; b:=b-7; c:=c+10; d:=d+7;
    if(FindColorTolerance(x, y, objcolor, a, b, a+10, d, tol))then
    begin
      MMouse(x, y, 0, 0);
      Wait(200);
      if(IsUpText(objtext))then
      begin
        result:=true;
        Break;
      end;
    end;
    if(FindColorTolerance(x, y, objcolor, a, d-7, c, d, tol))then
    begin
      MMouse(x, y, 0, 0);
      Wait(200);
      if(IsUpText(objtext))then
      begin
        result:=true;
        Break;
      end;
    end;
    if(FindColorTolerance(x, y, objcolor, c-10, b, c, d,tol))then
    begin
      MMouse(x, y, 0, 0);
      Wait(200);
      if(IsUpText(objtext))then
      begin
        result:=true;
        Break;
      end;
    end;
    if(FindColorTolerance(x, y,objcolor,a,b,c,b+7,tol))then
    begin
      MMouse(x, y, 0, 0);
      Wait(200);
      if(IsUpText(objtext))then
      begin
        result:=true;
        Break;
      end;
    end;
  until(b<6)
  if(result)then
  begin
    cx:=x;
    cy:=y;
  end;
end;

{-----------------------------------------------------------------------+
  Tries to find object by moving the mouse in the Direction specified in
  increments set by Steps, and the number of moves is detrmined by tries
+-----------------------------------------------------------------------}

function FindDirObj(var cx,cy:Integer; Direction,Text:string; Steps, Tries:Integer):Boolean;
var
  att:Integer;
  x, y: Integer;
begin
  x:=274
  y:=160
  att:=0
  if(Direction='N') then
    repeat
      att:=att+1
      MMouse(x,y-Steps,0,0)
      GetmousePos(x,y)
      if(IsUpText(Text)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='E') then
    repeat
      att:=att+1
      MMouse(x+Steps,y,0,0)
      GetmousePos(x,y)
      if(IsUpText(Text)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='W') then
    repeat
      att:=att+1
      MMouse(x-Steps,y,0,0)
      GetmousePos(x,y)
      if(IsUpText(Text)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='S') then
    repeat
      att:=att+1
      MMouse(x,y+Steps,0,0)
      GetmousePos(x,y)
      if(IsUpText(Text)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='NW') then
    repeat
      att:=att+1
      MMouse(x-Steps,y-Steps,0,0)
      GetmousePos(x,y)
      if(istextat2(9,9,Text,100)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='NE') then
    repeat
      att:=att+1
      MMouse(x+Steps,y-Steps,0,0)
      GetmousePos(x,y)
      if(IsUpText(Text)) then
      begin
        result:=true
      end else
        Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='SW') then
    repeat
    att:=att+1
    MMouse(x-Steps,y+Steps,0,0)
    GetmousePos(x,y)
    if(IsUpText(Text)) then
    begin
      result:=true
    end else
      Wait(10)
    until(IsUpText(Text)or(att>=Tries))
  if(Direction='SE') then
    repeat
    att:=att+1
    MMouse(x+Steps,y+Steps,0,0)
    GetmousePos(x,y)
    if(IsUpText(Text)) then
    begin
      result:=true
    end else
      Wait(10)
    until(IsUpText(Text)or(att>=Tries))
 if(Result=True)then
 begin
  cx:= x;
  cy:= y;
 end;
end;

{-----------------------------------------------------------------------+
  Returns true if Bank is Open
+-----------------------------------------------------------------------}

function BankScreen:Boolean;
begin
  result:=IsTextAtEx(185, 34, 'The Bank of', 30, chrUpChars, True, False, 0, 0, -1)
end;

{-----------------------------------------------------------------------+
  Opens the Bank
+-----------------------------------------------------------------------}

procedure OpenBank;
var
  x, y, fs, fs2: Integer;
begin
  repeat
    FindObj(x, y, 'Use Bank', 539728, 10);
    Mouse(x,y,4,4,false);
    Wait(500);
    if(FindBitmapMaskTolerance(mskUseQuick,x,y,0,0,495,325,0,100))then
    begin
      MouseFlag(x+10,y+5,10,4);
      repeat
      Wait(100);
      fs:=fs+1
      until(BankScreen)or(fs>=50)
    end;
    fs2:=fs2+1
  until(BankScreen) or (fs2>5);
end;
 
{-----------------------------------------------------------------------+
  Scrolls up the Bank
+-----------------------------------------------------------------------}
 
procedure FixBank;
var
  x, y:Integer;
begin
  if(GetColor(475,75)=1777699)and(BankScreen)then
  begin
    MMouse(475,65,3,3)
    GetMousePos(x,y)
    HoldMouse(x+random(1),y+random(1),true)
    while(GetColor(475,75)=1777699)do
      Wait(100);
    Wait(300+random(300))
    GetMousePos(x,y)
    ReleaseMouse(x,y,true)
  end;
end;

{-----------------------------------------------------------------------+
  Finds position of next empty slot in inventory
+-----------------------------------------------------------------------}

procedure GetEmptyItemPosition(var x, y: Integer);
var
  xx, yy: Integer;
begin
  for yy:= 0 to 6 do
  begin
    for xx:= 0 to 3 do
    begin
      if(not ExistsItem(xx, yy))then
      begin
        x:= xx;
        y:= yy;
        Exit;
      end;
    end;
  end;
end;

{-----------------------------------------------------------------------+
  Withdraws the ammount specified at the row and column specified
+-----------------------------------------------------------------------}

procedure Withdraw(row,col,amount:Integer);
var
  ex,ey,sx,sy:Integer;
  x, y: Integer;
begin
 if(BankScreen)then
 begin
  FixBank;
  sx:=42; sy:=37;
  ex:=sx+(col*49); ey:=sy+(row*39);
  if(amount=0)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskAll,x,y,27,60,459,286,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=10)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(MskTen,x,y,27,60,459,286,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=5)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskFive,x,y,27,60,459,286,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=1)then
  begin
   Mouse(ex,ey,3,3,true);
   Wait(800);
  end else
  begin
   Mouse(ex,ey,3,3,false);
   Wait(450);
   if(FindBitmapMaskTolerance(mskX,x,y,27,60,459,286,0,100))then
    Mouse(x+10,y+5,3,3,true);
   repeat
    Wait(450);
   until(GetColor(255,410)=8388608)
   SendText(inttostr(amount));
   Wait(random(300));
   SendText(chr(13));
   Wait(800);
  end;
 end;
end;

{-----------------------------------------------------------------------+
  Deposits the ammount specified at the row and column specified
+-----------------------------------------------------------------------}

procedure Deposit(row,col,amount:Integer);
var
  ex,ey,sx,sy:Integer;
  x, y: Integer;
begin
 if(BankScreen)then
 begin
  sx:=542; sy:=195;
  ex:=sx+(col*42); ey:=sy+(row*33);
  if(amount=0)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskAll,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
   if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=10)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskTen,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
   if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=5)then
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskFive,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
   if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end else if(amount=1)then
  begin
   Mouse(ex,ey,3,3,true);
   Wait(800);
  end else
  begin
   Mouse(ex,ey,3,3,false);
   Wait(800);
   if(FindBitmapMaskTolerance(mskX,x,y,568,216,731,455,0,100))then
   begin
    Mouse(x+10,y+5,3,3,true);
   repeat
    Wait(800);
   until(GetColor(255,410)=8388608)
   SendText(inttostr(amount));
   Wait(random(300));
   SendText(chr(13));
   Wait(800);
  end;
  if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
    Mouse(x+10,y+5,3,3,true);
  end;
 end;
end;

{-----------------------------------------------------------------------+
  Deposits all items in your inventory
+-----------------------------------------------------------------------}

procedure DepositAll;
var
  x, y: Integer;
begin
  if(BankScreen)then
  begin
   while(FindColor(x,y,65536,568,216,731,455))do
   begin
    Mouse(x+4,y+4,3,3,false);
     Wait(800);
     if(FindBitmapMaskTolerance(mskAll,x,y,568,216,731,455,0,100))then
     begin
      Mouse(x+10,y+5,3,3,true);
      Wait(800);
     end;
     if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
       Mouse(x+10,y+5,3,3,true);
   end;
  end;
end;

{----------------------------------------------------------------------+
  Deposits all items in specified Area
+-----------------------------------------------------------------------}

procedure DepositArea(sx,sy,ex,ey:Integer);
var
  x, y: Integer;
begin
  if(BankScreen)then
  begin
   while(FindColor(x,y,65536,sx,sy,ex,ey))do
   begin
    Mouse(x+4,y+4,3,3,false);
     Wait(800);
     if(FindBitmapMaskTolerance(mskAll,x,y,568,216,731,455,0,100))then
     begin
      Mouse(x+10,y+5,3,3,true);
      Wait(800);
     end;
     if(FindBitmapMaskTolerance(mskCancel,x,y,568,216,731,455,0,100))then
      Mouse(x+10,y+5,3,3,true);
   end;
  end;
end;

{-----------------------------------------------------------------------+
  Buys the specified amount of the Item at assigned row and column
+-----------------------------------------------------------------------}

procedure Buy(row, col, amount: Integer);
var
  ix, iy: Integer;
  ToBuy: array[1..3] of Integer;
  Done: array[1..3] of Integer;
begin
  if(row > 0)and(col > 0)then
  begin
    ix:=38+col*47;
    iy:=37+row*47;
      ToBuy[1]:= amount div 10;
      ToBuy[2]:= (amount mod 10) div 5;
      ToBuy[3]:= ((amount mod 10) mod 5)
      while(done[1] < tobuy[1])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 10', 0, 0, 503, 323))then
          Done[1]:=done[1]+1;
        Wait(300);
      end;
      while(done[2] < tobuy[2])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 5', 0, 0, 503, 323))then
          Done[2]:=done[2]+1;
        Wait(300);
      end;
      while(done[3] < tobuy[3])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 1', 0, 0, 503, 323))then
          Done[3]:=done[3]+1;
      end;
  end;
end;

{-----------------------------------------------------------------------+
  Buys the specified amout of the Item at x, y
+-----------------------------------------------------------------------}

procedure BuyCoords(x, y, amount: Integer);
var
  ix, iy: Integer;
  ToBuy: array[1..3] of Integer;
  Done: array[1..3] of Integer;
begin
      ix:=x;
      iy:=y;
      ToBuy[1]:= amount div 10;
      ToBuy[2]:= (amount mod 10) div 5;
      ToBuy[3]:= ((amount mod 10) mod 5)
      while(done[1] < tobuy[1])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 10', 0, 0, 503, 323))then
          Done[1]:=done[1]+1;
        Wait(300);
      end;
      while(done[2] < tobuy[2])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 5', 0, 0, 503, 323))then
          Done[2]:=done[2]+1;
        Wait(300);
      end;
      while(done[3] < tobuy[3])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Buy 1', 0, 0, 503, 323))then
          Done[3]:=done[3]+1;
        Wait(300);
      end;
end;

{-----------------------------------------------------------------------+
  Buys all items with that color
+-----------------------------------------------------------------------}

procedure BuyColor(Color,Amount:Integer);
var
  x, y:Integer;
begin
  while(FindColorSpiral(x,y,Color,16,53,501,321))do
  BuyCoords(x,y,amount);
end;

{-----------------------------------------------------------------------+
  Sells Items at assigned row and column
+-----------------------------------------------------------------------}

procedure Sell(row, col, amount: Integer);
var
  ix, iy: Integer;
  ToSell: array[1..3] of Integer;
  Done: array[1..3] of Integer;
begin
  if(row > 0)and(col > 0)then
  begin
  ix:=542+(col*42); iy:=195+(row*33);
      ToSell[1]:= amount div 10;
      ToSell[2]:= (amount mod 10) div 5;
      ToSell[3]:= ((amount mod 10) mod 5)
      while(done[1] < toSell[1])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 10', 530,163,763,495))then
          Done[1]:=done[1]+1;
        Wait(300);
      end;
      while(done[2] < toSell[2])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 5', 530,163,763,495))then
          Done[2]:=done[2]+1;
        Wait(300);
      end;
      while(done[3] < toSell[3])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 1', 530,163,763,495))then
          Done[3]:=done[3]+1;
      end;
  end;
end;

{-----------------------------------------------------------------------+
  Sells Item at x, y
+-----------------------------------------------------------------------}

procedure SellCoords(x, y, amount: Integer);
var
  ix, iy: Integer;
  ToSell: array[1..3] of Integer;
  Done: array[1..3] of Integer;
 begin
      ix:=x; iy:=y;
      ToSell[1]:= amount div 10;
      ToSell[2]:= (amount mod 10) div 5;
      ToSell[3]:= ((amount mod 10) mod 5)
      while(done[1] < toSell[1])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 10', 530,163,763,495))then
          Done[1]:=done[1]+1;
        Wait(300);
      end;
      while(done[2] < toSell[2])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 5', 530,163,763,495))then
          Done[2]:=done[2]+1;
        Wait(300);
      end;
      while(done[3] < toSell[3])do
      begin
        Mouse(ix,iy,3,3,false);
        if(ClickText('Sell 1', 530,163,763,495))then
          Done[3]:=done[3]+1;
      end;
end;

{-----------------------------------------------------------------------+
  Sells all items with that color
+-----------------------------------------------------------------------}

procedure SellColor(Color,Amount:Integer);
var
  x, y:Integer;
begin
  while(FindColorSpiral(x,y,Color,16,53,501,321))do
    SellCoords(x,y,amount);
end;

{-----------------------------------------------------------------------+
  Sets all chats to off
+-----------------------------------------------------------------------}

procedure ChatsOff;
var
  x, y, setx, sety, i: Integer;
begin
  for i:=0 to 2 do
  begin
    setx:= 55 + (i*135);
    sety:= 490;
    while(FindColor(x,y,16776960,setx-10,sety-10,setx+10,sety+10))do
      Mouse(x,y,5,5,true)
    while(FindColor(x,y,65280,setx-10,sety-10,setx+10,sety+10))do
      Mouse(x,y,5,5,true)
    while(FindColor(x,y,65535,setx-10,sety-10,setx+10,sety+10))do
      Mouse(x,y,5,5,true)
  end;
end;

{-----------------------------------------------------------------------+
  Sets public chat to off
+-----------------------------------------------------------------------}

procedure PublicOff;
var
  x, y: Integer;
begin
  while(FindColor(x,y,16776960,42,479,85,495))do
    Mouse(x,y,3,3,true)
  while(FindColor(x,y,65280,42,479,85,495))do
    Mouse(x,y,3,3,true)
  while(FindColor(x,y,65535,42,479,85,495))do
    Mouse(x,y,3,3,true)
end;

{-----------------------------------------------------------------------+
  Results true if finds yellow text on screen
+-----------------------------------------------------------------------}

function TextFound(var ranx, rany: Integer):Boolean;
begin
  if(FindColor(ranx,rany,65535,10,25,511,334))then
    result:=true;
end;

{-----------------------------------------------------------------------+
  Clicks through random talks till done
+-----------------------------------------------------------------------}

procedure DoTalking;
var
  x, y: Integer;
begin
  repeat
    if(FindColor(x,y,16711680,189,364,430,457))or
    (FindColor(x,y,16777215,189,364,430,457))then
    begin
     Mouse(x+10,y+3,1,1,true);
     Wait(1000);
    end;
  until(not FindColor(x,y,16711680,189,364,430,457))or(not FindColor(x,y,16777215,189,364,430,457))
end;

{-----------------------------------------------------------------------+
  Finds random and talks to it
+-----------------------------------------------------------------------}

procedure TalkToRand(ranx, rany: Integer);
var
  PixMoved,FailSafe:Integer;
  x, y: Integer;
begin
  PixMoved:= 0;
  y:= 16;
  MMouse(ranx+PixMoved, rany + y, 0, 1);
  repeat
    PixMoved:=PixMoved+2;
    MoveMouse(ranx+PixMoved, rany + y);
    Wait(50);
    if(IsUpText('Talk'))then
      Sleep(300);
  until(IsUpText('Talk'))or(PixMoved>=180);
  if(not IsUpText('Talk'))then
  begin
    y:= Random(6) + 35;
    MMouse(ranx+PixMoved, rany + y, 0, 1);
    repeat
      PixMoved:=PixMoved-3;
      MoveMouse(ranx+PixMoved, rany + y);
      Wait(50);
      if(IsUpText('Talk'))then
        Sleep(300);
    until(IsUpText('Talk'))or(PixMoved<=0);
  end;
  if(IsUpText('Talk'))then
  begin
    MouseFlag(ranx+PixMoved,rany+y,0,1);
    repeat
      Wait(250);
      FaiLSafe:=FaiLSafe+1;
    until(FailSafe>=25)or(FindColor(x,y,16711680,189,364,430,457))or(FindColor(x,y,16777215,189,364,430,457))
    DoTalking;
  end;
end;

{-----------------------------------------------------------------------+
  Results true if you are under attack
+-----------------------------------------------------------------------}

function BeingAttacked:Boolean;
var
  x, y: Integer;
begin
 result:= FindColor(x, y, 65280, 218, 143, 292, 189)
end;

{-----------------------------------------------------------------------+
  Clicks Specified skill (Lamp)
+-----------------------------------------------------------------------}

procedure ClickSkill(usage:string; var lampsx, lampsy: Integer);
begin
 case lowercase(usage) of
  'attack': Mouse(165,155,3,3,true);
  'strength': Mouse(196,155,3,3,true);
  'ranged': Mouse(227,155,3,3,true);
  'defence': Mouse(258,155,3,3,true);
  'hitpoints': Mouse(289,155,3,3,true);
  'prayer': Mouse(320,155,3,3,true);
  'agility': Mouse(184,193,3,3,true);
  'herblore': Mouse(215,193,3,3,true);
  'theiving': Mouse(246,193,3,3,true);
  'crafting': Mouse(277,193,3,3,true);
  'runecrafting': Mouse(308,193,3,3,true);
  'slayer': Mouse(339,193,3,3,true);
  'mining': Mouse(164,228,3,3,true);
  'smithing': Mouse(195,228,3,3,true);
  'fishing': Mouse(226,228,3,3,true);
  'cooking': Mouse(257,228,3,3,true);
  'firemaking': Mouse(288,228,3,3,true);
  'woodcutting': Mouse(319,228,3,3,true);
  'fletching': Mouse(350,228,3,3,true);
  else Mouse(289,155,3,3,true);
 end;
 GetMousePos(lampsx,lampsy);
end;

{-----------------------------------------------------------------------+
  If there is a lamp in your invin it uses it with the specified skill
+-----------------------------------------------------------------------}

function UseLamp(usage:string):Boolean;
var
  x, y: Integer;
  lampsx, lampsy: Integer;
begin
 while(FindDtm(dtmLamp,x,y,563,211,734,460))do
 begin
  result:=true;
  Mouse(x,y,2,2,true);
  repeat
   Wait(250);
  until(getcolor(253,122)=65535)
  Wait(350);
  ClickSkill(usage, lampsx, lampsy);
  repeat
   Wait(100)
  until(FindColor(x,y,1777020,lampsx-10,lampsy-10,lampsx+10,lampsy+10))
  Wait(350);
  Mouse(258,258,4,1,true);
  Wait(500);
 end;
end;

{-----------------------------------------------------------------------+
  Clicks on Direction, if RunFar is true it will run more than neccesary
+-----------------------------------------------------------------------}

procedure Run(dir:string; runfar:Boolean);
var
  yourx, youry, wc:Integer;
  ranx, rany, rand: Integer;
  Runed:Boolean;
begin
 yourx:=648; youry:=83;
 rand:=0;
 SetRun(true);
 while(not(runed=True))do
   begin
     if(runfar)then
      case uppercase(dir) of
       'N': Mouse(yourx,youry-63,rand,rand,true);
       'S': Mouse(yourx,youry+63,rand,rand,true);
       'E': Mouse(yourx+63,youry,rand,rand,true);
       'W': Mouse(yourx-63,youry,rand,rand,true);
      end;
     if(not runfar)then
      case uppercase(dir) of
       'N': Mouse(yourx,youry-30,rand,rand, true);
       'S': Mouse(yourx,youry+30,rand,rand, true);
       'E': Mouse(yourx+30,youry,rand,rand, true);
       'W': Mouse(yourx-30,youry,rand,rand, true);
      end;
     if(FlagPresent)then
     begin
       Runed:=True;
     end else
       rand:=rand+3;
   end;
     repeat
      wc:=wc+1
      Wait(200+random(50));
      if(TextFound(ranx, rany))then
        TalkToRand(ranx, rany);
     until(wc>=15)
     if(runfar)then
      case uppercase(dir) of
       'N': MouseFlag(yourx,youry+63,rand,rand);
       'S': MouseFlag(yourx,youry-63,rand,rand);
       'E': MouseFlag(yourx-63,youry,rand,rand);
       'W': MouseFlag(yourx+63,youry,rand,rand);
      end;
     if(not runfar)then
      case uppercase(dir) of
       'N': MouseFlag(yourx,youry+30,rand,rand);
       'S': MouseFlag(yourx,youry-30,rand,rand);
       'E': MouseFlag(yourx-30,youry,rand,rand);
       'W': MouseFlag(yourx+30,youry,rand,rand);
      end;
  GameTab(4);
end;

{-----------------------------------------------------------------------+
  Results true if there is a box in your inventory
+-----------------------------------------------------------------------}

function BoxPresent(var nsx, nsy: Integer):Boolean;
begin
 result:= FindBitMapToleranceIn(StrangeBox, nsx, nsy, 554, 205, 743, 464, 45)
end;

{-----------------------------------------------------------------------+
  Results true if you are dead, then it logs you out and Ends script
+-----------------------------------------------------------------------}

function CheckDead:boolean;
begin
  if(IsTextAtEx(20, 415, 'Oh dear', 35, chrChatChars, False, True, 0, 1, 0))then
  begin
    result:=true;
    LogOut;
    TerminateScript;
  end;
end;

{-----------------------------------------------------------------------+
  Results true if a mod is found, then it waits 30-60 mins and logs back in
+-----------------------------------------------------------------------}

function FindMod(acc: Integer):boolean;
var
  t, tx, ty:Integer;
begin
  if(FindBitmapToleranceIn(bmpMod,tx,ty,1,345,110,430,15)) or
  (FindBitmapToleranceIn(bmpAdmin,tx,ty,1,345,110,430,15))then
  begin
    result:=true;
    LogOut;
    repeat
      Wait(60000);
      t:=t+1;
    until(t>=30+random(30));
    Login(acc);
  end;
end;

{-----------------------------------------------------------------------+
  Results true if there is a plant in the screen and handles it
+-----------------------------------------------------------------------}

function FindPlant(screen:Boolean):Boolean;
var
  x, y:Integer;
begin
  if(FindColorTolerance(x, y, 11034756, 200, 90, 315, 200, 25)) or
  (FindColorTolerance(x, y, 617041, 200, 90, 315, 200, 25))then
  begin
    if(FindDTM(dtmPlant, x, y, 200, 90, 315, 200))then
    begin
      MMouse(x, y, 1, 1)
      if(IsUpText('Pick'))then
      begin
        GetMousePos(x, y);
        Mouse(x, y, 1, 1, true);
        gSiRandoms[6]:=gSiRandoms[6]+1;
        if(Screen)then
          TakeScreen('Plant', gSiRandoms[6]);
        result:=true;
      end;
    end;
  end;
end;

{-----------------------------------------------------------------------+
  Results true if you gained a level and handles text
+-----------------------------------------------------------------------}

function CheckLeveled:Boolean;
var
  x, y: Integer;
begin
  if(FindColor(x,y,16711680,114,358,494,454))or
  (FindColor(x,y,16777215,114,358,494,454))then
  begin
    result:=true;
    Mouse(x,y,0,0,true);
    Wait(500);
    if(FindColor(x,y,16711680,114,358,494,454))or
    (FindColor(x,y,16777215,114,358,494,454))then
    begin
      Mouse(x,y,0,0,true);
      Wait(300);
    end;
  end;
end;

{-----------------------------------------------------------------------+
  Acctset is the accountset to use to login, lampusage is skill to use when
  you get a lamp, rundir ("NA"(tm) disables running) is the direction
  to run from randoms in, runfar is if you want it to run far or short from
  randoms, takescreenshots is if you want it to take screenshots of randoms.
  This function does login, Talking randoms check, fight check, lamp, and
  box check and deals with them all.
  RandomTypes can be either srtAll, which means all randoms will be checked,
  or [rtAttack, rtBox, rtLamp, rtLeveled, rtLogout, rtText] or subsets
  (for an example, use [rtAttack, rtText] to deal with attackers and text
  randoms only)
+------------------------------------------------------------------------}

function CheckRandoms(acctset:Integer; lampusage,rundir:string; runfar,takescreenshot:Boolean; RandomTypes: RandomTypeSet):Boolean;
var
  x, y: Integer;
  ranx, rany: Integer;
  nsx, nsy: Integer;
begin
 PublicOff;
 Result:= False;
 if(rtLogout in RandomTypes)and(LoggedOut)then
 begin
  result:=true;
  gSiRandoms[4]:=gSiRandoms[4]+1;
  if(takescreenshot)then
   TakeScreen('Login',gSiRandoms[4]);
  Login(acctset);
 end;
 if(rtAttack in RandomTypes)and(BeingAttacked)then
 begin
  result:=true;
  gSiRandoms[0]:=gSiRandoms[0]+1;
  if(takescreenshot)then
   TakeScreen('Attack',gSiRandoms[0]);
  if(not(rundir='NA'))then
   Run(rundir,runfar);
 end;
 if(rtText in RandomTypes)and(TextFound(ranx, rany))then
 begin
  result:=true;
  gSiRandoms[1]:=gSiRandoms[1]+1;
  if(takescreenshot)then
   TakeScreen('Text',gSiRandoms[1]);
  TalkToRand(ranx, rany);
 end;
 if(rtLeveled in RandomTypes)and
 ((FindColor(x,y,16711680,114,358,494,454))or
 (FindColor(x,y,16777215,114,358,494,454)))then
 begin
  result:=true;
  gSiRandoms[5]:=gSiRandoms[5]+1;
  if(takescreenshot)then
   TakeScreen('Leveled',gSiRandoms[5]);
  CheckLeveled;
 end;
 if(rtLamp in RandomTypes)and(UseLamp(lampusage))then
 begin
  result:=true;
  gSiRandoms[2]:=gSiRandoms[2]+1;
  if(takescreenshot)then
   TakeScreen('Lamp',gSiRandoms[2]);
 end;
 if(rtBox in RandomTypes)and(BoxPresent(nsx, nsy))then
 begin
  result:=true;
  gSiRandoms[3]:=gSiRandoms[3]+1;
  if(takescreenshot)then
   TakeScreen('Box',gSiRandoms[3]);
  FindStrangeBox;
 end;
 if(rtDead in RandomTypes)then
   CheckDead;
 if(rtMod in RandomTypes)then
   FindMod(acctset);
 if(rtPlant in RandomTypes)then
   FindPlant(takescreenshot);
end;

{-----------------------------------------------------------------------+
  Shorter name for ClickTextCoords
+-----------------------------------------------------------------------}

function CTC(Text:string; x1,y1,r1,r2:Integer):Boolean;
begin
  result:= ClickTextCoords(Text,x1,y1,r1,r2)
end;

{-----------------------------------------------------------------------+
  Sets Fight Mode to specified Setting
+-----------------------------------------------------------------------}

procedure SetFightMode(Mode:Integer);
var
  s:integer;
begin
  GameTab(1);
  Wait(450);
  if(GetColor(605,317)=4345174)then
  begin
    s:=1;
  end else
    s:=2;
  if(s=1)then
  case mode of
    1:if(GetColor(580,273)=5334130)then Mouse(595,285,5,5,true);
    2:if(GetColor(580,319)=5334130)then Mouse(595,335,5,5,true);
    3:if(GetColor(580,365)=5334130)then Mouse(595,380,5,5,true);
  end;
  if(s=2)then
  case mode of
    1:if(GetColor(580,270)=5334130)then Mouse(595,285,5,5,true);
    2:if(GetColor(580,312)=5334130)then Mouse(595,325,5,5,true);
    3:if(GetColor(580,354)=5334130)then Mouse(595,370,5,5,true);
    4:if(GetColor(580,397)=5334130)then Mouse(595,410,5,5,true);
  end;
end;

{-----------------------------------------------------------------------+
  Waits for specified time and moves mouse around like bored human would
+-----------------------------------------------------------------------}

procedure SleepAndMoveMouse(Time: Integer);
var
  Moving: Boolean;
  mx, my: Integer;
  x, y, xv, yv: Extended;
  gx, gy: Extended;
  T: Integer;
begin
  GetMousePos(mx, my);
  x:= mx;
  y:= my;
  if(Random(2) = 0)then
    Moving:= False
  else
    Moving:= True;
  gx:= 130 + Random(500);
  gy:= 130 + Random(300);
  T:= GetTickCount;
  repeat
    Sleep(10);
    if(Moving)then
    begin
      //change mouse speed
      if(gx > x)then
        xv:= xv + 0.1
      else
        xv:= xv - 0.1;
      if(gy > y)then
        yv:= yv + 0.1
      else
        yv:= yv - 0.1;
      //move mouse
      x:= x + xv;
      y:= y + yv;
      MoveMouse(Round(x), Round(y));
    end;
    if(Random(100) = 0)then
      Moving:= not Moving;
    if(Random(30) = 0)then
    begin
      gx:= 130 + Random(500);
      gy:= 130 + Random(300);
    end;
  until(Abs(GetTickCount - T) >= Time);
end;

{-----------------------------------------------------------------------+
  Randomly selects w1,w2,w3, and adds randomness specified with RandW
+-----------------------------------------------------------------------}

procedure RandWait(W1,W2,W3:Integer);
var
  Rt :Integer;
begin
 rt:= ((W1+W2+W3) div 3) div 3;
 case (random(6)+1) of
  1: begin Wait(W1+Random(Rt)) end;
  2: begin Wait(W1-Random(Rt)) end;
  3: begin Wait(W2+Random(Rt)) end;
  4: begin Wait(W2-Random(Rt)) end;
  5: begin Wait(W3+Random(Rt)) end;
  6: begin Wait(W3-Random(Rt)) end;
 end;
end;

{-----------------------------------------------------------------------+
  Picks color on mouse position when you press Ctrl+G
+-----------------------------------------------------------------------}

function PickColor:Integer;
var tx,ty:Integer;
begin
 result:=0;
 Writeln('Move Your Mouse Over The Color You Wish To Pick...');
 Writeln('then Press And Hold Ctrl+G until It Says Color Picked');
 repeat
  Wait(10);
  if(IsFunctionKeyDown(1))and(IsKeyDown('g'))then
   begin
    GetMousePos(tx,ty);
    Result:=GetColor(tx,ty);
   end;
 until(not(Result=0))
 Writeln('Color Successfuly Picked');
 Writeln('Color: '+inttostr(result)+', At Coordinates ('+inttostr(tx)+', '+inttostr(ty)+')');
end;

{-----------------------------------------------------------------------+
  Sets the SCAR top line to whatever is specified in disguise
+-----------------------------------------------------------------------}

procedure DisguiseScar(disguise:string);
var application:tapplication;
    Self: TForm;
begin
 Application:= GetApplication;
 Application.Title:= disguise;
 Self:= GetSelf;
 Self.Caption:= disguise;
end;

{-----------------------------------------------------------------------+
  Finds and clicks your text searching the whole screen
+-----------------------------------------------------------------------}

procedure ClickTxt(s:string);
begin
 Wait(300);
 ClickText(s,4,4,755,488);
end;

{-----------------------------------------------------------------------+
  Picks up object
+-----------------------------------------------------------------------}

function PickUp(ObjName: string; PickUpColor, Tol:Integer): Boolean;
var
  x, y: Integer;
begin
  if(FindObj(x, y, 'Take '+ObjName, PickUpColor, Tol))then
  begin
    if(ClickTextCoords(ObjName, x, y, 1, 1))then
      result:=true;
  end;
end;

{-----------------------------------------------------------------------+
  Results true if woodcutting axe is broken
+-----------------------------------------------------------------------}

function BrokenAxe:Boolean;
begin
  GameTab(4)
  Wait(500)
  if(GetColor(593,220)=2105392)then
    Result:=True;
end;

{-----------------------------------------------------------------------+
  Gets axe colors used for Axe randoms
+-----------------------------------------------------------------------}

procedure AxeColors;
begin
  GameTab(4)
  Wait(500)
  if(not(GetColor(590,220)=4345174))then
    begin
      gSiAxeH:=GetColor(590,220)
      gSiAxeS:=GetColor(580,227)
    end;
end;

{-----------------------------------------------------------------------+
  Results true if Axe head is gone
+-----------------------------------------------------------------------}

function AxeGone:Boolean;
var tmpx,tmpy:Integer;
begin
  GameTab(4)
  Wait(500)
  if(not(FindColor(tmpx,tmpy,gSiAxeH,563,208,608,245)))then
   Result:=True;
end;

{-----------------------------------------------------------------------+
  Unites axe head and handle together
+-----------------------------------------------------------------------}

procedure FixAxe;
var
  x, y: Integer;
begin
  GameTab(4)
  Wait(500)
  FindColorSpiral(x,y,gSiAxeH,553,196,752,470)
  Mouse(x,y,2,2,true)
  FindColorSpiral(x,y,gSiAxeS,553,196,752,470)
  Mouse(x,y,2,2,true)
end;

{-----------------------------------------------------------------------+
  Results true if pick is broken
+-----------------------------------------------------------------------}

function BrokenPick(i : Integer): Boolean;
begin
  case i of
    1:begin
        GameTab(4);
        result:=(GetColor(591,220)=4345174)
      end;
    2:begin
        GameTab(5);
        result:=(GetColor(581,295)=5067346)
      end;
  end;
end;

{-----------------------------------------------------------------------+
  Gets the Pick Colors
+-----------------------------------------------------------------------}

procedure GetPickColors(i : Integer);
begin
  case i of
    1:begin
        GameTab(4);
        gSiPickH:=GetColor(590, 220);
      end;
    2:begin
        GameTab(5);
        gSiPickH:=GetColor(595, 295);
      end;
  end;
end;

{-----------------------------------------------------------------------+
  Results false if PickHead is Missing
+-----------------------------------------------------------------------}

function PickHead(i : Integer):Boolean;
var
  tmpx, tmpy : Integer;
begin
  case i of
    1:begin
        GameTab(4);
        result:=FindColor(tmpx, tmpy, gSiPickH, 575, 215, 590, 225);
      end;
    2:begin
        GameTab(5);
        result:=FindColor(tmpx, tmpy, gSiPickH, 580,290, 610, 300);
      end;
  end;
end;

{-----------------------------------------------------------------------+
  Results True if it is able to Pick up the Head
+-----------------------------------------------------------------------}

function GetHead(Axe : Boolean):boolean;
var
  x, y, color : Integer;
  ps : string;
begin
  case Axe of
    True: begin ps:= 'Axe' color:= gSiAxeH end;
    False: begin ps:= 'Pick' color:= gSiPickH end;
  end;
  if not(FindObj(x, y, 'Take '+ps, color, 10))then
  begin
    x:=648;
    y:=83;
    FindColorSpiralTolerance(x, y, 241, 570, 5, 725, 155, 20)
    MouseFlag(x+5, y+5, 2, 2);
  end else
    if(ClickTextCoords('Take '+ps, x, y, 0, 0))then
      Result:=True;
  Flag;
  if(FindObj(x, y, 'Take '+ps, Color, 10))and(not(Result=true))then
  begin
    if(ClickTextCoords('Take '+ps, x, y, 0, 0))then
      Result:=True;
      Flag;
  end;
  if(Result=True)then
  repeat
  Wait(100);
  until(FindColor(x, y, Color, 570, 215, 730, 455))
end;

{-----------------------------------------------------------------------+
  Picks Up the PickAxe and attaches head with handle
+-----------------------------------------------------------------------}

procedure FixPickAxe(pickt : Integer);
var
  nx, ny, hx, hy: Integer;
begin
  case Pickt of
    1:if not (PickHead(pickt)) then
    begin
      GetEmptyItemPosition(nx, ny);
      if(GetHead(false))then
      begin
        UseItem(1);
        nx:=569 + nx * 42;
        ny:=228 + ny * 36
        Mouse(nx+7, ny, 1, 1, true);
        Wait(450+random(300));
      end;
    end;
    2:if not (PickHead(pickt)) then
    begin
      nx:=569 + nx * 42;
      ny:=228 + ny * 36
      GetEmptyItemPosition(nx, ny);
      nx:=569 + nx * 42;
      ny:=228 + ny * 36
      TakeOff(5);
      Wait(450);
      GameTab(4)
      GetEmptyItemPosition(hx, hy);
      hx:=569 + hx * 42;
      hy:=228 + hy * 36;
      if(GetHead(false))then
      begin
        Mouse(nx+7, ny, 1, 1, true)
        Wait(450+random(300));
        Mouse(hx+7, hy, 1, 1, true)
        Wait(450+random(300));
        Mouse(nx+7, ny, 1, 1, true)
      end;
    end;
  end;
end;

{-----------------------------------------------------------------------+
  Results true if there is an ent, only works when mouse is over tree.
+-----------------------------------------------------------------------}

function CheckEnt:Boolean;
var
  x, y: Integer;
begin
  if(FindColorTolerance(x,y,56797,82,7,115,21,10) and IsUpText('Chop down'))then
  begin
    result:=True;
  End;
end;

{-----------------------------------------------------------------------+
  Logs out when the loggedin time is reached, then it waits for the
  loggedout time and logs back in using the account Number.
+-----------------------------------------------------------------------}

function AntiBan(loggedin, loggedout, account: Integer): Boolean;
var
  logtime, randomin, randomout, secsin, secsout: Integer;
begin
  logtime:= (GetSystemTime - gSiABT) div 1000;
  secsin:= loggedin * 60;
  randomin:= secsin + round((secsin / (random(60)+1)) - (secsin / (random(59)+1)));
  if(logtime >= randomin)then
  begin
    LogOut;
    Result:=True;
    WriteLn('|Anti-Ban| - Logged Out');
    secsout:= loggedout * 60;
    randomout:= secsout + round((secsout / (random(59)+1)) - (secsout / (random(59)+1)));
    Writeln('Waiting ' + inttostr(randomout) + ' Seconds To Log Back In');
    Wait(randomout * 1000);
    Login(account);
    WriteLn('|Anti-Ban| - Loged In');
    gSiABT:=GetSystemTime;
  end;
end;

{-----------------------------------------------------------------------+
  Returns Coords of Skill's Row and Column (Used for GetSkill functions)
+-----------------------------------------------------------------------}

function SkillCoords(row, column:integer):Tpoint;
begin
  case Column of
    1: result.x:=586;
    2: result.x:=650;
    3: result.x:=714;
  end;
  case Row of
    1: result.y:=210;
    2: result.y:=241;
    3: result.y:=272;
    4: result.y:=303;
    5: result.y:=334;
    6: result.y:=365;
    7: result.y:=396;
  end;
end;

{-----------------------------------------------------------------------+
  Gets amount of specified skill
+-----------------------------------------------------------------------}

function GetSkillAmount(skill:string):integer;
var
  T:Tpoint;
  TmpResult:string;
  i:integer;
begin
  GameTab(2);
  case lowercase(skill) of
    'attack':T:=SkillCoords(1,1);
    'hitpoints':T:=SkillCoords(1,2);
    'mining':T:=SkillCoords(1,3);
    'strength':T:=SkillCoords(2,1);
    'agility':T:=SkillCoords(2,2);
    'smithing':T:=SkillCoords(2,3);
    'defense':T:=SkillCoords(3,1);
    'herblore':T:=SkillCoords(3,2);
    'fishing':T:=SkillCoords(3,3);
    'ranged':T:=SkillCoords(4,1);
    'theiving':T:=SkillCoords(4,2);
    'cooking':T:=SkillCoords(4,3);
    'prayer':T:=SkillCoords(5,1);
    'crafting':T:=SkillCoords(5,2);
    'firemaking':T:=SkillCoords(5,3);
    'magic':T:=SkillCoords(6,1);
    'fletching':T:=SkillCoords(6,2);
    'woodcutting':T:=SkillCoords(6,3);
    'runecrafting':T:=SkillCoords(7,1);
    'slayer':T:=SkillCoords(7,2);
  end;
  tmpResult:=GetTextAtEx(T.x,T.y,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits);
  if((tmpresult='  ') or (tmpresult=' ') or (tmpresult='') )then
    for i:=1 to 5 do
    begin
      tmpResult:=GetTextAtEx(T.x+i,T.y,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits);
    if((tmpresult<>'  ') and (tmpresult<>' ') and (tmpresult<>'') )then
      Exit;
    end;
  if(not(tmpresult='  '))then
    result:=strtoint(GetTextAtEx(T.x,T.y,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits));
end;

{-----------------------------------------------------------------------+
  Gets level of specified skill
+-----------------------------------------------------------------------}

function GetSkillLevel(skill:string):integer;
var
T:Tpoint;
TmpResult:string;
i:integer;
begin
  GameTab(2);
  case lowercase(skill) of
    'attack':T:=SkillCoords(1,1);
    'hitpoints':T:=SkillCoords(1,2);
    'mining':T:=SkillCoords(1,3);
    'strength':T:=SkillCoords(2,1);
    'agility':T:=SkillCoords(2,2);
    'smithing':T:=SkillCoords(2,3);
    'defense':T:=SkillCoords(3,1);
    'herblore':T:=SkillCoords(3,2);
    'fishing':T:=SkillCoords(3,3);
    'ranged':T:=SkillCoords(4,1);
    'theiving':T:=SkillCoords(4,2);
    'cooking':T:=SkillCoords(4,3);
    'prayer':T:=SkillCoords(5,1);
    'crafting':T:=SkillCoords(5,2);
    'firemaking':T:=SkillCoords(5,3);
    'magic':T:=SkillCoords(6,1);
    'fletching':T:=SkillCoords(6,2);
    'woodcutting':T:=SkillCoords(6,3);
    'runecrafting':T:=SkillCoords(7,1);
    'slayer':T:=SkillCoords(7,2);
  end;
  tmpResult:=GetTextAtEx(T.x+12,T.y+12,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits);
  if((tmpresult='  ') or (tmpresult=' ') or (tmpresult='') )then
    for i:=1 to 5 do
    begin
      tmpResult:=GetTextAtEx(T.x+i+12,T.y+12,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits);
    if((tmpresult<>'  ') and (tmpresult<>' ') and (tmpresult<>'') )then
      Exit;
    end;
  if(not(tmpresult='  '))then
    result:=strtoint(GetTextAtEx(T.x+12,T.y+12,100,chrFont3, False, True, 0, 5, -1, 2,true, tr_Digits));
end;

{-----------------------------------------------------------------------+
  Returns Hp left as a percentage
+-----------------------------------------------------------------------}

function HpPercent: Integer;
var
  tlevel, tamount: Integer;
begin
 tlevel:=GetSkillLevel('hitpoints');
 tamount:=GetSkillAmount('hitpoints');
 result:=(tamount * 100) / tlevel
end;

{-----------------------------------------------------------------------+
  Drops all items in specified area
+-----------------------------------------------------------------------}

procedure DropArea(x1,y1,x2,y2:Integer);
var
 x, y, Drop:Integer;
begin
  Drop:= DTMFromString('78DA63B4636260E064644006FFFFFF07D3305' +
     '1465BA01A5E5435300057E30A542344408D07500D0F01BBF48854' +
     'C346408D19A69B31D480FCCE875F0D00B9181450');
  while(FindColor(x,y,65536,x1,y1,x2,y2))do
  begin
    Mouse(x+5,y,1,1,false);
    Wait(450);
    if(FindDtm(Drop,x,y,548,168,761,496))then
    begin
      Mouse(x,y,1,1,true)
      Wait(450);
    end;
  end;
  FreeDtm(Drop);
end;

{-----------------------------------------------------------------------+
  Drops all items in inventory
+-----------------------------------------------------------------------}

procedure DropAll;
begin
  DropArea(550,196,748,468);
end;

{-----------------------------------------------------------------------+
  Drops all items with the specified color
+-----------------------------------------------------------------------}

procedure DropColor(Color:Integer);
var
  x, y, Drop:Integer;
begin
  Drop:= DTMFromString('78DA63B4636260E064644006FFFFFF07D3305' +
     '1465BA01A5E5435300057E30A542344408D07500D0F01BBF48854' +
     'C346408D19A69B31D480FCCE875F0D00B9181450');
  while(FindColor(x,y,Color,548,168,761,496))do
  begin
    Mouse(x+5,y,1,1,false);
    Wait(450);
    if(FindDtm(Drop,x,y,548,168,761,496))then
    begin
      Mouse(x,y,1,1,true)
      Wait(450);
    end;
  end;
  FreeDtm(Drop);
end;

{-----------------------------------------------------------------------+
  Drops Beer and Kebab
+-----------------------------------------------------------------------}

procedure DropUseless;
var
  x, y, drop:Integer;
begin
  Drop:= DTMFromString('78DA63B4636260E064644006FFFFFF07D3305' +
       '1465BA01A5E5435300057E30A542344408D07500D0F01BBF48854' +
       'C346408D19A69B31D480FCCE875F0D00B9181450');
  GameTab(4);
  while(FindColorSpiralTolerance(x,y,1876180,550,199,751,468,10))do
  begin
    MMouse(x,y,1,1);
    if(IsTextAt2(9,9,'Drink Be',150))then
    begin
      Mouse(x,y,1,1,false);
      if(FindDtm(Drop,x,y,548,168,761,496))then
      begin
        Mouse(x,y,1,1,true)
        Wait(450);
      end;
    end;
  end;
  while(FindColorSpiralTolerance(x,y,1677842,550,199,751,468,10))do
  begin
    MMouse(x,y,1,1);
    if(IsTextAt2(9,9,'Eat Ke',150))then
    begin
      Mouse(x,y,1,1,false);
      if(FindDtm(Drop,x,y,548,168,761,496))then
        begin
        Mouse(x,y,1,1,true)
        Wait(450);
      end;
    end;
  end;
  FreeDtm(Drop);
end;

{-----------------------------------------------------------------------+
  Types text then presses enter
+-----------------------------------------------------------------------}

procedure Speak(text:string);
begin
  SendText2(text);
  SendKeys(chr(13))
end;

{-----------------------------------------------------------------------+
  Assigns words to variables according to the ActionType (GhostSpeak)
+-----------------------------------------------------------------------}

procedure LoadWords(ActionType:string);
begin
if(Lowercase(ActionType)='fighting')then
   begin
     gSiSay[1]:='str lvls';       //Fighting
     gSiSay[2]:='def lvls';
     gSiSay[3]:='att lvls';
     gSiSay[4]:='take that';
     gSiSay[5]:='crazy';
     gSiSay[6]:='cant handle this';
     gSiSay[7]:='super';
     gSiSay[8]:='pretty fly';
     gSiSay[9]:='ooog';
     gSiSay[10]:='arg';
     gSiSay[11]:='doh';
     gSiSay[12]:='doof';
     gSiSay[13]:='ai karumba';
     gSiSay[14]:='ugg';
     gSiSay[15]:='man this is insane';
     gSiSay[16]:='booya';
     gSiSay[17]:='owning these beasts';
     gSiSay[18]:='owned';
     gSiSay[19]:='watch and learn';
     gSiSay[20]:='oh yeah';
     gSiSay[21]:='uh huh';
     gSiSay[22]:='victory dance';
     gSiSay[23]:='we are the champions';
     gSiSay[24]:='no time to sleep';
     gSiSay[25]:='perfect';
     gSiSay[26]:='captain insano';
     gSiSay[27]:='excellent';
     gSiSay[28]:='yay almost lvled up';
     gSiSay[29]:='keep it up';
     gSiSay[30]:='bring it on';
end;
if(Lowercase(ActionType)='mining')then
begin
     gSiSay[1]:='Mining lvls';       //Mining
     gSiSay[2]:='smithing lvls';
     gSiSay[3]:='stop stealin my ores';
     gSiSay[4]:='i love this pick';
     gSiSay[5]:='mining is boring';
     gSiSay[6]:='haha';
     gSiSay[7]:='lol';
     gSiSay[8]:='oh yeah';
     gSiSay[9]:='u like to mine';
     gSiSay[10]:='go away';
     gSiSay[11]:='let me mine in peace';
     gSiSay[12]:='bahaha';
     gSiSay[13]:='freakin rocks';
     gSiSay[14]:='how many ores u got in bank';
     gSiSay[15]:='ive got ores';
     gSiSay[16]:='my mining owns yours';
     gSiSay[17]:='ill give you my pick, not';
     gSiSay[18]:='noob';
     gSiSay[19]:='minin lvl';
     gSiSay[20]:='mining level';
     gSiSay[21]:='give me a rune pick';
     gSiSay[22]:='are rune picks the best';
     gSiSay[23]:='be quiet';
     gSiSay[24]:='your annoying';
     gSiSay[25]:='buzz off';
     gSiSay[26]:='go take a dump';
     gSiSay[27]:='mining takes too long';
     gSiSay[28]:='yay almost lvl up';
     gSiSay[29]:='my mining is about to lvl up';
     gSiSay[30]:='w00t';
end;
if(Lowercase(ActionType)='woodcutting')then
begin
     gSiSay[1]:='Cutting lvls';       //Woodcutting
     gSiSay[2]:='wood level';
     gSiSay[3]:='woodcutting levels';
     gSiSay[4]:='Taste my axe';
     gSiSay[5]:='poison ivy oh no';
     gSiSay[6]:='chop away';
     gSiSay[7]:='the bark is worse than the bite';
     gSiSay[8]:='whats the best tree';
     gSiSay[9]:='these trees grow fast';
     gSiSay[10]:='look at all these logs';
     gSiSay[11]:='haha';
     gSiSay[12]:='lol';
     gSiSay[13]:='owned';
     gSiSay[14]:='like my axe';
     gSiSay[15]:='my wc is about to lvl';
     gSiSay[16]:='yay woodcutting is almost lvled';
     gSiSay[17]:='bout to lvl up';
     gSiSay[18]:='w00t';
     gSiSay[19]:='are rune axes the best';
     gSiSay[20]:='i found an owl';
     gSiSay[21]:='noob';
     gSiSay[22]:='my woodcutting is better than yours';
     gSiSay[23]:='axes are cool';
     gSiSay[24]:='wow';
     gSiSay[25]:='crazy';
     gSiSay[26]:='insane';
     gSiSay[27]:='cant handle this';
     gSiSay[28]:='stupid tree';
     gSiSay[29]:='why are leaves green';
     gSiSay[30]:='whats your wc lvl';
end;
if(Lowercase(ActionType)='cooking')then
begin
     gSiSay[1]:='Cooking lvls';       //Cooking
     gSiSay[2]:='cooking level';
     gSiSay[3]:='cooking levels';
     gSiSay[4]:='Taste my pie';
     gSiSay[5]:='rofl';
     gSiSay[6]:='cook away';
     gSiSay[7]:='mmm biscuits';
     gSiSay[8]:='whats the best food';
     gSiSay[9]:='wanna see my cherry pie';
     gSiSay[10]:='look at all these cakes';
     gSiSay[11]:='haha';
     gSiSay[12]:='lol';
     gSiSay[13]:='owned';
     gSiSay[14]:='like my spatula';
     gSiSay[15]:='my cooking is about to lvl';
     gSiSay[16]:='yay cooking is almost lvled';
     gSiSay[17]:='bout to lvl up';
     gSiSay[18]:='w00t';
     gSiSay[19]:='im a chef';
     gSiSay[20]:='i found a cookie';
     gSiSay[21]:='noob';
     gSiSay[22]:='my cooking is better than yours';
     gSiSay[23]:='pies are cool';
     gSiSay[24]:='wow';
     gSiSay[25]:='crazy';
     gSiSay[26]:='insane';
     gSiSay[27]:='cant handle this';
     gSiSay[28]:='stupid oven';
     gSiSay[29]:='too much wine';
     gSiSay[30]:='whats your cooking lvl';
end;
if(Lowercase(ActionType)='fletching')then
begin
     gSiSay[1]:='Fletching lvls';       //Fletching
     gSiSay[2]:='Fletching level';
     gSiSay[3]:='fletchin levels';
     gSiSay[4]:='Taste my arrow';
     gSiSay[5]:='rofl';
     gSiSay[6]:='shoot away';
     gSiSay[7]:='my arrow has cool feathers';
     gSiSay[8]:='whats the best arrow';
     gSiSay[9]:='these arrows are crooked';
     gSiSay[10]:='look at all these arrows';
     gSiSay[11]:='haha';
     gSiSay[12]:='lol';
     gSiSay[13]:='owned';
     gSiSay[14]:='like my arrow';
     gSiSay[15]:='my fletching is about to lvl';
     gSiSay[16]:='yay fletching is almost lvled';
     gSiSay[17]:='bout to lvl up';
     gSiSay[18]:='w00t';
     gSiSay[19]:='are rune arrows the best';
     gSiSay[20]:='i dont have the skills';
     gSiSay[21]:='noob';
     gSiSay[22]:='my fletching is better than yours';
     gSiSay[23]:='arrows are cool';
     gSiSay[24]:='wow';
     gSiSay[25]:='crazy';
     gSiSay[26]:='insane';
     gSiSay[27]:='cant handle this';
     gSiSay[28]:='stupid arrow';
     gSiSay[29]:='freakin idiot';
     gSiSay[30]:='whats your fletching lvl';
end;
if(Lowercase(ActionType)='smelting')then
begin
     gSiSay[1]:='smelting lvls';       //Smelting
     gSiSay[2]:='Smelting level';
     gSiSay[3]:='smelting levels';
     gSiSay[4]:='Taste my iron bar';
     gSiSay[5]:='rofl';
     gSiSay[6]:='smelt away';
     gSiSay[7]:='how about steel';
     gSiSay[8]:='whats the best bar';
     gSiSay[9]:='these bars smelt fast';
     gSiSay[10]:='this iron keeps melting';
     gSiSay[11]:='haha';
     gSiSay[12]:='lol';
     gSiSay[13]:='owned';
     gSiSay[14]:='like my skillz';
     gSiSay[15]:='my smelting is about to lvl';
     gSiSay[16]:='yay smelting is almost lvled';
     gSiSay[17]:='bout to lvl up';
     gSiSay[18]:='w00t';
     gSiSay[19]:='are rune bars the best';
     gSiSay[20]:='i found a rune bar';
     gSiSay[21]:='noob';
     gSiSay[22]:='my smelting is better than yours';
     gSiSay[23]:='bars are cool';
     gSiSay[24]:='wow';
     gSiSay[25]:='crazy';
     gSiSay[26]:='insane';
     gSiSay[27]:='cant handle this';
     gSiSay[28]:='stupid iron';
     gSiSay[29]:='im gonna sell this and get rich';
     gSiSay[30]:='whats your smelting lvl';
end;
end;

{-----------------------------------------------------------------------+
  Would Randomly say a random phrase according to the skill in Action
+-----------------------------------------------------------------------}

procedure GhostSpeak(Action:string);
var
  rn:Integer;
begin
  LoadWords(Action)
  if(random(25)=1)then
  begin
    rn:=random(30)+1;
    Speak(gSiSay[rn])
    Wait(100+random(100));
    ChatsOff;
  end;
end;

{-----------------------------------------------------------------------+
  Returns current time as a string
+-----------------------------------------------------------------------}

function TheTime:string;
var Hour,Min,Sec,MSec:Word;
PM:string;
begin
 DecodeTime(Now, Hour, Min, Sec, MSec);
 PM:='AM';
 if(hour>12)then
 begin
  hour:=hour-12;
  PM:='PM';
 end;
 result:=(inttostr(hour) + ':' + inttostr(min) + ':' + inttostr(sec) + ' ' + PM);
end;

{-----------------------------------------------------------------------+
  Loads into Memory files for Si usage
+-----------------------------------------------------------------------}

procedure LoadItems;
begin
 chrUpChars  := LoadChars2(AppPath + 'Charsrs22\');
 chrChatChars:= LoadChars2(AppPath + 'CharsChat2\');
 chrFont3    := LoadChars2(AppPath + 'CharsChat2\fontsmall\');
 MskUseQuick := CreateBitmapMaskFromText('Use-quick', chrUpChars);
 MskTen      := CreateBitmapMaskFromText('10', chrUpChars);
 MskFive     := CreateBitmapMaskFromText('5', chrUpChars);
 MskAll      := CreateBitmapMaskFromText('All', chrUpChars);
 MskX        := CreateBitmapMaskFromText('X', chrUpChars);
 MskCancel   := CreateBitmapMaskFromText('Cancel', chrUpChars);
 srtAll      := [rtText, rtLamp, rtLogout, rtAttack, rtLeveled, rtBox, rtDead, rtMod, rtPlant];
 bmpFlag     := BitmapFromString(2, 2,'FF00005D3311C656045D3311');
 bmpMod      := BitmapFromString(9, 6, 'z78DA733472A41B74350041' +
              '08DB0009E012B13407414C5DF8D994E8220F0200F59E4633');
 bmpAdmin    := BitmapFromString(9, 6, 'z78DA7333777333B070A3' +
              '0F0904162610B60112C025E26266E96A6488A90B3F9B125DE4910' +
              '0A83249DE');
 bmpBank     := BitmapFromString(12, 7, 'z78DA333134723330304126' +
              '9D8C2D0C2C48254D0D8C5DB091D432875493893707BFF9949B032' +
              '54D4D0C089294DBE268628C8D34B33071452501412D6A80');
 dtmLamp     := DTMFromString('78DA63B462626078C4800618914820ED0454F' +
              '390801A2FA09A7B04D4F813614E1850CD53026A02806A5E10E19E' +
              '9704D4B812560300D6300994');
 dtmPlant    := DTMFromString('78DA6354636060306100031E08C5D092B0824' +
              '103483302F17F2060D404323450D5046671C2D58000A31690B046' +
              '5533ABE0305C0D18EB00092DDCE630013100D4CB0B1F');

end;

{-----------------------------------------------------------------------+
+-----------------------------------------------------------------------}

procedure ButtonYes(Sender : TObject);
begin
  Updt.ModalResult:=MrOk;
  gSiUpdateit:=True;
end;

procedure ButtonNo(Sender : TObject);
begin
  WriteLn('Si Was not updated')
  Updt.ModalResult:=MrOk
end;

procedure UpdtForm;
var
  UpdtApplication:TApplication;
  SelfUpdt: TForm;
  Update:Tlabel;
  Yes,No:TButton;
begin
  UpdtApplication:= GetApplication;
  SelfUpdt:= GetSelf;
  Updt:=TForm.Create(nil);
  Updt.Left := 100;
  Updt.Top := 115;
  Updt.Width := 160
  Updt.Height := 110
  Updt.BorderStyle := bsDialog;
  Updt.Caption := 'SI Updater'
  Update:=TLabel.Create(Updt)
  Update.Caption:= 'Do you Want to Update Si?'
  Update.Top:= 10
  Update.Left:= 10
  Update.Parent:= Updt
  Yes:=TButton.Create(Updt)
  Yes.Caption:= '&Yes'
  Yes.Top:= 35
  Yes.Left:= 20
  Yes.Width:= 40
  Yes.Parent:= Updt;
  Yes.OnClick := @buttonyes;
  Yes.Default := True;
  No:=TButton.Create(Updt)
  No.Caption:= '&No'
  No.Top:= 35
  No.Left:= 80
  No.Width:= 40
  No.Parent:= Updt;
  No.OnClick := @buttonno;
  No.Default := True;
  Updt.ShowModal
  Updt.Free
end;

procedure CheckUpdate;
var
  Ver: string;
begin
  Ver:=GetPage('http://www.xthost.info/Siscar/Versions/Version.txt')
  WriteLn('Latest Version = ' +Ver + ' Current Version = '+ SiVersion)
  if(not(Ver=''))then
  begin
    if(not(SiVersion=Ver))then
    begin
      UpdtForm;
    end;
  end;
  if(Ver='')then
  begin
    WriteLn('Connection Error')
  End;
end;

{-----------------------------------------------------------------------+
+-----------------------------------------------------------------------}

procedure UpdateInclude;
begin
  CheckUpdate;
  if(gSiUpdateit)then
  begin
    OpenWebPage('http://www.xthost.info/Siscar/')
  end;
end;

{-----------------------------------------------------------------------+
+-----------------------------------------------------------------------}

procedure InitAccounts;
begin
  gSiUser[1]:= User1;
  gSiPass[1]:= Pass1;
  gSiUser[2]:= User2;
  gSiPass[2]:= Pass2;
  gSiUser[3]:= User3;
  gSiPass[3]:= Pass3;
  gSiUser[4]:= User4;
  gSiPass[4]:= Pass4;
  gSiUser[5]:= User5;
  gSiPass[5]:= Pass5;
end;

{-----------------------------------------------------------------------+
  Loads the include, checks for updates and disguises scar as what you
  want, if you set MustUpdate to false it wont look for newer versions
+-----------------------------------------------------------------------}

procedure LoadInclude(disguise:string; MustUpdate: Boolean);
begin
  InitAccounts;
  if(MustUpdate)then
    UpdateInclude;
  DisguiseScar(disguise);
  SetMouseMode(false);
  BoxOpenerSetup;
  LoadItems;
  gSiSt:=GetSystemTime;
  gSiABT:=GetSystemTime;
end;
