Results 1 to 22 of 22

Thread: How to choose closest ATPA / tpa?

  1. #1
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default How to choose closest ATPA / tpa?

    How?


    Code:
     
     
      Function Findiron:boolean;
    var
      ironTPA, WoodTPA:TPointArray;
      ironATPA:T2DPointArray;
      ironBox:TBox;
      i, r, counter:integer;
    begin
     if not(loggedin) then
        exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.23, 0.83);
      if findcolorstolerance(ironTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
        begin
    
          SortATPASize(ironATPA, True);
          for i := 0 to high(ironATPA) do
            begin
              ironBox := GetTPABounds(ironATPA[i]);
              SetColorSpeed2Modifiers(0.04, 0.28);
              if findcolorstolerance(ironTPA, 4609378, ironBox.x1, ironbox.Y1, ironbox.X2, ironbox.Y2, 15) then
                Break;
              if i = high(ironATPA) then
                begin
                  writeln('Colours not finding!');
                  Terminatescript;
                end;
            end;
          SetColorToleranceSpeed(1);
          SetColorSpeed2Modifiers(0.02, 0.02);
          marktime(counter);
          while (not isuptextmulticustom(['ron','iron'])) do
            begin
              r := random(length(ironTPA));
              mmouse(ironTPA[r].x, ironTPA[r].y, 3, 3);
              wait(randomrange(200, 500));
              if timefrommark(counter) > 5000 then
                begin
                  writeln('No Uptext Found');
                  Logout;
                  Terminatescript;
                end;
            end;
          clickmouse2(mouse_right);
      if ChooseOption('em') then
        begin
          Writeln('Mining...');
        end;
        end;
    end;
    Last edited by Peanuts; 05-28-2013 at 02:45 PM.

  2. #2
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    I think you are right.. But i need a lil more explanation.. Can't seem to find info on it. Or i suck at google.

  3. #3
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    you can use:

    Code:
    SortATPAFromMidPoint(yourATPA, yourTPoint)
    and then the closest TPA to yourTPoint will be yourATPA[0]

  4. #4
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    you can use:

    Code:
    SortATPAFromMidPoint(yourATPA, yourTPoint)
    and then the closest TPA to yourTPoint will be yourATPA[0]
    Thanks..
    Makes sense. I think.

    I'm just confused on what i put into the 'yourTpoint' part..
    Which t point.. like.. erg..

  5. #5
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    Thanks..
    Makes sense. I think.

    I'm just confused on what i put into the 'yourTpoint' part..
    Which t point.. like.. erg..
    it the point that you want to get the closest TPA to ...

    eg.

    i want to find the closest TPA to a rock, yourTPoint would therefore be the TPoint that is the rocks location. you then sort yourATPA from the rock (yourTPoint) and the first index will be the closest TPA in yourATPA to the rock.

  6. #6
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Like this?

    Simba Code:
    SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

    That sorts from the middle of the mainscreen

  7. #7
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    it the point that you want to get the closest TPA to ...

    eg.

    i want to find the closest TPA to a rock, yourTPoint would therefore be the TPoint that is the rocks location. you then sort yourATPA from the rock (yourTPoint) and the first index will be the closest TPA in yourATPA to the rock.
    Like this?

    Simba Code:
    SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

    That sorts from the middle of the mainscreen
    Thanks lads!

    EDIT: Sorry... but.. I put that in my script and its still picking random rocks.. :|
    My first script is almost complete !
    Last edited by Peanuts; 05-28-2013 at 03:05 PM.

  8. #8
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Bump. Not sure if edited response was seen.

    Heres the code

    Code:
     begin
    
          SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));
          for i := 0 to high(GemATPA) do
            begin
              GemBox := GetTPABounds(GemATPA[i]);
              SetColorSpeed2Modifiers(0.04, 0.28);
              if findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15) then
                Break;
              if i = high(GemATPA) then
                begin
                  writeln('We went through all TPA''s and found no brown! Check your CTS2 Work!');
                  Terminatescript;
                end;
            end;
          SetColorToleranceSpeed(1);
          SetColorSpeed2Modifiers(0.02, 0.02);
          marktime(counter);
          while (not isuptextmulticustom(['em','asd'])) do
    Last edited by Peanuts; 05-28-2013 at 03:23 PM.

  9. #9
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    what do you mean picking random rocks?

  10. #10
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    Thanks lads!

    EDIT: Sorry... but.. I put that in my script and its still picking random rocks.. :|
    My first script is almost complete !
    Can you debug the atpa?

    smart_debugATPA(true, ATPA);

  11. #11
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    what do you mean picking random rocks?
    I want to pick the rock closest to me, like a human would.

    Quote Originally Posted by Officer Barbrady View Post
    Can you debug the atpa?

    smart_debugATPA(true, ATPA);
    I put that in.. is something supposed to happen im meant to paste to you?

  12. #12
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    I want to pick the rock closest to me, like a human would.
    yes i get that, but what do you mean by random?

    because from what i can see, the ATPA is sorted and then you are iterating through to find whatever color you're looking for, and that seems fine. how do you find the initial ATPA?

  13. #13
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    I want to pick the rock closest to me, like a human would.



    I put that in.. is something supposed to happen im meant to paste to you?
    Yes, it is supposed to show the found ATPA's on the screen, if it does not then your colors are probably bad

  14. #14
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Just a rough snippet, but should be solid for you.
    Simba Code:
    tempCTS := GetColorToleranceSpeed; //save CTS so we can reset it
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(hue, sat);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, color, MSX1, MSY1, MSX2, MSY2A, tol);
      SetColorSpeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(tempCTS);
      ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
      SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.

  15. #15
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    yes i get that, but what do you mean by random?

    because from what i can see, the ATPA is sorted and then you are iterating through to find whatever color you're looking for, and that seems fine. how do you find the initial ATPA?
    By random i mean.. It will sometimes click the furthest away rock instead of the one next to me. (Which is what i want)
    I'm so confused.. Perhaps i should read more tutorials.


    Quote Originally Posted by Officer Barbrady View Post
    Yes, it is supposed to show the found ATPA's on the screen, if it does not then your colors are probably bad
    It never has an issue finding the colors.. I tested it alone over n over.. n it seemed flawless.

    I think perhaps I did something else wrong?



    Quote Originally Posted by Kevin View Post
    Just a rough snippet, but should be solid for you.
    Simba Code:
    tempCTS := GetColorToleranceSpeed; //save CTS so we can reset it
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(hue, sat);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, color, MSX1, MSY1, MSX2, MSY2A, tol);
      SetColorSpeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(tempCTS);
      ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
      SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.
    I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
    which appears to have different vars
    Should i change to findspiral like in your example?
    Will that do the trick?

  16. #16
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
    which appears to have different vars
    Should i change to findspiral like in your example?
    Will that do the trick?
    That's the easiest approach

    or u use this by flight: http://villavu.com/forum/showthread....97#post1232797

    Creds to DannyRS for this wonderful sig!

  17. #17
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    By random i mean.. It will sometimes click the furthest away rock instead of the one next to me. (Which is what i want)
    I'm so confused.. Perhaps i should read more tutorials.

    It never has an issue finding the colors.. I tested it alone over n over.. n it seemed flawless.

    I think perhaps I did something else wrong?




    I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
    which appears to have different vars
    Should i change to findspiral like in your example?
    Will that do the trick?
    Changing to findspiral shouldn't be nearly as big a deal for what you want as this portion:
    Simba Code:
    ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
      SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.
    That will be where the ATPA is created (the separated rocks) as well as the actual sorting of them so the first object in the array will be the closest rock to you.

  18. #18
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    Changing to findspiral shouldn't be nearly as big a deal for what you want as this portion:
    Simba Code:
    ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
      SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.
    That will be where the ATPA is created (the separated rocks) as well as the actual sorting of them so the first object in the array will be the closest rock to you.
    When I put that in...

    Code:
      if findcolorstolerance(GemTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
        begin
          GemATPA:= SplitTPA(GemTPA, 5);//This creates the array of tpas.
          SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));
    
          for i := 0 to high(GemATPA) do
            begin
              GemBox := GetTPABounds(GemATPA[i]);
              SetColorSpeed2Modif
    I get - Error: Out Of Range at line 235.

    Code:
            begin
              r := random(length(GemTPA));
              mmouse(GemTPA[r].x, GemTPA[r].y, 3, 3);   -----235
              wait(randomrange(400, 600));
              if timefrommark(counter) > 5000 then
                begin
    Its to do with the random/[r] thing?
    Last edited by Peanuts; 05-28-2013 at 06:38 PM.

  19. #19
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    ok from your first post this is the code that i go:

    Simba Code:
    Function Findiron:boolean;
    var
      ironTPA: TPointArray;
      ironATPA: T2DPointArray;
      ironBox: TBox;
      i: integer;
    begin
      Result := false;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.23, 0.83);
      if findcolorstolerance(ironTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then              // search for color store in ironTPA
      begin
        ironATPA:= SplitTPAEx(ironTPA, 5, 5);                                                // split ironTPA into 5x5's
        SortATPAFromMidpoint(ironATPA, Point(MSCX, MSCY));                                   // sort ironATPA from the centre of MS

        for i := 0 to high(ironATPA) do                                                      // iterate through ironATPA and check
        begin
          ironBox := GetTPABounds(ironATPA[i]);
          SetColorSpeed2Modifiers(0.04, 0.28);                                               // for ore color within the rock
          if findcolorstolerance(ironTPA, 4609378, ironBox.x1, ironbox.Y1, ironbox.X2, ironbox.Y2, 15) then
          begin
            //do whatever you need to do here for example:
            MMouse((ironBox.x1 + ironBox.x2) /2, (ironBox.y1 + ironBox.y2) /2, 5, 5);        // if or found then move mouse to centre of rock
            if IsUpTextEx('ron') then                                                        // if the uptext is 'ron'
            begin                                                                            // then left click to mine and then break
              clickMouse2(true);                                                             // out of for loop
              Result = true;
              Break;
            end;
          end;
          if i = high(ironATPA) then                                                         // if you get to the end of ironATPA and
          begin                                                                              // have found no ores then terminate
            writeln('No rocks that can be mined found, terminating ...');
            Terminatescript;
          end;
        end;
      end;
      SetColorToleranceSpeed(1);                                                             // reset toleranceSpeed and modifiers at the
      SetColorSpeed2Modifiers(0.02, 0.02);                                                   // end of your procedure/function
    end;

    the looks a lot messier on here :/ the comments were on the right hand side and it looked all prettyful

    EDIT: why if you have just found the index of the rock closest that you can mine, have you then gone and used random to get an index to move the mouse to?

    and i believe that by using
    Code:
     r := random(length(GemTPA));
    r can equal length(GemTPA) which is out of bounds, you should use length(GemTPA)-1
    EDIT2: or actually, just dont do that.
    Last edited by EngageTheRage; 05-29-2013 at 11:26 PM.

  20. #20
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    ok from your first post this is the code that i go:

    the looks a lot messier on here :/ the comments were on the right hand side and it looked all prettyful

    EDIT: why if you have just found the index of the rock closest that you can mine, have you then gone and used random to get an index to move the mouse to?

    and i believe that by using
    Code:
     r := random(length(GemTPA));
    r can equal length(GemTPA) which is out of bounds, you should use length(GemTPA)-1
    EDIT2: or actually, just dont do that.
    okay. Copy pasted into simba n i can read it a bit easier now.. Giving it a go.

  21. #21
    Join Date
    Mar 2008
    Posts
    426
    Mentioned
    1 Post(s)
    Quoted
    116 Post(s)

    Default

    Quote Originally Posted by EngageTheRage View Post
    ok from your first post this is the code that i go:
    ARGHH...


    Why does it still not choose the closest.. I'm guessing im missing some tiny thing -.-


    Code:
    unction FindGems:boolean;
    var
      GemTPA, WoodTPA:TPointArray;
      GemATPA:T2DPointArray;
      GemBox:TBox;
      i : integer;
    begin
      Result := False
        if not(loggedin) then
          exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.23, 0.83);
    
        if findcolorstolerance(GemTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
          begin
            GemATPA:= SplitTPAeX(GemTPA, 5, 5);
            SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));
              for i := 0 to high(GemATPA) do
                begin
                  GemBox := GetTPABounds(GemATPA[i]);
                  SetColorSpeed2Modifiers(0.04, 0.28);
                    if findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15) then
                      Break;
                end;
            SetColorToleranceSpeed(1);
            SetColorSpeed2Modifiers(0.02, 0.02);
              while (not isuptextmulticustom(['em','asd'])) do
                begin
                  mmouse((gemBox.x1 + gemBox.x2) /2, (gemBox.y1 + gemBox.y2) /2, 5, 5);
                  wait(randomrange(400, 600));
                  ClickMouse2(false);
                    if ChooseOption('em') then
                      result := true;
                end;
          end;
    end;
    P.S - It seems to be starting from the left side, maybe left bottom corner. Always picks there first
    Last edited by Peanuts; 05-28-2013 at 07:35 PM.

  22. #22
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    Quote Originally Posted by Peanuts View Post
    ARGHH...


    Why does it still not choose the closest.. I'm guessing im missing some tiny thing -.-

    P.S - It seems to be starting from the left side, maybe left bottom corner. Always picks there first
    first off, that last part doesnt seem great,

    Code:
    while (not isuptextmulticustom(['em','asd'])) do
                begin
                  mmouse((gemBox.x1 + gemBox.x2) /2, (gemBox.y1 + gemBox.y2) /2, 5, 5);
                  wait(randomrange(400, 600));
                  ClickMouse2(false);
                    if ChooseOption('em') then
                      result := true;
                end;
    seems destined to continue for eternity ...

    use

    Code:
    SMART_Debug(GemATPA);
    before your for loop to check out what the ATPA looks like after its sorted, then in your for loop, use:

    Code:
    SMART_DrawBoxEx(true, GemBox, 255);
    to show you which box it is on. you might have to add a few wait(1000); just so you can see whats going on.

    by doing that you will see it iterate through and see the order in which it checks the rocks, and the one on which it breaks.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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