Page 2 of 8 FirstFirst 1234 ... LastLast
Results 26 to 50 of 199

Thread: SRL Essence Miner v4!

  1. #26
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Many why is rune ess so cheap :[.
    600 hr * 42gp ea = 25,200gp/hr only!

    Anyways, hell yea awesome work, such a wonderful addition to our script database!

  2. #27
    Join Date
    Aug 2007
    Location
    Hawaii
    Posts
    3,880
    Mentioned
    7 Post(s)
    Quoted
    152 Post(s)

    Default

    Pure ess is supposed to be 50gp each. That is pre removal of the wilderness and free trade.
    Faith is an oasis in the heart which will never be reached by the caravan of thinking.

  3. #28
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    @ Fakawi, thanks for the really great feedback, also for the first time
    Hadn't tought of 'cant reach that' at all, I was actually thinking of doing some distance calculation to the new calibration DDTM (which you probably saw already) but your method is both more practical and way easier to do.
    Symbol finding: I have no idea why, that's still Wizzup's code and I think he must have had a really good reason to do it that way. Never saw it having a false positive before except for today so I blamed the usually quite accurate DDTM which was newly added. As you can see in (also new) FindAuburyStore, Symbol overrides DDTM when they differ too much so I have no idea why it clicks that far off, probably because as you said it indeed wrongly detected the symbol.. (wild idea, restore the NewAutocolor it used to have for finding mage symbol more accurately, the DDTM uses that too)
    The new DDTM which is used to find Aubury's shop uses both the two red lines, one blue line and one other point in the south-east corner of the varrock bank. For some reason it would give me the wrong location when not using that final one. Adding a bit of Y to the main point should get the accurate calibration below the door done Right now the main problem is actually knowing if it should open the door, the code/logic behind that one is flawed atm and also needs a rewrite.
    euphemism told me he'd redo the portal finder. My object-finding skills are really bad (as opposed to mapwalking ones) so anyone feel free to submit some kind of portal finder
    The final thing you found, exiting while inventory is half-full, is one I do not understand. Never witnessed that one and afaik it should either leave when it can't really find the essence or when the inventory is full (as it loops while not InvFull). Any ideas about that one?
    As usual, any bugfixes, patches and feedback are highly welcome!
    I made a new script, check it out!.

  4. #29
    Join Date
    Dec 2011
    Posts
    60
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    How about on line SortATPAFromMidPoint(NewATPA, IntToPoint(MSCX, MSCY));

  5. #30
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Try this. Stand at Bank. Script performs Step 1 out-of-bank and Step 2 ends-up-right-in-front-of-door. I have tried it 100 times on different worlds with some random rotation....worked 100%.

    Simba Code:
    program AubyTrot;

    {$i srl/srl.simba}

    var
      PlantColor, PlantDTM:Integer;

    procedure DeclarePlayers;
    begin
      HowManyPlayers:= 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

      Players[0].Name      := ' ';
      Players[0].Pass      := '';
      Players[0].Nick      := '';
      Players[0].Active    := true;
    end;

    //****************************************************************************//

    procedure SetupScript;
    begin
      SetUpSRL;
      DeclarePlayers;
     end;

    //****************************************************************************//

    Function GetMyColorTPA(BaseColor, MinSize, MaxSize, x1, y1, x2, y2,             // returns unique color defined by boundaries min and max
                            tol:integer): Integer;
    var
      TPA: TPointArray;
    begin
      if FindColorsTolerance(TPA, BaseColor, x1, y1, x2, y2, tol) then
      begin
        Writeln('Len TPA = ' + IntToStr(High(TPA)));
        If (High(TPA) > MinSize) and (High(TPA) < MaxSize) then
        begin
          Result := GetColor(TPA[0].x, TPA[0].y);
          Writeln('Storing Color ' + IntToStr(Result) + '...');
        end
        else
        begin
        WriteLn('ERROR: NO COLOR FOUND');
          Result := -1;
        end
      end
      else
      begin
        WriteLn('ERROR: NO COLOR FOUND');
        Result := -1;
      end;
     end;

    //****************************************************************************//

    Procedure AssemblePlantDTM;                                                     // assembles dynamically the anchorpoint of this script
                                                                                    // uses tree pixels of the three plants in the minimap
    var
      DTMSubPoints: array[0..3] of TDTMPointDef;
      DTMMainPoint: TDTMPointDef;
      TempTDTM: TDTM;

    begin
      Writeln('Assembling PlantDTM...');
      DTMMainPoint.x:=MMCx;
      DTMMainPoint.y:=MMCy;
      DTMMainPoint.areasize:=1;
      DTMMainPoint.areashape:=0;
      DTMMainPoint.color:=0;
      DTMMainPoint.tolerance:=255;                                                  // Odd thing with tol. If Tol > 100 then Mainpoint has offset

      DTMSubPoints[0].x:=618;
      DTMSubPoints[0].y:=104;
      DTMSubPoints[0].areasize:=2;
      DTMSubPoints[0].areashape:=0;
      DTMSubPoints[0].color:=PlantColor;
      DTMSubPoints[0].tolerance:=0;

      DTMSubPoints[1].x:=618;
      DTMSubPoints[1].y:=107;
      DTMSubPoints[1].areasize:=2;
      DTMSubPoints[1].areashape:=0;
      DTMSubPoints[1].color:=PlantColor;
      DTMSubPoints[1].tolerance:=0;

      DTMSubPoints[2].x:=630;
      DTMSubPoints[2].y:=104;
      DTMSubPoints[2].areasize:=2;
      DTMSubPoints[2].areashape:=0;
      DTMSubPoints[2].color:=PlantColor;
      DTMSubPoints[2].tolerance:=0;

      DTMSubPoints[3].x:=630;
      DTMSubPoints[3].y:=107;
      DTMSubPoints[3].areasize:=2;
      DTMSubPoints[3].areashape:=0;
      DTMSubPoints[3].color:=PlantColor;
      DTMSubPoints[3].tolerance:=0;


      TempTDTM.MainPoint := DTMMainPoint;
      TempTDTM.SubPoints := DTMSubPoints;
      PlantDTM            := AddDTM(TempTDTM);
    end;

    //****************************************************************************//

    Function Callibrate(Offset:String): Boolean;                                    // Clicks at fixed points relative to Anchor DDTM.
    var
      Ox, Oy, x,y:Integer;
      WhichAngle: Extended;
    Begin
       case Offset of
        'C':        // Centre
       begin
          Ox := 5 + Random(2);
          Oy := - 40;                                                               // see line 72?
          Players[CurrentPlayer].loc :='C'
        end;
       'Step_1':
        begin
          Ox := 24 + Random(2);
          Oy := 20 + Random(2);
          Players[CurrentPlayer].loc :=''
        end;
       'Step_2':
        begin
          Ox := 5 + Random(2);
          Oy := 50 + Random(2);
          Players[CurrentPlayer].loc :=''
        end;
      end
     if FindDtmRotatedSE(PlantDTM, x, y, MMX1, MMY1, MMX2, MMY2, rs_GetCompassAngleRadians-pi, rs_GetCompassAngleRadians+pi, 0.05,
       WhichAngle) then
       begin
       if rs_OnMiniMap(x,y) then
       begin
         MFF(x + Ox, y + Oy, 1, -1);
         Repeat until not IsMoving; // ugly but only for demo now (Flag's off the map :) )
         FFlag(0);
         Result := True;
         writeln('Callibrate ' + Offset + ' Succesful!');
         Exit;
         end
         else
          writeln('Coords not on minimap');                       // Maybe trunc coords to fit MM?
       end
       else
       begin
        Result := False;
        writeln(' Couldnt Callibrate -> ' + Offset + '  !');
       end;
     end;

    //****************************************************************************//

    begin
      SetupScript;
      LoginPlayer;
      PlantColor := GetMyColorTPA(3371596, 30, 150, MMCx - 20, MMCy + 10, MMCx + 40, MMCy + 40, 10);
      if PlantColor = - 1 then
      Begin
        Writeln('Couldnt find PlantColor. Terminating Script.');
        TerminateScript;
      End
      Else
      Begin
        AssemblePlantDTM;
        Repeat
    //      Callibrate('C');
          Callibrate('Step_1');
          Callibrate('Step_2');
          Callibrate('Step_1');
      Until(False);
      End;
    end.

    The DDTM consists of four green pixels of the two trees under the bank, mapped in a square, with tol 0 and areasize 2. At script startup I grab this color and construct the DDTM. The Mainpoint is Color 0 with tolerance 255, which oddly gives it a strange offset. Need to look into this more closely.

    Also note that the flag "hangs" in the bank (probably deliberate antibot measure). SRL's MouseFlagEx does NOT correct this! (Old Flagroutine did this properly....waited 40 seconds, and if the flag was still visible, it would MFF til flag gone)
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  6. #31
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Simba Code:
    function AreaToBoxArray(const AreaX1, AreaY1, AreaX2, AreaY2, Width, Height: Integer): TBoxArray;
    var
      AreaW, AreaH: Integer;
      BoxX, BoxY: Integer;
      x, y, i: Integer;
    begin
      // Calculate the area dimensions
      AreaW := AreaX2 - AreaX1 + 1;
      AreaH := AreaY2 - AreaY1 + 1;

      // Calculate the number of boxes in each dimension
      BoxX := AreaW div Width;
      if AreaW mod Width <> 0 then Inc(BoxX);
      BoxY := AreaH div Height;
      if AreaH mod Height <> 0 then Inc(BoxY);

      // Set the number of boxes
      SetLength(Result, BoxX * BoxY);

      // Calculate the boxes
      i := 0;
      for y := 0 to BoxY - 1 do
        for x := 0 to BoxX - 1 do
        begin
          Result[i] := IntToBox(AreaX1 + x * Width,
            AreaY1 + y * Height,
            Min(AreaX2, AreaX1 + (x + 1) * Width - 1),
            Min(AreaY2, AreaY1 + (y + 1) * Height - 1));
          Inc(i);
        end;
    end;



    function FindPortal(var X, Y: Integer): Boolean;
    var
      TBA: TBoxArray;
      TIA: TIntegerArray;
      PortalPoint: TPoint;
      Hi, I: Integer;
    begin
      TBA := AreaToBoxArray(MSX1, MSY1, MSX2, MSY2, 13, 17);
      TIA := PixelShiftMulti(TBA, 350);
      Hi := Length(TBA);
      for I := 0 to Hi - 1 do
        if TIA[I] > 100 then
        begin
          PortalPoint := MiddleBox(TBA[I])
          MMouse(PortalPoint.X, PortalPoint.Y, 0, 0);
          if (CountColorTolerance(14342657, 7, 7, 100, 25, 70) > 50) then
            if WaitUpTextMulti(['nter', 'ortal', 'Ent', 'Port', 'P'], 500) then
            begin
              GetMousePos(X, Y);
              Result := True;
              Exit;
            end;
        end;
    end;


    Basic FindPortal with Via PixelShift.



    ~Home

  7. #32
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by Home View Post
    Simba Code:
    function AreaToBoxArray(const AreaX1, AreaY1, AreaX2, AreaY2, Width, Height: Integer): TBoxArray;
    var
      AreaW, AreaH: Integer;
      BoxX, BoxY: Integer;
      x, y, i: Integer;
    begin
      // Calculate the area dimensions
      AreaW := AreaX2 - AreaX1 + 1;
      AreaH := AreaY2 - AreaY1 + 1;

      // Calculate the number of boxes in each dimension
      BoxX := AreaW div Width;
      if AreaW mod Width <> 0 then Inc(BoxX);
      BoxY := AreaH div Height;
      if AreaH mod Height <> 0 then Inc(BoxY);

      // Set the number of boxes
      SetLength(Result, BoxX * BoxY);

      // Calculate the boxes
      i := 0;
      for y := 0 to BoxY - 1 do
        for x := 0 to BoxX - 1 do
        begin
          Result[i] := IntToBox(AreaX1 + x * Width,
            AreaY1 + y * Height,
            Min(AreaX2, AreaX1 + (x + 1) * Width - 1),
            Min(AreaY2, AreaY1 + (y + 1) * Height - 1));
          Inc(i);
        end;
    end;



    function FindPortal(var X, Y: Integer): Boolean;
    var
      TBA: TBoxArray;
      TIA: TIntegerArray;
      PortalPoint: TPoint;
      Hi, I: Integer;
    begin
      TBA := AreaToBoxArray(MSX1, MSY1, MSX2, MSY2, 13, 17);
      TIA := PixelShiftMulti(TBA, 350);
      Hi := Length(TBA);
      for I := 0 to Hi - 1 do
        if TIA[I] > 100 then
        begin
          PortalPoint := MiddleBox(TBA[I])
          MMouse(PortalPoint.X, PortalPoint.Y, 0, 0);
          if (CountColorTolerance(14342657, 7, 7, 100, 25, 70) > 50) then
            if WaitUpTextMulti(['nter', 'ortal', 'Ent', 'Port', 'P'], 500) then
            begin
              GetMousePos(X, Y);
              Result := True;
              Exit;
            end;
        end;
    end;


    Basic FindPortal with Via PixelShift.



    ~Home
    That's awesome.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  8. #33
    Join Date
    Feb 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    its not working for me wont sign in help

  9. #34
    Join Date
    Feb 2012
    Posts
    28
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I am unable to use the script? I dont understand i can't get it started

    Players[1].Name :='';
    Players[1].Pass :='';
    Players[1].Nick :='';
    Players[1].Active := True;
    Players[1].Loc := 'Bank';
    Players[1].Booleans[0] := True; // Is The Pick Equipped?


    It highlights this whether i fill it out or not. Then i get
    (not filled)
    [Hint] (33:4): Variable 'DTMAUBURYMAP' never used at line 32
    Compiled successfully in 782 ms.
    SRL Compiled in 0 msec
    SMART Initialized.
    Loaded: Server 52, Members: False, Signed: True, Super Detail: False.
    Error: Out Of Range at line 49
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
    (filled)

    [Hint] (33:4): Variable 'DTMAUBURYMAP' never used at line 32
    Compiled successfully in 781 ms.
    SRL Compiled in 0 msec
    SMART Initialized.
    Loaded: Server 52, Members: False, Signed: True, Super Detail: False.
    Error: Out Of Range at line 49
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
    .......
    IDK

  10. #35
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Script says NumberOfPlayers = 1, yet there are 4 Players declared, thus: Error: Out Of Range at line 49. ange the number of Players to 4 and you should be fine.
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  11. #36
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    Markus, here's the new portal finder I wrote for you. Pretty sure it's 100% now. Messed around with using Simba's bitmap filters for this one.


    Simba Code:
    function FindPortal(var X, Y: Integer): Boolean;
    var
      x1, y1, x2, y2, W, H: Integer;
      CTS, ClientBitmap, I, Len: Integer;
      GrabBox: TBox;
      TPA: TPointArray;
      ATPA: T2DPointArray;
      Colors: Array of TVariantArray;
      ITarget, KMTarget: Integer;
    begin

      Result := False;
      CTS := GetColorToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetLength(Colors, 3);

      Colors[0] := [2585224, 30, 0.13, 1.49];
      Colors[1] := [11382909, 29, 1.70, 0.50];
      Colors[2] := [14806010, 5, 0.92, 5.72];

      //Grabs rectangle around player, something like 7x6 tiles
      ClientBitmap := BitmapFromClient(125, 65, 380, 265);
      SetBitmapName(ClientBitmap, 'ClientGrab');

      //Paints white rectangle around player so the player doesn't mess with finding
      TPA := TPAFromBox(IntToBox(115, 80, 147, 121));
      for I := 0 to High(TPA) do
        FastSetPixel(ClientBitmap, TPA[i].x, TPA[i].y, clBlack);

      //Changes Simba's target to the bitmap we just made
      KMTarget := GetKeyMouseTarget;
      ITarget := GetImageTarget;
      SetTargetBitmap(ClientBitmap);

      GetClientDimensions(W, H);
      x1 := 0; y1 := 0; x2 := W - 1; y2 := H - 1;

      //Applies bitmap filters to make it easier to single out portal
      GetMufasaBitmap(ClientBitmap).Invert(GetMufasaBitmap(ClientBitmap));
      GetMufasaBitmap(ClientBitmap).Brightness(GetMufasaBitmap(ClientBitmap), 80);
      GetMufasaBitmap(ClientBitmap).Contrast(GetMufasaBitmap(ClientBitmap), 3);


      //Paints most of the ground white on bitmap
      for I := 0 to 2 do
      begin

        SetColorSpeed2Modifiers(Colors[i][2], Colors[i][3]);
        FindColorsTolerance(TPA, Colors[i][0], x1, y1, x2, y2, Colors[i][1]);
        Len := Length(TPA);
        for X := 0 to (Len - 1) do
          FastSetPixel(ClientBitmap, TPA[X].x, TPA[X].y, clWhite);
      end;

      //Applies bitmap filters to make it easier to single out portal
      GetMufasaBitmap(ClientBitmap).Contrast(GetMufasaBitmap(ClientBitmap), 1);
      GetMufasaBitmap(ClientBitmap).Brightness(GetMufasaBitmap(ClientBitmap), -100);
      GetMufasaBitmap(ClientBitmap).Contrast(GetMufasaBitmap(ClientBitmap), 10);
      GetMufasaBitmap(ClientBitmap).GreyScale(GetMufasaBitmap(ClientBitmap));

      //Finds the black of the portal
      SetColorToleranceSpeed(0);
      FindColorsTolerance(TPA, 5855577, x1, y1, x2, y2, 89);
      SplitTPAWrap(TPA, 4, ATPA);
      SortATPASize(ATPA, True);

      Len := Length(ATPA);

      //Loops through black groups to find one with correct dimensions
      for I := 0 to (Len - 1) do
      begin

        GrabBox := GetTPABounds(ATPA[i]);

        W := (GrabBox.x2 - GrabBox.x1);
        H := (GrabBox.y2 - GrabBox.y1);

        X := Length(ATPA[i]);

        if (not InRange(X, 300, 1150)) then
          Continue;
        if (not (InRange(W, 25, 40) and InRange(H, 15, 40))) then
          Continue;

        SetLength(TPA, 1);
        TPA[0] := MiddleTPA(ATPA[i]);
        OffSetTPA(TPA, IntToPoint(125, 65));

        X := TPA[0].x;
        Y := TPA[0].y;

        MMouse(X, Y, 5, 5);

        Result := True;
        Break;
      end;

      //Debug image--------------------
      if (I < (Len)) then
      begin
        Len := Length(ATPA[i]);

      if Len > 0 then
        for W := 0 to (Len - 1) do
          FastSetPixel(ClientBitmap, ATPA[i][W].x, ATPA[i][W].y, clFuchsia);
      end;
      DisplayDebugImgWindow(255,200);
      DrawBitmapDebugImg(ClientBitmap);
      //-------------------------------

      //Sets Simba's target back to SMART
      FreeTarget(GetImageTarget);
      SetKeyMouseTarget(KMTarget);
      SetImageTarget(ITarget);

      SetColorToleranceSpeed(CTS);
      FreeBitmap(ClientBitmap);
    end;

    E: Updated for awesomeness.
    Last edited by euphemism; 02-06-2012 at 08:18 AM.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  12. #37
    Join Date
    Feb 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    mine is getting stuck at doors and not running to the bank all the time

  13. #38
    Join Date
    Nov 2011
    Posts
    99
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    flawless !

  14. #39
    Join Date
    Feb 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    GUYS I NEED HELP~~~~ i put everthing into the script but when i run it and get on runescape it doesnt do anything!!!?!??!?! all if says is that the script isnt freed and freeying it now HOW DO I FIX THIS PLEASE~!!~~~~~~~~~~~~

  15. #40
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    when i put my user and pass in to the section it comes up with an orange line where i have put the username can i have a solution


    thanks

  16. #41
    Join Date
    Jan 2012
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SortATPAFromMidPoint(NewATPA, IntToPoint(MSCX, MSCY));
    says compiling failed there soooo

  17. #42
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i dosent work for me it sais this
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]

  18. #43
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    sound got it working it working its quite innacurate with the moving but other than that its good

  19. #44
    Join Date
    Nov 2011
    Location
    Jozi, South Africa
    Posts
    249
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Exclamation Your portal finder routine

    @euphemism: Seeing your reply to my SPS question reminded me that I want to ask you a question about the essence miner that Markus posted using your portal finder.

    Can you give me an overview of how it works ? I would like to understand it if I can ? To my untrained eye, it seems to be over the top - but as I said, that's just my undertrained eye. Thanks!
    Ciao
    NM

  20. #45
    Join Date
    Feb 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default did not work

    it kept running around randomly it dosnt open doors and it dosnt know how to get back needs alot work but close =D

  21. #46
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Going to have to take a more wider look at the market in runescape right now to decide to risk getting banned by using this bot, not blaming the scripting just the initial spot it self sucks.

  22. #47
    Join Date
    Jan 2012
    Posts
    62
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Hey man, fixed it with a pin option and it didnt seem to work when adding the pin so i took out all other players (only one now).
    Simba Code:
    program New;
    {$i srl/srl/misc/smart.simba}
    {$i srl/srl.simba}
    {$ifdef smart}
    {$i srl/srl/misc/paintsmart.simba}
    {$endif}

    Const
       NumberOfUsers = 1;
       StartPlayer = 0;
       Loads = 900;
       VersionNumber = '3.01';
       FastAubury = True;
       SRL_ID   = '';  // Stats ID.
       SRL_PASS = ''; // Stats Pass.
       //SmartPrefix = 'world10';

    {Type
       EssLoc = Record
         Name: String;
         Info: Array Of Array Of Integer;
         MMClicks, MSEss: TPointArray;
         L, ReportIDVar: Integer;
       End;
       EssLocArray = Array Of EssLoc; }


    Var
      // EssInfo: EssLocArray;
       AubTPA: TPointArray;
       NewAutoColorWorked, NoEssFound: Boolean;
       EssenceMined, Abyss: Integer;
       MiddleDTM1, MiddleDTM2, DTMAuburyMap, DTMAuburyDoor : integer;
       //BlackOffset : integer;
    //{$DEFINE DEBUG}

    Procedure DeclarePlayers;

    Begin
      NumberOfPlayers( NumberOfUsers );
      CurrentPlayer := StartPlayer;

      Players[0].Name :='';
      Players[0].Pass :='';
      Players[0].Nick :='';
      Players[0].Active := True;
      Players[0].Loc := 'Bank';
      Players[0].Booleans[0]  := True;       // Is The Pick Equipped?
      Players[0].Pin  :='';



      Writeln( IntToStr ( HowManyPlayers ) + ' Players' );
    End;

    Procedure FNRWait(ms: Integer);

    Var
       T: Integer;
    Begin
      T := GetSystemTime;
      While GetSystemTime - T < ms Do
      Begin
        Wait(200);
        FindNormalRandoms;
      End;
    End;

    procedure MFlag;
    var
      t : integer;
    begin
      FFlag(0);
      t := GetSystemTime;
      while (GetSystemTime-t) < 7500 do
        if (PixelShift(IntToBox(mmx1, mmy1, mmx2, mmy2), 200)) < 1000 then //1000 should do
          break;
    end;

    Procedure DebugMM(TPA: TPointArray);
      {
    Var
       I, L: Integer;
       C: TCanvas; }


    Begin
      {DisplayDebugImgWindow(0, 0);
      DisplayDebugImgWindow(MMX2-MMX1, MMY2-MMY1);
      C := GetDebugCanvas;
      CopyCanvas(GetClientCanvas, C, MMX1, MMY1, MMX2, MMY2, 0, 0, MMX2 - MMX1, MMY2 - MMy1);
      L := High(tpa);
      For I := 0 To L Do
        C.Pixels[tpa[i].x - MMX1, tpa[i].y - MMY1] := 255;
      DisplayDebugImgWindow(MMX2-MMX1, MMY2-MMY1); }

    End;

    function BlackOffset : integer; //Inspired by GetMinimapDots
    var                             //18msecs, pretty slow...
      TPA : TPointArray;
      i : integer;
    begin
      result := -1;
      FindColorsTolerance(TPA, 3699532, mmx1, mmy1, mmx2, mmy2, 20); //should do?
      for i := 0 to high(TPA) do
      begin
        if (GetColor(TPA[I].X, TPA[I].Y) - GetColor(TPA[I].X-1, TPA[I].Y) = (3699532-1196650)) then
        begin             //a1                       //a2                           //a1-a2 = dif
          Result := 0-((3699532-329220)-GetColor(TPA[I].X, TPA[I].Y));//magic       //c1-c2 = dif
          //writeln('Black offset: '+ToStr(result));                                  //c2 = c1-dif
          exit;
        end;
      end;
    end;

    Function FindMagicSymbol(Var P: TPoint): Boolean;                               //Could do something nice with the black offset here...

    Var
       I, J, cts: Integer;
       Points, P2: TPointArray;
       aTPA: T2DPointArray;
       MagicSymbolColors, C: TIntegerArray;
       H, S, L: Extended;

    Begin
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.20, 2.0);
      Result := False;
      MagicSymbolColors := [2326527, 2925567];

      SetLength(Points, 0);
      For I := 0 To High(MagicSymbolColors) Do
      Begin
        SetLength(P2, 0);
        SetLength(C, 0);
        FindColorsTolerance(P2, MagicSymbolColors[I], MMX1, MMY1, MMX2, MMY2, 18);
        C := GetColors(P2);
        For J := 0 To High(C) Do
        Begin
          ColorToHSL(C[J], H, S, L);
          //If ((H > 8.5) And (H < 9.5)) Or ((H > 5.5) And (H < 7.5)) Then
          If (((H > 5.5) And (H < 10.0)) Or (H < 1.0)) And (S > 85.0) Then
          Begin
            SetLength(Points, Length(Points) + 1);
            Points[High(Points)] := P2[J];
          End;
        End;
        //Points := CombineTPA(Points, P2);
      End;
      {$IFDEF DEBUG} debugMM(Points); {$ENDIF}
      ColorToleranceSpeed(cts);
      aTPA := SplitTPA(Points, 5);
      SortATPASize(aTPA, True);
      If Length(aTPA) = 0 Then
        Exit;
      Result := Length(aTPA[0]) > 2;
      P := MiddleTPA(aTPA[0]);
      If Not Result Then
        WriteLn('No Aubury Shop');
    End;

    function FindAuburyStore(var P : TPoint) : boolean;
    var
      AuburyMapDDTM :   TSDTM;
      DTMAuburyMap  : integer;
      aFound : extended;
      P2 : TPoint;
    begin
      if (BlackOffset = -1) then
      begin
        result :=  FindMagicSymbol(P);
        exit;
      end;

      { Stop here.
      Look at this DDTM, it works quite smart imho ^-^.
      This uses the old colour relation technique discovered by yours truly in 2007.
      The technique is most commonly used for autocoloring stuff, but there are a
      few other uses like this one. The black colour is nowadays also 'modified'
      (not static), so I use it as an offset. From every colour, the main 'black'
      is substracted (the 329220) so it's made for black = 0. Because nowadays in RS
      the black is never true black, we add the 'rs black' to it (AtMine sets it).
      This way, we can create a DDTM with 100% accurate colors. No false positives.
      Note, it has a bit of area tolerance to accomodate for RS ugly rotation.
      For some reason, the last point (which is just terrain) didn't work too well
      so that one uses regular 15 tol. It's just an anchor point though, the real
      uniqueness is point 0 (the tiny bit of black at the the left).
      Points 1 and 2 are the two trees south of VEB, behind the fence. }


      AuburyMapDDTM.MainPoint.x := 608;
      AuburyMapDDTM.MainPoint.y := 107;
      AuburyMapDDTM.MainPoint.Color := 13371337; //who cares
      AuburyMapDDTM.MainPoint.Tolerance := 500; //tol is high enough
      SetLength(AuburyMapDDTM.SubPoints, 4);

      with AuburyMapDDTM.SubPoints[0] do
      begin
        x := 668;
        y := 109;
        Color := BlackOffset;
        areasize := 2;
      end;

      with AuburyMapDDTM.SubPoints[1] do
      begin
        x := 606;
        y := 48;
        Color := 3699532-329220+BlackOffset; //green
        Tolerance := 0;
        AreaSize := 2;
      end;

      with AuburyMapDDTM.SubPoints[2] do
      begin
        x := 615;
        y := 49;
        Color := 1196650-329220+BlackOffset; //brown
        AreaSize := 2;
      end;

      with AuburyMapDDTM.SubPoints[3] do //This is part of the terrain
      begin                              //probably calculated different or whatever
        x := 631;
        y := 49;
        Color := 2511437-329220+BlackOffset;
        AreaSize := 2;
        Tolerance := 15;
      end;

      //After typing this all of this by hand, WHERE THE F@#! IS THE DDTM EDITOR!!!

      DTMAuburyMap := AddSDTM(AuburyMapDDTM);
      SetDTMName(DTMAuburyMap, 'Aubury Map DDTM');
                                                                                    //For some reason it tried to click @ quest tab?
      if FindDTMRotated(DTMAuburyMap, P.x, P.y, mmx1, mmy1, mmx2, mmy2-5, -pi/2, pi/2, pi/60, afound) then
      begin                                                                         //should do some checks here to make sure it isn't too far of from mage symbol..
        writeln('Found Aubury store using offset DDTM!');
        if (FindMagicSymbol(P2)) then
        begin
          if Distance(p2.x, p2.y, p.x, p.y) > 15 then //can be tweaked
          begin
            writeln('Distance too big. Falling back to magic symbol!');
            P := P2;
          end;
          result := true;
        end;
        FreeDTM(DTMAuburyMap);                                                      //Thanks to Wizzup's leak finder, else wouldnt have found this one.
        exit;
      end;
      FreeDTM(DTMAuburyMap);
      result := FindMagicSymbol(P); //Fallback
    end;


    Function FindBankers(Var Bank: TPoint; Var Angle: Extended): Boolean;

    Var
       I: Integer;
       B, gB: TPointArray;
       aTPA: T2DPointArray;

    Begin
      Result := False;
      //FindColorsSpiralTolerance(MMCX, MMY2, B, 785125, MMX1, MMY1, MMX2, MMY2, 0);
      B := GetMiniMapDots('npc');
      aTPA := SplitTPA(B, 10);
      SortATPASize(aTPA, True);
      If Length(aTPA) = 0 Then
        Exit;
      B := aTPA[0];
      For I := 0 To High(B) - 1 Do
      Begin
        If (Abs(B[I].Y - B[I + 1].Y) < 15) And (Abs(B[I].X - B[I + 1].X) < 60) Then
        Begin
          SetLength(gB, Length(gB) + 1);
          gB[High(gB)] := B[I];
          If High(gB) > 3 Then // 4 bankers.
          Begin
            Bank := MiddleTPA(gB);
            Bank.Y := Bank.Y - 5;
            Angle := Degrees(ArcTan2(gB[0].y - gB[High(gB)].y, gB[0].x - gB[High(gB)].x)) + 90;
            If Angle < 0 Then
              Angle := 90 - (Angle * -1) + 270;
            Result := True;
            Exit;
          End;
        End
        Else
          SetLength(gB, 0);
      End;
    End;

    Function Randomize(x, Randomness: Integer): Integer;

    Begin
      Result := RandomRange(X - Randomness, X + Randomness);
    End;

    Function AtMine: Boolean; //Counts the black to see if we are in the mine

    Var
       TPA: TPointArray;
    Begin
      ColorToleranceSpeed(0);
      FindColorsTolerance(TPA, 65536, MMX1, MMY1, MMX2, MMY2, 7);
      ColorToleranceSpeed(1);
      Result := Length(TPA) > 2000;

     { if (result) and (BlackOffset = -1) then
      begin                                //fck this
        BlackColors := GetColors(TPA);
        ClearSameIntegers(BlackColors);
        for i := 0 to high (BlackColors) do
        begin
          FindColorsTolerance(TPA, BlackColors[i], mmx1, mmy1, mmx2, mmy2, 0);
          if (length(TPA) > maxcount) then
          begin
            BlackOffset := BlackColors[i];
            maxcount := Length(TPA);
          end;
        end;
        Writeln('Calculated black offset = '+ToStr(BlackOffset));
      end;        }

    End;

    function FindPortal(var cx, cy: Integer): Boolean; //by euphemism, thanks!
    var
      Area, ColorSpeed, EdgeColor, EdgeTol, GroundColor, GroundTol, I, Match,
       WallColor, WallTol: Integer;
      TestPoint: TPoint;
      EdgeHue, EdgeSat, GroundHue, GroundSat, WallHue, WallSat: Extended;
      CharBox, AreaBox, SearchBox: TBox;
      CharTPA, ColorsTPA, NewTPA, EdgeTPA, SearchTPA: TPointArray;
      ResultsATPA, NewATPA: T2DPointArray;
    begin

      ColorSpeed := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.37, 1.57);
      Match := 0;
      Result := False;

      CharBox := IntToBox(MSCX - 14, MSCY - 21, MSCX + 12, MSCY + 16);
      CharTPA := TPAFromBox(CharBox);

      //SearchBox := IntToBox(MSX1, MSY1, MSX2, MSY2);
      //SearchBox := IntToBox(201, 123, 320, 231); //FASTER, BUT THIS ONLY WORKS IF YOU ARE ADJACENT TO THE PORTAL
      SearchBox := IntToBox(MSCX - 80, MSCY - 80, MSCX + 80, MSCY + 80);
      SearchTPA := TPAFromBox(SearchBox);

      GroundColor := 7047023; GroundHue := 0.72; GroundSat := 0.22; GroundTol := 43;
      WallColor   := 16180721; WallHue  := 3.42; WallSat   := 7.34; WallTol   := 4;
      EdgeColor   := 10391949; EdgeHue  := 0.16; EdgeSat   := 0.23; EdgeTol   := 28;

      SetToleranceSpeed2Modifiers(GroundHue, GroundSat);
      if not FindColorsTolerance(NewTPA, GroundColor, SearchBox.x1, SearchBox.y1,   //Finds ground colours
       SearchBox.x2, SearchBox.y2, GroundTol) then
        Exit;

      SetToleranceSpeed2Modifiers(WallHue, WallSat);                                //Finds wall colours
      FindColorsTolerance(ColorsTPA, WallColor, SearchBox.x1, SearchBox.y1,
       SearchBox.x2, SearchBox.y2, WallTol);

      ColorsTPA := CombineTPA(ColorsTPA, NewTPA);                                   //Combine both

      SetToleranceSpeed2Modifiers(EdgeHue, EdgeSat);
      FindColorsTolerance(EdgeTPA, EdgeColor, SearchBox.x1, SearchBox.y1,
       SearchBox.x2, SearchBox.y2, EdgeTol);
                                                                                    //Add edge colours, too
      AppendTPA(ColorsTPA, EdgeTPA);
      NewTPA := ClearTPAFromTPA(SearchTPA, ColorsTPA);                              //SearchTPA is the entire box we are searching in,
      ColorsTPA := ClearTPAFromTPA(NewTPA, CharTPA);                                //We remove our own character and all other points from it

      ResultsATPA := SplitTPA(ColorsTPA, 1);
      SetLength(NewATPA, 0);

      for I := 0 to High(ResultsATPA) do                                            //This thing is still a miracle to me
      begin

        AreaBox := GetTPABounds(ResultsATPA[i]);
        Area := ((AreaBox.X2 - AreaBox.X1) * (AreaBox.Y2 - AreaBox.Y1));

        if (InRange(Area, 500, 1500) and (InRange(Length(ResultsATPA[i]), 250,      //Probably filters based on not being too small/large
         1200))) then
        begin

          SetLength(NewATPA, Length(NewATPA) + 1);
          NewATPA[Match] := ResultsATPA[i];
          Inc(Match);
        end;
      end;

      if Length(NewATPA) = 0 then                                                   //When no points left, no point to contine
        Exit;

      SortATPAFromMidPoint(NewATPA, IntToPoint(MSCX, MSCY));

      for I := 0 to High(NewATPA) do                                                //Regular (A)TPA iteration
      begin

        TestPoint := MiddleTPA(NewATPA[i]);
        MMouse(TestPoint.x, TestPoint.y, 5, 5);

        if WaitUpTextMulti(['Enter', 'Portal', 'nter', 'ortal', 'er P'], 500) then
        begin
          {$IfDef SMART}
          Smart_DrawDotsEx(True, NewATPA[i], clFuchsia);                            //Flashes the points, though noone watches it.
          Wait(100);
          SMART_ClearCanvas;
          {$EndIf}
          Result := True;

          cx := TestPoint.x;
          cy := TestPoint.y;
          Break;
        end;
      end;
    end;

    Function DoorClosedWizzup: Boolean;

    Var
       TP: TPoint;
       TPA: TPointArray;
       aTPA: T2DPointArray;
       I, c: Integer;


    Begin
      Result := False;
      c := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.2, 0.5);
      FindColorsTolerance(TPA, 5208714, 3, 3, 515, 336, 8);
      //aTPA := TPAToATPAEx(TPA, 50, 50);
      aTPA := SplitTPA(TPA, 3);
      SortATPAFrom(aTPA, IntToPoint(mscx, mscy)); //noob Wizzup forgot this one -.-'
      For I := 0 To High(aTPA) Do
      Begin
        If Length(aTPA[I]) < 320 Then
          Continue;
        TP := MiddleTPA(aTPA[I]);
        MMouse(TP.X, TP.Y, 0, 0);
        Wait(200);
        If IsUpText('pen') And IsUpText('oor') Then
        Begin
          Result := True;
          Mouse(TP.X, TP.Y, 0, 0, True);
          //FFlag(0);
          MFlag;
          Break;
        End;
      End;
      ColorToleranceSpeed(c);
      SetColorspeed2Modifiers(0.2, 0.2);
    End;

    function DoorClosedDTM : boolean;                                               //I dont want too many DTMs in here, but Demise likes them so much
    var                                                                             //and if she does the hard work, why would I? ;)
      x, y : integer;
      aFound : extended;
    begin
      result := False;
      if FindDTMRotated(DTMAuburyDoor, x, y, msx1, msy1, msx2, msy2, -Pi/4, Pi/4, Pi/60, aFound) then
      begin
        MMouse(x, y, 5, 5);
        if IsUpText('pen') and IsUpText('oor') then
        begin
          Result := True;
          ClickMouse2(true);
          MFlag;
        end;
      end;
    end;

    function DoorClosed : boolean;                                                  //'Kapstopfunctie'
    begin
      writeln('Opening door!');
      if DoorClosedDTM then
        result := true
      else if DoorClosedWizzup then
        result := true
      else
        result := false;
    end;

    Function FindArrow: Boolean;

    Var
       x, y: Integer;
    Begin
      Result := False;
    {  If NewAutoColorWorked Then //always returns false
        If FindColor(x, y, srl_AutoGetColor('transport'), MMX1, MMY1, MMX2, MMY2) Then  //Kicked new autocolor out
        Begin
          Result := True;
          WriteLn('Succesfully used NewAutoColor for FindArrow');
        End;  }

      If Not Result Then
        If FindSymbol(x, y, 'transportation') Then
          Result := True;
      If Result Then
      Begin
        Mouse(x, y, 4, 4, True);
        Wait(1000);
        //FFlag(0);
        MFlag;
        FNRWait(1000);
      End;
    End;

    Procedure BankToAubury; //need to add a dtm to this, symbol really isnt accurate at all

    Var
       V: TPoint;
       T: Integer;
    Begin
      FindNormalRandoms;
      MFNF(Randomize(640, 4), Randomize(140, 4), -1, -1);
      Wait(10000);                                                                  //Walk is indeed something ike 10, 15 seconds
      T := GetSystemTime;                                                           //As flag isn't visible, this is the right way to do it
      While (GetSystemTime - T < 60000) Do                                          //60 sec killswitch again, he seems to love those
      Begin
        FindNormalRandoms;
        If FindAuburyStore(V) Then                                                  //used to be symbol. After the first run, uses DTM.
          Break;
        Wait(500);
      End;
      If GetSystemTime - T >= 60000 Then
      Begin
        WriteLn('BankToAuburyTime');
        LogOut;
        Exit;
      End;       //It wanted to click at quest tab, wtf.
      Mouse(V.X, min(V.Y + 3,mmy2-5), 0, 0, True);                                    //Coords of mage symbol are found above
      Wait(500);
      //FFlag(0);
      MFlag;
      Players[CurrentPlayer].Loc := 'Aubury';
    End;

    Procedure MineToAubury;

    Var
       x, y, T, T2, I: Integer;

    Begin
      FNRWait(1000);

      T := GetSystemTime;
      While GetSystemTime - T < 60000 Do                                            //1 minute killswitch, again
      Begin
        If GetSystemTime - T > 30000 Then
          MakeCompass('E');                                                         //Change compass after 30 secs, might help with portal finding
        If Not AtMine Then
          Break;
        FindNormalRandoms;
        If Not FindArrow Then
        Begin
          WriteLn('MineToAubury - Could not find the transportation symbol. Exiting');
          FNRWait(5000);
          Continue;
        End;
        FindNormalRandoms;
        For I := 0 To 5 Do                                                          //6 tries to find portal
        Begin
          If FindPortal(x, y) Then
          Begin
            Mouse(x, y, 0, 0, True);
            T2 := GetSystemTime;
            While AtMine And (GetSystemTime - T2 < 10000) Do                        //We should really be out after 10 secs or so
            Begin
              //FindTalk;
              FNRWait(500);
            End;
            Break;
          End;
          Wait(250);
        End;
        FNRWait(1000);
        FindNormalRandoms;
      End;
      If GetSystemTime - T >= 60000 Then                                            //60 secs for portal finding is already quite long imo
      Begin
        //LogOut;
        WriteLn('No Portal!');
        LogOut;
        Exit;
      End;
      MakeCompass('N');
    End;

    function MageSymbolDistance : integer;                                          //Should be replaced by something that works with Aubury shop middle
    var
      p : TPoint;
    begin
      if not FindMagicSymbol(p) then
        result := MaxInt
      else
        result := Distance(p.x, p.y, mmcx, mmcy);
    end;

    Procedure AuburyToBank;                                                         //This entire function needs to be redone. It works, but not perfect.

    Var
       T: Integer;
       P: TPoint;
       A: Extended;

    Begin
      T := GetSystemTime;
      While GetSystemTime - T < 120000 Do                                           //We'll try to go to bank for 2 minutes
      Begin
        FindNormalRandoms;
        Mouse(665, 30, 8, 8, True);                                                 //magic coords, still working in 2012
        Wait(Randomize(6500, 500));                                                 //Small wait, as flag has changed a tiny bit
        FindAuburyStore(P);
        If (FlagDistance < 40) Or (Not FlagPresent) or (Distance(mmcx, mmcy, P.x, P.y) < 10) Then //Distance needs a bit of tweaking..
        Begin                                                                       //This door handling is still the most crappy thing imaginable.
          if (Distance(mmcx, mmcy, P.x, P.y) < 15) then
          begin
            writeln('Distance to store is close.');
            if (BlackOffset <> -1) then  //I'll just trust it to use the DDTM then..
            begin
              Mouse(MMCX, RandomRange(MMCY + 5, MMCY + 10), 4, 0, True);
              FNRWait(1500);
              if DoorClosed then
                writeln('Opened door!')
              else
                writeln('Could NOT open door!');
            end;
          end else
          begin
            writeln('No idea what''s going on now, flag is weird but distance to store..');
            Mouse(MMCX, RandomRange(MMCY + 5, MMCY + 15), 4, 0, True);
            FNRWait(1500);
            DoorClosed;
          end;
        End
        Else
        Begin
         { T2 := GetSystemTime;
          While GetSystemTime - T2 < 8000 Do
          Begin
            Wait(1000);
            FindMagicSymbol(P);
            If Distance(P.x, P.y, MMCX, MMCY) > 30 Then
              Break;
          End;
          FFlag(10);  }

          FNRWait(8000);
          FFlag(10);
          FindAuburyStore(P);
          If Distance(P.x, P.y, MMCX, MMCY) > 30 Then
            Break;
        End;
        If Not FindAuburyStore(P) Then
          Break;
        If Distance(P.X, P.Y, MMCX, MMCY) > 30 Then
          Break;
      End;
      WriteLn('Out of shop');
      //FFlag(0);
      MFlag;
      If FindBankers(P, A) Then
      Begin
        writeln('Found bankers using NPC dots!');
        Mouse(P.x, P.y, 0, 0, True);
        FNRWait(3000);
        //FFlag(0);
        MFlag;
      End
      Else
      If FindSymbol(P.x, P.y, 'Bank') Then
      Begin
        writeln('Found bank using symbol!');
        Mouse(P.x, P.y, 0, 0, True);
        FNRWait(3000);
        //FFlag(0);
        MFlag;
      End Else
      Begin
        WriteLn('No Bank');
        LogOut;
      End;
      Players[CurrentPlayer].Loc := 'Bank';
    End;

    Function FindAuburyText: Boolean;                                               //Hard to test this one, or shall we get legits to say
    var      // FindTalk but modded.                                                //Senventior Disthine Molenko? =)
      TPA,Matches : TPointArray;
      TempATPA : T2DPointArray;
      I,CTS,x,y : integer;
      Box  : TBox;

    begin;
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      FindColorsTolerance(TPA, 65535, 3, 3, 515, 336, 0);
      if FindTPAinTPA(aubtpa ,TPA,Matches) then  //Length check inside the function ;)
      For I := 0 to High(Matches) do                                                //This is all real magic to me..
      begin;
        FindColorsTolerance(TPA,65535,3, Matches[I].y - 1,516,Matches[I].y + 14,0);
        if High(TPA) < 0 then
          Continue;
        TempATPA := FindGapsTPA(TPA,10);
        if Length(TempATPA) > 1 then
        begin;
          SetLength(TPA,Length(TempATPA));
          For x := 0 to High(TempATPA) do
          begin;
            Box := GetTPABounds(TempATPA[x]);
            TPA[x] := Point((Box.x2 + Box.x1) shr 1, Box.y2);
          end;
          SortTPAFrom(TPA,Point(Matches[I].x,Matches[I].y));
          x := TPA[0].x;
          y := TPA[0].y;
        end else
        begin;
          Box := GetTPABounds(TempATPA[0]);
          x := (Box.x2 + Box.x1) shr 1;
          y := Box.y2;
        end;
        y := y + 8;
        MMouse(x, y, 0, 0);
        Wait(100 + Random(50));
        if IsUpTextMultiCustom(['Talk','lk-to']) then //Remember kids, 'alk' matches both Talk AND Walk
        begin
          GetMousePos(x, y);
          Mouse(x, y, 0, 0, False);
          Wait(450 + Random(125));
          If ChooseOptionMulti(['ele', 'port']) Then
          Begin
            Result := True;
            Exit;
          End;
        end;
      end;
      ColorToleranceSpeed(CTS);
    end;

    Function FindAubury: Boolean;                                                   //Not the best!

    Var
       I, T, cts: Integer;
       P: TPoint;
       PA: TPointArray;
       aPA: T2DPointArray;

    Begin
      Result := False;
      If FindAuburyStore(P) Then                                                    //This part locates inside his shop
      Begin
        If (Distance(P.x, P.y, MMCX, MMCY) > 15) Or (Random(20) = 0) Then
        Begin
          Mouse(P.x + 3, P.y + 10, 2, 2, True);
          Wait(1000);
          //FFlag(0);
          MFlag;
          wait(randomize(1200, 200));
        End;
      End;
      If FindAuburyText Then
      Begin
        Result := True;
        Exit;
      End;
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      FindColorsTolerance(PA, 6450290, MSX1, MSY1, MSX2, MSY2, 3);                  //tolerance seems low
      //writeln(inttostr(length(pa)));                                              //but is severly optimized
      aPA := TPAToATPA(PA, 50);
      SortATPAFrom(aPA, IntToPoint(mscx, mscy));                                    //Should do MiddlesATPA and then SortTPA (faster)
      //writeln(inttostr(length(apa)));
      For I := 0 To High(aPA) Do
      Begin
        //Wait(200);
        If AtMine Then
        Begin
          Result := True;
          Break;
        End;
        If Length(aPA[I]) < 3 Then
          Continue;
        P := MiddleTPA(aPA[I]);
        MMouse(p.X, P.Y, 3, 3);
        Wait(150);                                                                  //Small wait really necessary
        writeln('ut: '+rs_GetUpText);
        If Not IsUpTextMultiCustom(['bury', 'Talk']) Then                           //Bug-fix! alk fits 'Walk', too
          Continue;
        GetMousePos(P.X, P.Y);
        Mouse(P.X, P.Y, 0, 0, False);
        Wait(50);
        //writeln('here');
          //  writeln(GetChooseOptions('All'));
        If Not ChooseOptionMulti(['elep', 'ort', 'Tel']) Then                       //Here, this fixes some glitching
        begin
          Continue;
        end;
        T := GetSystemTime;
        While GetSystemTime - T < 15000 Do
        Begin
          Wait(500);
          If AtMine Or (Not FindMagicSymbol(P)) Then                                //Good enough, it's just location checking
            Break;
        End;
        Result := GetSystemTime - T < 10500;
        If AtMine Then
          Result := True;
        If Result Then
          Break;
      End;
      ColorToleranceSpeed(cts);
    End;

    Function GetCurrentTPA: TPointArray;

    Var
       cts: Integer;

    Begin
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      FindColorsTolerance(Result, clWhite, MMX1, MMy1, MMX2, MMY2, 421);            //Matches everything besides pure black
      ColorToleranceSpeed(cts);
    End;

    Function ScanMM(Const TPA: TPointArray; SD, ED, MinR, MaxR: Integer): Integer;  //Not used anymore with new cool mine handling

    Begin
      FilterPointsPie(TPA, SD, ED, MinR, MaxR, MMCX, MMCY);
      Result := Length(TPA);
      {$IFDEF DEBUG} DebugMM(TPA); {$ENDIF}
    End;


    Function AdeptDegree(CompassAngle: Extended; Degree: Integer): Integer;         //idem dito, but I like it

    Begin
      Result := Round(Abs(CompassAngle + Degree));
      While Result > 360 Do
        Result := Result - 360;
    End;

    function AmountOfGaps(ar : TBoolArray) : integer;                               //Better name: amount of transitions
    var
      prevone : boolean;
      i : integer;
    begin
      prevone := ar[0];
      result := 0;
      for i := 1 to high(ar) do
      begin
        if ar[i] <> prevone then
          inc(result);
        prevone := ar[i];
      end;
      result := result;
    end;

    procedure StartStopGap(ar : tbooleanarray; var start, stop : integer);          //Not used.
    var                                                                             //could (in theory) be used for quadrant detection
      prevone : boolean;
      i : integer;
    begin
      prevone := ar[0];
      for i := 1 to high(ar) do
      begin
        if ar[i] <> prevone then
        begin
          start := i;
          prevone := ar[i];
          break;
        end;
      end;
      for i := i to high(ar) do
      begin
        if ar[i] <> prevone then
        begin
          stop := i;
          prevone := ar[i];
          break;
        end;
      end;
    end;

    procedure WalkToMiddleRoom;                                                     //No checks, nothing. Just plain clickin'
    var
      TPA : TPointArray;
      p : TPoint;
    begin
      ColorToleranceSpeed(2);                                                       //ACA obviously
      SetColorSpeed2Modifiers(1.46, 0.39);                                          //dark grey colour in the mine
      FindColorsTolerance(tpa, 10461335, MMX1, MMY1, MMX2, MMY2, 7)
      ColorToleranceSpeed(1);
      SetColorspeed2Modifiers(0.2, 0.2);
      p := MiddleTPA(tpa); //should do
      Mouse(p.x, p.y, 4, 4, true);
      wait(500);
      //FFlag(0);
      MFlag;
      Wait(500);
    end;

    function FindEss : Boolean; //ACA love
    var
      arP : TPointArray;
      ararP: T2DPointArray;
      arL, i : Integer;
      P: TPoint;
    //  fx, fy : integer;
    begin
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.08, 0.17);

      if not(FindColorsTolerance(arP, 8618897, MSX1, MSY1, MSX2, MSY2, 29)) then
      begin
        Writeln('Failed to find the color, no object found.');
        ColorToleranceSpeed(1);                                                     //no need to store cts, 1 is always good
        SetColorSpeed2Modifiers(0.2, 0.2);
        Exit;
      end;

      ararP := SplitTPAEx(arP, 3, 3);                                               //SLLOOOOWWWW, as there are LOTS of points
      arL := Min(4, High(ararP));                                                   //and 5 is already a lot, it should find it in 1 try

      SortATPASize(ararP, true);                                                    //hey, I did this line of code myself, not ACA

      for i := 0 to arL do
      begin
        if (Length(ararP[i]) < 10) then Continue;
        P := MiddleTPA(ararP[i]);
        MMouse(P.x, P.y, 5, 5);
        Wait(100 + Random(100));
        if (IsUpTextMultiCustom(['ine', 'ure', 'ssen'])) then
        begin;
          Result := True;
          ClickMouse2(True); //mine it!
          Break;
        end;
      end;

      ColorToleranceSpeed(1);
      SetColorSpeed2Modifiers(0.2, 0.2);

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

    end;

    function LocateInsideEssMine : boolean;                                         //returns true if @ mine
    var                                                                             //VERY BAD CODING PRACTICE INSIDE!!!!
      BlackArr : array [mmx1..mmx2] of array [mmy1..mmy2] of boolean;
      Angles : array[0..359] of boolean;
      i : integer;
      radius, angle : integer;
      tpa : TPointArray;
    //  p : TPoint;
      x, y : integer;
      aFound : extended;
    begin
      //setupsrl;
      ColorToleranceSpeed(0);
      FindColorsTolerance(tpa, 0, mmx1, mmy1, mmx2, mmy2, 7);                       //Find all the black!
      ColorToleranceSpeed(1);

      for i := 0 to high(tpa) do
        BlackArr[tpa[i].x][tpa[i].y] := True;

      for radius := 74 downto 50 do                                                 //Minimap is 75 radius. 50 was determined experimentally
        for angle := 0 to 359 do
        begin
          x :=  round(Cose(angle-90)*radius+mmcx);                                  //cose and sine use lookup tables, so pretty quick
          y :=  round(Sine(angle-90)*radius+mmcy);
          if (BlackArr[x][y]) then                                                  //Reason for using if, we don't want to set it to false, only to true
            Angles[angle] := True;
        end;

      writeln(AmountOfGaps(angles));


      if(AmountOfGaps(angles) > 4) then                                             //Only then can it really be middle..
      begin
        writeln('We are standing in the middle');
        if (not(FindDTMRotated(MiddleDTM1, x, y, MMX1, MMY1, MMX2, MMY2, -Pi, Pi, Pi/360, aFound))) then  //Look what I did here
          if (not(FindDTMRotated(MiddleDTM2, x, y, MMX1, MMY1, MMX2, MMY2, -Pi, Pi, Pi/360, aFound))) then
          begin
            writeln('Force-walking to the middle of room..');
            WalkToMiddleRoom;
            if FindSymbol(x, y, 'transportation') then
            begin
              writeln('We weren''t in the middle indeed');
              //WalkToMiddleRoom;
              writeln('should be in middle of mine now');
              if (not(FindEss)) then
              begin
                NoEssFound := True;
                WriteLn('No Essence Fake Middle');
              end else
                Result := True;                                                     //best thing is, wizzup's code doesnt even use this result
              exit;
            end;
            writeln('Location detection failed! No middle and no DTMs');
            Players[0].Loc := 'NoMine';
            result := False;
            exit;
          end; //else
          writeln('We are standing at quadrant: '+inttostr(((Trunc(FixD(ArcTan2(y - mmcy, x - mmcx) * 180.0 / pi) / 90.0))+3)mod 4));  //thanks to mixster
          x := Round(Cose((((Trunc(FixD(ArcTan2(y - mmcy, x - mmcx) * 180.0 / pi) / 90.0))+2)mod 4)*90+RandomRange(40,50))*randomrange(48,53))+mmcx; //this will randomize like wtf xd
          y := Round(Sine((((Trunc(FixD(ArcTan2(y - mmcy, x - mmcx) * 180.0 / pi) / 90.0))+2)mod 4)*90+RandomRange(40,50))*randomrange(48,53))+mmcy; //x and y are both randomly generated
          Mouse(X, Y, 4, 4, True); //random random random
          Wait(2000);
          //FFlag(0);
          MFlag;
          Wait(500);
          if(not(FindEss)) then  //Does at most 5 "wacky" movements, low cost to pay compared to clicking minimap and waiting 5 seconds
          begin
            WalkToMiddleRoom; //Usu
            //Wait(Randomize(750, 250)); //should work with this, too
            if (not(FindEss)) then
            begin
              NoEssFound := True;
              WriteLn('No Essence');
              //NoEssenceFound := True;
            end;
          end;
      end else
      //  if(AmountOfGaps(angles) = 2) then
      begin
        writeln('We are standing in a room');
        writeln('Fortunately we can walk to the middle.');
        WalkToMiddleRoom;
        writeln('should be in middle of mine now');
            if (not(FindEss)) then
            begin
              NoEssFound := True;
              WriteLn('No Essence Corner');
            end;
        {writeln('We can now determine exct loc')     //Useless. Essmine rotates so we should not rely on that
        StartStopGap(angles, start, stop);
        writeln('START: '+inttostr(start)+', STOP: '+inttostr(stop));
        writeln('Location: '+locationnames[(start+stop) div 180]);}

      end
    end;

    Function EssenceCount: Integer;

    {Var
       I: Integer;
       TPA: TPointArray;
       B: TBox; }


    Begin
     { Result := 0;
      For I := 1 To 28 Do
      Begin
        B := InvBox(I);
        FindColorsTolerance(TPA, 65536, B.X1, B.Y1, B.X2, B.Y2, 0);
        If Length(TPA) = 82 Then //doesnt work anymore
          Result := Result + 1;
      End;    }

      result := InvCount; //Too bad if your pickaxe isnt equipped
    End;

    Procedure Bank;

    Var
       I: Integer;
       P: TPoint;
       A: Extended;
       TempEss: Integer;

    Begin
      //ReportVars[1] := ReportVars[1] + 1; // Banks
      Players[CurrentPlayer].Banked := Players[CurrentPlayer].Banked + 1;
      For I := 0 To 2 Do
        If OpenBankFast('veb') Then
          Break
        Else
          If FindBankers(P, A) Then
          Begin
            Mouse(p.x, p.y, 0, 0, True);
            Wait(4000);
            //FFlag(0);
            MFlag;
            Wait(1500);
          End;
      If Not BankScreen Or PinScreen Then
      Begin
        LogOut;
        Players[CurrentPlayer].Loc := 'NoBank';
        Players[CurrentPlayer].Active := False;
        Exit;
      End;
      TempEss := EssenceCount;
      EssenceMined := EssenceMined + TempEss;
      //ReportVars[0] := ReportVars[0] + TempEss;
      Players[CurrentPlayer].Integers[0] := Players[CurrentPlayer].Integers[0] + TempEss;
      If Players[CurrentPlayer].Booleans[0] Then
        Deposit(1, 28, True)
      Else
        Deposit(2, 28, True);  //blindly assumes it is in spot 1

      if (random(3) = 1) then //no need to close it all the time Wiz
        CloseBank;
    End;

    Procedure PlayerReport;

    Var
      Active, Rand: string;
      I: Integer;

    Begin
      For I := 0 To High(Players) Do
      Begin
        If Players[i].Active Then
          Active := 'T'
        Else
          Active := 'F';
        If Players[i].Rand <> '' Then
          Rand := '; Rand: ' + Players[i].Rand
        Else
          Rand := '';

        WriteLn((IntToStr(I)) + ' : ' + Players[I].Nick + ' = ' +
         Active + '; ' + Players[I].Loc  + rand + '; B: ' + IntToStr(Players[I].Integers[0])
         + ' Essence;'+ ' M : ' + IntToStr(Players[I].Level[15]));
      End;
    End;

    Procedure ProgressReport;

    Begin
      WriteLn('----------------------------');
      WriteLn('');
      WriteLn('Wizzup? and Markus Essence Miner, Version ' + VersionNumber);
      WriteLn('');
      WriteLn('Worked for '+ TimeRunning);
      WriteLn('Mined ' + IntToStr(EssenceMined) + ' Essence');
      If Abyss > 0 Then WriteLn('Solved ' + IntToStr(Abyss) + ' abyssal random events.');//and it will never solve them cause the solver was removed ^-^
      WriteLn('');
      WriteLn('----------------------------');
      WriteLn('');
      PlayerReport;
      WriteLn('');
      WriteLn('----------------------------');
      SRLRandomsReport;
    End;

    Procedure ScriptTerminate;

    Begin
      ProgressReport;
    End;

    Function GetAndSetAnyReferenceColor: Boolean;                                   //if I could get black here, I'd do it.

    //Var
      // c: integer;

    Begin
      NewAutoColorWorked := False;
      result := False;
      Exit;
      {
      c := AutoColor(srl_RockColor);
      If c > 0 Then
      Begin
        SetAutoColorReference('grey rock', c);
        WriteLn('Got the color using the grey rock');
        NewAutoColorWorked := True;
        Result := True;
        Exit;
      End;     }

    End;

    Procedure InitPlayer;
       {
    Var
       I: Integer; }

    Begin
      {For I := 1 To 5 Do
      If Not Players[CurrentPlayer].Booleans[I] Then
      Begin
        Case I Of
          1: SetGraphics(4, '', '' ,'', '', '', '', '', '');
          2: Retaliate(False);
          3: SetAudio(0, 0, 0, Mono);
        End;
        Players[CurrentPlayer].Booleans[I] := True;
      End;}


      GetAllLevels;
      SetChat('on',1);
      SetChat('friends',2);
      SetChat('on',3);
      SetAngle(SRL_ANGLE_HIGH);
    End;

    Procedure SetupScript;

    //Var
    //   I: Integer;
    Begin
     // SRLID := SRL_ID;
      //SRLPassword := SRL_PASS;
    //  For I := 1 To 19 Do
    //    ReportVars[I] := 0;
      //ScriptID := '51';
      DeclarePlayers;
      LoginPlayer;
      InitPlayer;

      //BlackOffset := -1;

      //Thanks to Demise for restoring my faith in DTMs :)
      MiddleDTM1 := DTMFromString('mlwAAAHicY2dgYChhYmCIBuIMIK4B4g4gjgHiOiAOAcr7A7'+
      'ELEFsBcTIQxwGxFxD///+fwVyNAwW7aAkyfH79kWECIwMDPwN2zIgHQwEAMRYOKA==');
      MiddleDTM2 := DTMFromString('mggAAAHicY2NgYKhiYmAoAOIGIG4H4glAnAPE4UA5JyB2BW'+
      'IfIM4G4kwgfvTmHYO9gTCDkQ4XGG/Zuw/Mn8DIwMDPgIkZcWAIAAAOAAyf');

      {DTMAuburyMap := DTMFromString('mwQAAAHic42RgYNBlZGBQA2I9IJYF4v9AMWEgHQzEBkCs'+  //Thanks Demise, for this one
      'AcS3gWIHofg6ED9kgKh7DMRcQPlNQDop1IwhxpgbjP1ddRg8HQ0YnKxUGb4zMjFEhIcx/P/PySA'+
      'JVEcIMxGB4QAAolMSVg==');}


      DTMAuburyDoor := DTMFromString('mAAEAAHic42FgYDAGYnkodoVikJgClG0CxEZAHM8AAfx'+  //Thanks Demise, love you!
      'AzAvEAlA2NxBLA7EMEEsBsSZUHcg8USDOjrFgyIoxZyhIsGTIjDJlSI0wZciIMmPIibNkiAs0ZN'+
      'DVVGII8dBh0NYRZ6gNlgObSQpmBGImIjAbFCMDAJFbDpI=');

      SetDTMName(MiddleDTM1, 'Middle DTM 1');
      SetDTMName(MiddleDTM2, 'Middle DTM 2');
      SetDTMName(DTMAuburyDoor, 'Aubury door DTM');
    End;

    Var
      T, T2, I:integer;

    begin
      //Smartsetup(SmartPrefix, true, true, false);
      //Settargetdc(smartgetdc);
      AubTPA := CreateTPAFromText('isthin', UpCharsEx);
      Smart_Server := 52;
      Smart_Signed := True;
      Smart_SuperDetail := False;
      SetupSRL;
      SetupScript;
      //LoadLocations;
      //SetupNewAutoColor;
      GetAndSetAnyReferenceColor;
      Repeat

        If Players[CurrentPlayer].Loc = 'Bank' Then
          BankToAubury;

        If Players[CurrentPlayer].Loc = 'Aubury' Then
        Begin
          T2 := GetSystemTime;
          While Not AtMine Do
          Begin
            If GetSystemTime - T2 > 180000 Then
            Begin
              Players[CurrentPlayer].Loc := 'NoAubury';
              Break;
            End;
            //DoorClosed; //ffs, walk to the right place first ;)
            If FindAubury Then
            Begin
              T := GetSystemTime;
              While (Not AtMine) and (GetSystemTime - t < 10000) Do Wait(250);
              If AtMine Then
                Break;
            End;
            Wait(500);
          End;
          Players[CurrentPlayer].Loc := 'Mine';
        End;

        If Players[CurrentPlayer].Loc = 'Mine' Then
        Begin
          Wait(500);
          If InAbyss Then
            SolveAbyss;

          LocateInsideEssMine;
          T := GetSystemTime;
          T2 := GetSystemTime;
          While (GetSystemTime - T < 180000) And (InvCount < 28) Do
          Begin
            If NoEssFound Then
            Begin
              WriteLn('We did not find any essence...');
              NoEssFound := NoEssFound xor NoEssFound; //wizzup's way of saying = false;
              Break;
            End;
            If GetSystemTime - T2 > 60000 Then
            Begin
              I := Random(14) + 21;
              If I = tab_Inv Then I := tab_Stats;
              GameTab(I);
              Wait(RandomRange(200, 4000));
              GameTab(tab_Inv);
              T2 := GetSystemTime;
            End;

            Wait(1000);
            If LevelUp Then
            Begin
              WriteLn('You levelled up, congratulations!'); //Wizzup? wasn't nice here, but I am
              Break;
            End;
            If FindNormalRandoms Then
            Begin
              T := GetSystemTime;
              While GetSystemTime - T < 5000 Do
              Begin
                Wait(250);
                FindNormalRandoms;
              End;
            End;
          End;
          MineToAubury;
          AuburyToBank;
          Bank;
        End;

        ProgressReport;

        If Not LoggedIn Then
        Begin
          NextPlayer(False);
          InitPlayer;
          Continue;
        End;

        If Players[CurrentPlayer].Banked Mod Loads = 0 Then
        Begin
          NextPlayer(True);
          InitPlayer;
          Continue;
        End;

      Until False;
    End.

  23. #48
    Join Date
    Feb 2012
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Doesn't work..

    Code:
    Could NOT open door!
    Found Aubury store using offset DDTM!
    Found Aubury store using offset DDTM!
    Distance to store is close.
    Opening door!
    Could NOT open door!
    Found Aubury store using offset DDTM!
    Found Aubury store using offset DDTM!
    Distance to store is close.
    Opening door!
    Could NOT open door!
    Found Aubury store using offset DDTM!
    Found Aubury store using offset DDTM!
    Distance too big. Falling back to magic symbol!
    No idea what's going on now, flag is weird but distance to store..
    Opening door!
    Found Aubury store using offset DDTM!
    Distance too big. Falling back to magic symbol!
    Out of shop
    No Bank

  24. #49
    Join Date
    Dec 2011
    Location
    Sydney
    Posts
    1,284
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Currently 67k/hr for pure ess .

  25. #50
    Join Date
    Feb 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    How do I run this script??, I downloaded the script and hit run but where do I put my login option so that it can login by itself?? I tried to login by myself but the script don't seem to want to start. please help

    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
    Last edited by Angecide; 02-17-2012 at 10:43 AM.

Page 2 of 8 FirstFirst 1234 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •