Results 1 to 17 of 17

Thread: Help with ATPA please

  1. #1
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Help with ATPA please

    So, I've been all day coding a simple rock finder using ATPA, should be done in 10 minutes or less but instead is error after error when everything seems correct.

    It compiles fine but the behave it has is very different.

    I defined the TPA and the ATPA, created a MS region for the findcolorstolerance, divided even in that space in small boxes 10 w 10 h and used splitTPAEx.

    What it does is loop through the ATPA as if nothing was found and just loops and loops even with a break there.

    I know it's hard to but please, try to ignore the messy standards. ( Doesn't do the proper standards in a QUOTE statement)

    I leave here the parts that are giving me trouble:

    Function FindTin: Boolean;
    var
    tmpCTS, i, x, y: Integer;
    RockTPA: TPointArray;
    RockATPA: T2DPointArray;

    begin


    tmpCTS := GetToleranceSpeed;
    SetColorToleranceSpeed(2);
    SetToleranceSpeed2Modifiers(0.06,0.87);

    FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19)

    SetColorToleranceSpeed(tmpCTS);
    SetToleranceSpeed2Modifiers(0.02,0.02);

    RockATPA := SplitTPAEx(RockTPA, 10, 10);
    SortATPASize(RockATPA, True);

    for i :=0 to high(RockATPA) do
    begin
    MiddleTPAEx(RockATPA[i],x,y);
    MMouse(x, y, 5, 5);
    if WaitUptext('ocks', 400)then
    begin
    Result := True;
    Exit;
    end;
    end;
    end;

    Procedure MineTin;

    begin
    if FindTin then
    begin
    case random(100) of

    0..75:begin
    wait(RandomRange(50,150));
    FastClick(mouse_left);
    repeat
    wait(1000 + random(100));
    until not PlayerIsMining;
    end;
    76..100:begin
    wait(RandomRange(50,150));
    FastClick(mouse_right);
    wait(100+Random(100));
    ChooseOption('Tin');
    repeat
    wait(1000 + random(100));
    until not PlayerIsMining;
    end;
    end;
    end;
    end;
    Last edited by Slashed; 12-15-2012 at 02:05 AM.

  2. #2
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    Use MSX1, MSY1, MSX2, MSY2 instead of the hand-picked coordinates you have. I think you didn't set the client before grabbing the coordinates, so they're all off, making the object never found.

  3. #3
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, I forgot to mention that I restricted that because it was doing the same thing. Before, I had MSX1,MSY1, MSX2, MSY2 in the FindColorsTolerance and it still did the same thing. So I guess it's not from that.

    Any idea mate? Thanks for the reply

  4. #4
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Try looking for isup "mine" "ine" not rocks?

    Dont think it looks that far for text

    That first repeat wait until notmining, looks a bit sketchy, if thats not working, theres no way to break?
    Last edited by DannyRS; 12-15-2012 at 02:23 AM.


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  5. #5
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by DannyRS View Post
    Try looking for isup "mine" "ine" not rocks?

    Dont think it looks that far for text
    Nope, still doesn't work

  6. #6
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Quote Originally Posted by Slashed View Post
    Nope, still doesn't work
    Just call the TPA, not any of the other loop, and add this to just after the size sort

    Simba Code:
    DebugATPABounds(ATPA);

    Will print out the ATPA on screen


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  7. #7
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    What is PlayerIsMining?

    I see nothing wrong with it.. I fixed the standards and added a length check :l

    Simba Code:
    function FindTin: Boolean;
    var
      tmpCTS, i, x, y: Integer;
      RockTPA: TPointArray;
      RockATPA: T2DPointArray;
    begin
      tmpCTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.06, 0.87);
      FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
      SetColorToleranceSpeed(tmpCTS);
      SetToleranceSpeed2Modifiers(0.02, 0.02);

      If (Length(RockTPA) < 1) Then Exit;

      RockATPA := SplitTPAEx(RockTPA, 10, 10);
      SortATPASize(RockATPA, True);

      for i := 0 to high(RockATPA) do
      begin
        MiddleTPAEx(RockATPA[i], x, y);
        MMouse(x, y, 5, 5);
        if WaitUptext('ock', 600) then
        begin
          Result := True;
          Exit;
        end;
      end;
    end;

    procedure MineTin;
    begin
      if FindTin then
      begin
        case random(100) of
          0..75:
            begin
              wait(RandomRange(50, 150));
              FastClick(mouse_left);
              repeat
                wait(1000 + random(100));
              until not PlayerIsMining;
            end;
          76..100:
            begin
              wait(RandomRange(50, 150));
              FastClick(mouse_right);
              wait(100 + Random(100));
              ChooseOption('Tin');
              repeat
                wait(1000 + random(100));
              until not PlayerIsMining;
            end;
        end;
      end;
    end;
    I am Ggzz..
    Hackintosher

  8. #8
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    What is PlayerIsMining?

    I see nothing wrong with it.. I fixed the standards and added a length check :l

    Simba Code:
    function FindTin: Boolean;
    var
      tmpCTS, i, x, y: Integer;
      RockTPA: TPointArray;
      RockATPA: T2DPointArray;
    begin
      tmpCTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.06, 0.87);
      FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
      SetColorToleranceSpeed(tmpCTS);
      SetToleranceSpeed2Modifiers(0.02, 0.02);

      If (Length(RockTPA) < 1) Then Exit;

      RockATPA := SplitTPAEx(RockTPA, 10, 10);
      SortATPASize(RockATPA, True);

      for i := 0 to high(RockATPA) do
      begin
        MiddleTPAEx(RockATPA[i], x, y);
        MMouse(x, y, 5, 5);
        if WaitUptext('ock', 600) then
        begin
          Result := True;
          Exit;
        end;
      end;
    end;

    procedure MineTin;
    begin
      if FindTin then
      begin
        case random(100) of
          0..75:
            begin
              wait(RandomRange(50, 150));
              FastClick(mouse_left);
              repeat
                wait(1000 + random(100));
              until not PlayerIsMining;
            end;
          76..100:
            begin
              wait(RandomRange(50, 150));
              FastClick(mouse_right);
              wait(100 + Random(100));
              ChooseOption('Tin');
              repeat
                wait(1000 + random(100));
              until not PlayerIsMining;
            end;
        end;
      end;
    end;
    PlayerIsMining is an AveragePixelShift check.

    Simba Code:
    //Thanks to Flight for the pixelshift Tutorial
    Function PlayerIsMining: Boolean;
      var
        playerBox: TBox;
      begin
        PlayerBox := IntToBox(245, 130, 285, 195);
        Result := (AveragePixelShift(playerBox, 250, 500) > 400);
      end;

    Looking now with other eyes, it seems the problem may be on the definition of the result. Any ideas?
    Last edited by Slashed; 12-15-2012 at 02:45 AM.

  9. #9
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Quote Originally Posted by Slashed View Post
    PlayerIsMining is an AveragePixelShift check.
    That should be a function : boolean returning true\false if the AveragePixelShift is reached

    Forum account issues? Please send me a PM

  10. #10
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Slashed View Post
    PlayerIsMining is an AveragePixelShift check.

    Simba Code:
    //Thanks to Flight for the pixelshift Tutorial
    Function PlayerIsMining: Boolean;
      var
        playerBox: TBox;
      begin
        PlayerBox := IntToBox(245, 130, 285, 195);
        Result := (AveragePixelShift(playerBox, 250, 500) > 400);
      end;

    Looking now with other eyes, it seems the problem may be on the definition of the result. Any ideas?
    Looks about right.. Where did you get FastClick from? I see no such function in Simba's includes :l

    Change fast click to something like:

    ClickMouse2(MOUSE_LEFT);

    Also your animation function might be giving false positives. Run it in a test loop and see if it detects you mining all the time or not.
    I am Ggzz..
    Hackintosher

  11. #11
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by [J]ustin View Post
    That should be a function : boolean returning true\false if the AveragePixelShift is reached
    I thought about that, but if I say that the result in the PlayerIsMining is the AveragePixelShift(something), AveragePixelShift is a boolean itself, it detects if the the pixels change a lot and return true or false and assigns that to the result.

    Brandon, FastClick is a mouse procedure by Flight, I tried with clickmouse2 before and it still did a loop. It gets stuck somewhere in the beginning.

    Will try what DannyRS and you suggested. Will report soon. Thanks for the replies guys!

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

    Default

    Quote Originally Posted by Brandon View Post
    Looks about right.. Where did you get FastClick from? I see no such function in Simba's includes :l

    Change fast click to something like:

    ClickMouse2(MOUSE_LEFT);

    Also your animation function might be giving false positives. Run it in a test loop and see if it detects you mining all the time or not.
    FastClick is one of mine. Also, adding on to this, I'd also recommend adjusting your "PlayerIsMining" function. Try getting your player's average pixel shift facing all 4 directions.

    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..."


  13. #13
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    FastClick is one of mine. Also, adding on to this, I'd also recommend adjusting your "PlayerIsMining" function. Try getting your player's average pixel shift facing all 4 directions.
    Oh, that makes sense. Will try tomorrow ( 3 am here). Will report progress on this tomorrow. Thanks for the insight Flight!

  14. #14
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    EDIT: Sorry for the double post! Didn't notice.

    Reporting in,

    So after tweaking a LOT to no avail, I tried a different approach and it worked! I'm so happy!

    I tweaked the PlayerIsMining function after debugging my pixels and lowered the condition for the AveragePixelShift to return true. I deleted the repeat and replaced with a while. After that I only did an IF THEN check for the uptext, if it found it, it would break out of the loop and set the result to true.



    I leave here the code to the curious ones:

    Ignore the case statement as I deleted the right mouse clicking case for testing purposes.

    Simba Code:
    function FindTin: Boolean;
    var
      tmpCTS, i, x, y: Integer;
      RockTPA: TPointArray;
      RockATPA: T2DPointArray;
    begin
      tmpCTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.06, 0.87);
      FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
      SetColorToleranceSpeed(tmpCTS);
      SetToleranceSpeed2Modifiers(0.02, 0.02);

      If (Length(RockTPA) < 1) Then Exit;

      RockATPA := SplitTPAEx(RockTPA, 10, 10);
      SortATPASize(RockATPA, True);


      for i := 0 to high(RockATPA) do
      begin
        MiddleTPAEx(RockATPA[i], x, y);
        MMouse(x, y, 5, 5);
        if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
          Break
          else Writeln('We didnt find the rock');
      end;
      Result :=True;
    end;

    procedure MineTin;
    begin
      if FindTin then
      begin
        case random(100) of
          0..100:
            begin
              wait(RandomRange(50, 150));
              FastClick(mouse_left);
              while PlayerIsMining do
                wait(1000 + random(100));
            end;
        end;
      end;
    end;

    Thanks a lot to everyone who lost 5 minutes of their time to help me! Really appreciated!
    Last edited by Slashed; 12-15-2012 at 06:28 PM.

  15. #15
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    From what I can see, your function will still result as true if you don't find any ore if it goes through the ATPA to no avail. You might want to add some Exit with your writeln to avoid this.

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

    Default

    Quote Originally Posted by Wardancer View Post
    From what I can see, your function will still result as true if you don't find any ore if it goes through the ATPA to no avail. You might want to add some Exit with your writeln to avoid this.
    Ah yeah you're right Wardancer. Take a look at where you placed "Result := True;" in your findTin function, Slashed. Here's what I would recommend using instead for your for...to...do loop:

    Simba Code:
    for i := 0 to high(RockATPA) do
      begin
        MiddleTPAEx(RockATPA[i], x, y);
        MMouse(x, y, 5, 5);
        if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
        begin
          Result :=True;
          Exit;
        end else
          Writeln('We didnt find the rock');
      end;

    Notice the placement of Result := True and how it exits the functions immediately following successfully finding the tin rock.

    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..."


  17. #17
    Join Date
    Dec 2012
    Posts
    191
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Ah yeah you're right Wardancer. Take a look at where you placed "Result := True;" in your findTin function, Slashed. Here's what I would recommend using instead for your for...to...do loop:

    Simba Code:
    for i := 0 to high(RockATPA) do
      begin
        MiddleTPAEx(RockATPA[i], x, y);
        MMouse(x, y, 5, 5);
        if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
        begin
          Result :=True;
          Exit;
        end else
          Writeln('We didnt find the rock');
      end;

    Notice the placement of Result := True and how it exits the functions immediately following successfully finding the tin rock.

    Well, that was stupid on my part I had the result inside the loop before but when tweaking I must have left the result outside the loop. My bad!

    Thanks Wardancer and Flight!

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
  •