Results 1 to 15 of 15

Thread: How can I use 2 colors with ATPA?

  1. #1
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default How can I use 2 colors with ATPA?

    Hey I want to search for 2 colors so if both colors are found near eachother, the object is found. Just like these

    Code:
    obj_bank.create('Bank chest', ['Use Bank chest', 'Bank chest'], [createCol(1383720, 2, 0.9, 0.9)], [createCol(1976631, 2, 0.9, 0.9)]);
    I dont like using those though, right now I can use ATPA and customize a lot more, but how can I search for a second color like the Aerolib objects do?

    Code:
    var
    x, y: integer;
    obj_lesser: TMSObject;
    
    
    function GetDemonPos(var Position : TPoint) : Boolean;
    var
      DemonCol : TColEx;
      TPA : TPointArray;
      ATPA : T2DPointArray;
      I : Integer;
    begin
      DemonCol.create(792912, 13, 0.16, 2.04);
      if DemonCol.findAllIn(IntToBox(MSX1, MSY1, MSX2, MSY2), TPA) then
      begin
        ATPA := ClusterTPA(TPA, 3);
        FilterTPAsBetween(ATPA, 0, 400);
        Result := (Length(ATPA) > 0);
        if Result then
        begin
          if (Length(ATPA) > 1) then
            SortATPASize(ATPA, True);
          SortTPAFrom(ATPA[0], MiddleTPA(ATPA[0]));
          I := Abs(iGaussRange(-High(ATPA[0]), High(ATPA[0])));
          Position := ATPA[0][I];
        end;
      end;
    end;
    Thats my current code for using a single color.

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by SimbaOp View Post
    Hey I want to search for 2 colors so if both colors are found near eachother, the object is found. Just like these

    Code:
    obj_bank.create('Bank chest', ['Use Bank chest', 'Bank chest'], [createCol(1383720, 2, 0.9, 0.9)], [createCol(1976631, 2, 0.9, 0.9)]);
    I dont like using those though, right now I can use ATPA and customize a lot more, but how can I search for a second color like the Aerolib objects do?

    Code:
    var
    x, y: integer;
    obj_lesser: TMSObject;
    
    
    function GetDemonPos(var Position : TPoint) : Boolean;
    var
      DemonCol : TColEx;
      TPA : TPointArray;
      ATPA : T2DPointArray;
      I : Integer;
    begin
      DemonCol.create(792912, 13, 0.16, 2.04);
      if DemonCol.findAllIn(IntToBox(MSX1, MSY1, MSX2, MSY2), TPA) then
      begin
        ATPA := ClusterTPA(TPA, 3);
        FilterTPAsBetween(ATPA, 0, 400);
        Result := (Length(ATPA) > 0);
        if Result then
        begin
          if (Length(ATPA) > 1) then
            SortATPASize(ATPA, True);
          SortTPAFrom(ATPA[0], MiddleTPA(ATPA[0]));
          I := Abs(iGaussRange(-High(ATPA[0]), High(ATPA[0])));
          Position := ATPA[0][I];
        end;
      end;
    end;
    Thats my current code for using a single color.
    I think AND_TPA is what you're looking for.

  3. #3
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    you could combine 2 unlike colors after searching for them individually to get one tpa, then do your searching/filtering/etc, etc.

    Code:
    tpa1 := findcolors(params, color1);
    tpa2 := findcolors(params, color2);
    tpa1andtpa2 := combinetpa(tpa1, tpa2);
    
    and whatever else you want to do now

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

    Default

    Quote Originally Posted by SimbaOp View Post
    I dont like using those though
    Why?

    Anyways, there's a few ways you can accomplish this. As posted above, bg5's AND_TPA is a nice option if you don't mind including a plugin just to accomplish this. You can also find the first color, split/cluster it into a 2DPointArray, then do the same with the second color. After that, check every array within both 2DPointArrays if the middle point is within a specified distance (NearbyPointInArray()) from the other 2DPointArray (every array within it). Or... as a more thorough searching, after splitting/clustering your 2 color into ATPAs (2DPointArrays), check each point, rather than only checking the middle point, if they're within distance to the opposing ATPA (every point within each [TPA]).

    Break apart AeroLib's TMSObject.findAll() function for a perfect example of doing this.

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


  5. #5
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    Quote Originally Posted by SimbaOp View Post
    Hey I want to search for 2 colors so if both colors are found near eachother, the object is found. Just like these
    I found this function in an old thread that has some more links with related discussion. It would need some rework but the basics are there.

    Simba Code:
    // -----------------------------------------------------------------------------
    // TObjFind._doFilterInclusiveExact(allPoints: T2DPointArray)
    //
    // Filters points so the only remaining ones are where all colors are in the
    // specified distance in the inclusiveSpec
    // -----------------------------------------------------------------------------
    function TobjFind._doFilterInclusiveExact(allPoints: T2DPointArray) : T2DPointArray;
    var
       base, compareTo, basePoint, i: integer;
       highAllPoints, highBase: integer;
       foundOne: array of boolean;
       foundAll: boolean;
       
    begin
       if ((self.inclusiveSpec.minDist <= 0) and (self.inclusiveSpec.maxDist <= 0)) then
       begin
          result := allPoints.copy();
          exit;
       end;

       highAllPoints := high(allPoints);
       
       // initialize things
       setLength(foundOne, length(allPoints));
       setLength(result, length(allPoints));
       for i := 0 to highAllPoints do
          setLength(result[i], 0);
       
       for base := 0 to highAllPoints do
       begin
          {$IFDEF TOBJ_DEBUG}
             writeln('TobjFind._doFilterInclusive: Processing array ', base);
          {$ENDIF}
             
          foundOne[base] := true;  // we can find our own point within distance :)
         
          highBase := high(allPoints[base]);
          for basePoint := 0 to highBase do
          begin        
             for compareTo := 0 to highAllPoints do
             begin
                // don't compare to the same color, only the others
                if (compareTo = base) then continue;
                 
                foundOne[compareTo] := NearbyPointInArray(allPoints[base][basePoint],
                   self.inclusiveSpec.maxDist, allPoints[compareTo]);        
             end;
             
             // all other colors have been looked at, did they all match?
             // if so, add this point to the return list.
             foundAll := true;
             for i := 0 to highAllPoints do
                if (not foundOne[i]) then
                begin
                   foundAll := false;
                   break;
                end;
             if (foundAll) then
             begin
                if (length(result[base]) = 0) then
                begin
                   setLength(result[base], 1);
                   result[base][0] := allPoints[base][basePoint];
                end
                else
                   result[base].append(allPoints[base][basePoint]);
             end;            
          end;  // for basePoint    
       end;  // for base
       {$IFDEF TOBJ_DEBUG}
          writeln('TobjFind._doFilterInclusive: processing complete.  len result=', length(result));
       {$ENDIF}
    end;

  6. #6
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by SimbaOp View Post
    ...
    I would also recommend my AND_TPA plugin. It was made as a plugin due to large number of iterations, which would take Lape quite a lot of time. From what I know Aerolib also uses it. What's TColEx? Uhmm, looks familiar.
    You could probably do the same just by making a copy of Aerolib's function and modifying it. But here is raw code from scratch:

    I gonna use only AND_TPA and this little include, because I'm familiar with it, but it's easy to transcript to Aerolib.

    Simba Code:
    program new;
    {$include TCol.simba}
    {$loadlib AND_TPA}

    function FindDemon() : TPoint;
    var
    DemonCol1, DemonCol2 : TCol;
    TPA1, TPA2 :TPointArray;
    begin
      DemonCol1.Create(792912, 13, 2, 0.16, 2.04);
      DemonCol2.Create($FFFFF, 13, 2, 0.16, 2.04); // just define second color here
      DemonCol1.FindTPA(TPA1,MSX1, MSY1, MSX2, MSY2);
      DemonCol2.FindTPA(TPA2,MSX1, MSY1, MSX2, MSY2);
      FilterTPADistTPA(TPA1 , 0 , 5 , TPA2);
      // It means: Keep each Point in TPA1, which is in the distance of 0 to 5 to any Point from TPA2.
      // Notice, that as an output you get only the part of TPA1, which was close to TPA2, so second colour is not included at all.
      //Thus, it's recommended that first colour should be the one closest to center of object.
      //
      //If you would like to combine output from both colours you would need to do:
      // FilterTPADistTPA(TPA2 , 0 , 5 , TPA1);
      // AppendTPA(TPA1,TPA2);
      //
      // Now you can do your ATPA stuff
      // ATPA := ClusterTPA(TPA, 3); ...

    end;


    begin

    end.

  7. #7
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by bg5 View Post
    I would also recommend my AND_TPA plugin. It was made as a plugin due to large number of iterations, which would take Lape quite a lot of time. From what I know Aerolib also uses it. What's TColEx? Uhmm, looks familiar.
    You could probably do the same just by making a copy of Aerolib's function and modifying it. But here is raw code from scratch:

    I gonna use only AND_TPA and this little include, because I'm familiar with it, but it's easy to transcript to Aerolib.

    Simba Code:
    program new;
    {$include TCol.simba}
    {$loadlib AND_TPA}

    function FindDemon() : TPoint;
    var
    DemonCol1, DemonCol2 : TCol;
    TPA1, TPA2 :TPointArray;
    begin
      DemonCol1.Create(792912, 13, 2, 0.16, 2.04);
      DemonCol2.Create($FFFFF, 13, 2, 0.16, 2.04); // just define second color here
      DemonCol1.FindTPA(TPA1,MSX1, MSY1, MSX2, MSY2);
      DemonCol2.FindTPA(TPA2,MSX1, MSY1, MSX2, MSY2);
      FilterTPADistTPA(TPA1 , 0 , 5 , TPA2);
      // It means: Keep each Point in TPA1, which is in the distance of 0 to 5 to any Point from TPA2.
      // Notice, that as an output you get only the part of TPA1, which was close to TPA2, so second colour is not included at all.
      //Thus, it's recommended that first colour should be the one closest to center of object.
      //
      //If you would like to combine output from both colours you would need to do:
      // FilterTPADistTPA(TPA2 , 0 , 5 , TPA1);
      // AppendTPA(TPA1,TPA2);
      //
      // Now you can do your ATPA stuff
      // ATPA := ClusterTPA(TPA, 3); ...

    end;


    begin

    end.
    Hey, I want to use this but I think Im doing something wrong. The script compiled successfully but wont find anything.
    Code:
    function Getdemonpos(var Position : TPoint): Boolean;
    var
    DemonCol1, DemonCol2 : TCol;
    TPA, TPA1, TPA2 :TPointArray;
    ATPA : T2DPointArray;
    I : Integer;
    begin
      DemonCol1.Create(7445944, 56, 1, 8, 8);
      DemonCol2.Create(4679031, 78, 1, 8, 9); // just define second color here
      DemonCol1.FindTPA(TPA1,MSX1, MSY1, MSX2, MSY2);
      DemonCol2.FindTPA(TPA2,MSX1, MSY1, MSX2, MSY2);
      FilterTPADistTPA(TPA1 , 0 , 5 , TPA2);
     ATPA := ClusterTPA(TPA1, 3);
        FilterTPAsBetween(ATPA, 0, 400);
        Result := (Length(ATPA) > 0);
        if Result then
        begin
          if (Length(ATPA) > 1) then
            SortATPASize(ATPA, True);
          SortTPAFrom(ATPA[0], MiddleTPA(ATPA[0]));
          I := Abs(iGaussRange(-High(ATPA[0]), High(ATPA[0])));
          Position := ATPA[0][I];
        end;
    end;
    function AttackedDemon() : Boolean;
    var
      DemonPos : TPoint;
    begin
      for 1 to 3 do
      if GetDemonPos(DemonPos) and PointInBox(DemonPos, IntToBox(MSX1, MSY1, MSX2, MSY2)) then
      begin
        Mouse(DemonPos, 0, 0, Mouse_Move);
      end else
        Wait(Random(1300, 2450));
    end;
    
    begin
    inital;
    attackeddemon;
    end.

  8. #8
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Actually, my bad I forgot to combine the tpa's

    Code:
    function Getdemonpos(var Position : TPoint): Boolean;
    var
    DemonCol1, DemonCol2 : TCol;
    TPA, tpa1andtpa2, TPA1, TPA2 :TPointArray;
    ATPA : T2DPointArray;
    I : Integer;
    begin
      DemonCol1.Create(7248822, 2, 1, 0.09, 0.16);
      DemonCol2.Create(5537689, 12, 1, 0.02, 0.38); // just define second color here
      DemonCol1.FindTPA(TPA1,MSX1, MSY1, MSX2, MSY2);
      DemonCol2.FindTPA(TPA2,MSX1, MSY1, MSX2, MSY2);
      tpa1andtpa2 := combinetpa(tpa1, tpa2);
      FilterTPADistTPA(TPA1 , 0 , 40 , TPA2);
     ATPA := ClusterTPA(tpa1andtpa2, 3);
        FilterTPAsBetween(ATPA, 0, 40);
        Result := (Length(ATPA) > 0);
        if Result then
        begin
          if (Length(ATPA) > 1) then
            SortATPASize(ATPA, True);
          SortTPAFrom(ATPA[0], MiddleTPA(ATPA[0]));
          I := Abs(iGaussRange(-High(ATPA[0]), High(ATPA[0])));
          Position := ATPA[0][I];
        end;
    end;
    The script looks around for the colors now so I should be good, Thanks.

  9. #9
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by SimbaOp View Post
    Actually, my bad I forgot to combine the tpa's

    Code:
    function Getdemonpos(var Position : TPoint): Boolean;
    var
    DemonCol1, DemonCol2 : TCol;
    TPA, tpa1andtpa2, TPA1, TPA2 :TPointArray;
    ATPA : T2DPointArray;
    I : Integer;
    begin
      DemonCol1.Create(7248822, 2, 1, 0.09, 0.16);
      DemonCol2.Create(5537689, 12, 1, 0.02, 0.38); // just define second color here
      DemonCol1.FindTPA(TPA1,MSX1, MSY1, MSX2, MSY2);
      DemonCol2.FindTPA(TPA2,MSX1, MSY1, MSX2, MSY2);
      tpa1andtpa2 := combinetpa(tpa1, tpa2);
      FilterTPADistTPA(TPA1 , 0 , 40 , TPA2);
     ATPA := ClusterTPA(tpa1andtpa2, 3);
        FilterTPAsBetween(ATPA, 0, 40);
        Result := (Length(ATPA) > 0);
        if Result then
        begin
          if (Length(ATPA) > 1) then
            SortATPASize(ATPA, True);
          SortTPAFrom(ATPA[0], MiddleTPA(ATPA[0]));
          I := Abs(iGaussRange(-High(ATPA[0]), High(ATPA[0])));
          Position := ATPA[0][I];
        end;
    end;
    The script looks around for the colors now so I should be good, Thanks.
    No, there is no point in combining both TPSa ,before their are filtered. What I see wrong in your script is how you created TCol. 3rd value is CTS and you've used CTS 1, instead of 2.

  10. #10
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by bg5 View Post
    No, there is no point in combining both TPSa ,before their are filtered. What I see wrong in your script is how you created TCol. 3rd value is CTS and you've used CTS 1, instead of 2.
    Changed that

  11. #11
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Why?

    Anyways, there's a few ways you can accomplish this. As posted above, bg5's AND_TPA is a nice option if you don't mind including a plugin just to accomplish this. You can also find the first color, split/cluster it into a 2DPointArray, then do the same with the second color. After that, check every array within both 2DPointArrays if the middle point is within a specified distance (NearbyPointInArray()) from the other 2DPointArray (every array within it). Or... as a more thorough searching, after splitting/clustering your 2 color into ATPAs (2DPointArrays), check each point, rather than only checking the middle point, if they're within distance to the opposing ATPA (every point within each [TPA]).

    Break apart AeroLib's TMSObject.findAll() function for a perfect example of doing this.
    The reason I dont use the objects anymore is when they search around for the color, the mouse jumps around a lot. Not sure if Im doing something wrong there.

    The main reason is because I was in srl chat and showed my script and needed help and a guy said those are bad you shouldnt use them. Then he gave the code that I have above, and since then I just use that.

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

    Default

    Quote Originally Posted by SimbaOp View Post
    The reason I dont use the objects anymore is when they search around for the color, the mouse jumps around a lot. Not sure if Im doing something wrong there.

    The main reason is because I was in srl chat and showed my script and needed help and a guy said those are bad you shouldnt use them. Then he gave the code that I have above, and since then I just use that.
    The more information you feed into your TMSObject the more accurate its detection will be. Your mouse is jumping around a lot because you didn't define very much with it. You can provide two different colors that make up your TMSObject, and beyond that you can specify the mincount (minimum amount of your inner color to be considered a possible object) as well as both your height and width dimensions, with a tolerance to both. So you can make TMSObjects extremely accurate if you're willing to provide the information in your script.

    I think what I need to do is add optional live debugging to TMSObjects in Aerolib to aid scripters.

    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
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    The more information you feed into your TMSObject the more accurate its detection will be. Your mouse is jumping around a lot because you didn't define very much with it. You can provide two different colors that make up your TMSObject, and beyond that you can specify the mincount (minimum amount of your inner color to be considered a possible object) as well as both your height and width dimensions, with a tolerance to both. So you can make TMSObjects extremely accurate if you're willing to provide the information in your script.

    I think what I need to do is add optional live debugging to TMSObjects in Aerolib to aid scripters.
    I First used them when I took it from another script, didnt change the tolerance, hue, sat and just put in my new colors. This somehow worked to find objects but it would jump around a lot. Ill adjust all the things to my object just how you said, and give them another try.

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

    Default

    Quote Originally Posted by SimbaOp View Post
    I First used them when I took it from another script, didnt change the tolerance, hue, sat and just put in my new colors. This somehow worked to find objects but it would jump around a lot. Ill adjust all the things to my object just how you said, and give them another try.
    I might be able to help with your TMSObject if you'd like.

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


  15. #15
    Join Date
    Sep 2016
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    I might be able to help with your TMSObject if you'd like.
    Yeah, Im having trouble finding something, pm me

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
  •