Results 1 to 10 of 10

Thread: Parsing TPointArrays

  1. #1
    Join Date
    Apr 2012
    Posts
    157
    Mentioned
    10 Post(s)
    Quoted
    57 Post(s)

    Default Parsing TPointArrays

    Is there a function to automatically parse "similar" tpoint coordinates inside an array, or do I need to write a custom one to look and decide?

    Thanks!

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

    Default

    What do you mean parse Similar TPoints inside an array..

    Do you mean search an array for a tpoint? if so then:
    PointInTPA will work..


    Here's a couple others:
    Simba Code:
    Function TPAPointInTPABounds(Search, EntireTPA: TPointArray): Boolean;
    var
      I, L: Integer;
      Bounds: TBox;
    begin
      Result := True;
      Bounds := GetTPABounds(EntireTPA);
      L:= High(Search);
      for I:= 0 To L do
        if (PointInBox(Search[I], Bounds)) then
          Exit;
      Result := False;
    end;

    Function TPAInTPABounds(Search, EntireTPA: TPointArray): Boolean;
    var
      I, L: Integer;
      Bounds: TBox;
    begin
      Result:= False;
      Bounds:= GetTPABounds(EntireTPA);
      L:= High(Search);
      For I:= 0 To L do
        if (Not PointInBox(Search[I], Bounds)) then
          Exit;
      Result:= True;
    end;

    Function TPAInTPAMajority(Search, EntireTPA: TPointArray): Boolean;
    var
      I, L, Found, NotFound: Integer;
      Bounds: TBox;
    begin
      Bounds:= GetTPABounds(EntireTPA);
      L:= High(Search);
      For I:= 0 To L do
        if (PointInBox(Search[I], Bounds)) then
          Inc(Found)
        else
          Inc(NotFound);
      Result:= Found >= NotFound;
    end;
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Apr 2012
    Posts
    157
    Mentioned
    10 Post(s)
    Quoted
    57 Post(s)

    Default

    Well, I am grabbing a lot of data on screen. I am grabbing all the "Grey", but I want to remove any 2 points that are too close, as I want to then search within this "grey" for another color (The gold of a bank symbol).

    So I figured, if I grab all the grey on screen into an array. I can then parse the array so I have less points, and then use another findcolorsspiral function around each of these grey pixels to look for my gold.

    Should I just use FindSymbol? Would that be easier..lol

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

    Default

    Quote Originally Posted by serajin View Post
    Well, I am grabbing a lot of data on screen. I am grabbing all the "Grey", but I want to remove any 2 points that are too close, as I want to then search within this "grey" for another color (The gold of a bank symbol).

    So I figured, if I grab all the grey on screen into an array. I can then parse the array so I have less points, and then use another findcolorsspiral function around each of these grey pixels to look for my gold.

    Should I just use FindSymbol? Would that be easier..lol

    These two could help you:
    Simba Code:
    //FoundSymbol By Flight:
      Function FoundSymbol(Ident: Integer; var X, Y, Dist: Integer): Boolean;
      var
        B: TBox;
        TPA: TPointArray;
        L,i,CTS: Integer;
        ATPA,ATPA2: T2DPointArray;
      begin
        CTS := GetColorToleranceSpeed;
        ColorToleranceSpeed(2);
        FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
        FilterPointsPie(TPA, 0.0, 360.0, 0.0, 70.0, MMCX, MMCY);
        ColorToleranceSpeed(CTS);
        if Length(TPA) < 1 then
          Exit;
        ATPA := TPAtoATPAEx(TPA, 10, 10);
        L := High(ATPA);
        SetArrayLength(ATPA2, L+1);
        for i := 0 to L do
        begin
          B := GetTPABounds(ATPA[i]);
          with B do
          begin
            if (Ident = 1) then
              FindColorsTolerance(ATPA2[i], 4672833, B.X1, B.Y1, B.X2, B.Y2, 10)    //Transporter Symbol.
            else if(Ident = 2) then
              FindColorsTolerance(ATPA2[i], 16279333, B.X1, B.Y1, B.X2, B.Y2, 10)   //Water Symbol..
            else if (Ident = 3) then
              FindColorsTolerance(ATPA2[i], 2413294, B.X1, B.Y1, B.X2, B.Y2, 5);   //Bank Symbol..
            FFinder:= 'Found Symbol';
            Result := (Length(ATPA2[i]) > 0);
            if Result then
            begin
              MiddleTPAEx(ATPA2[i], X, Y);
              Dist := Distance(MMCX, MMCY, X, Y);
              Exit;
            end;
          end;
        end;
      end;

    And the one by me:
    Simba Code:
    Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
    var
      CTS, L, I: Integer;
      TPACopy: TPointArray;
      ATPA, ATPA2: T2DPointArray;
      B: TBox;
    begin
      CTS:= GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(Speed[0], Speed[1]);

      if (Length(TPA) < 1) then
        Exit;

      TPACopy:= CopyTPA(TPA);
      if (Length(TPACopy) < 1) then
        Exit;

      ATPA:= TPAToATPAEx(TPACopy, Width, Height);
      SortATPASize(ATPA, True);
      L := High(ATPA);
      SetArrayLength(ATPA2, L+1);

      For I:= 0 To L do
      begin
        B := GetTPABounds(ATPA[I]);
        with B do
        begin
          FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
          if (Length(ATPA2[I]) < 1) then
            Continue;
        end;
      end;
      if (Length(ATPA2) > 0) then
        Result:= MergeATPA(ATPA2)
      else
        Result:= [];

      ColorToleranceSpeed(CTS);
      SetColorSpeed2Modifiers(0.02, 0.02);
    end;

    Function FoundSymbol(Ident: Integer; var Point: TPoint; var Dist: Integer): Boolean;
    var
      CTS, I, L: Integer;
      TPA, ColorTPA: TPointArray;
      ATPA: T2DPointArray;
    begin
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
      FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
      ColorToleranceSpeed(CTS);
      if Length(TPA) < 1 then
        Exit;

      ATPA:= TPAToATPAEx(TPA, 10, 10);
      L:= High(ATPA);
      For I:= 0 To L Do
      begin
        case Ident of
          1:  ColorTPA:= FindObjectInObject(TPA, 1260388, 10, 10, 5, [0.2, 0.2]);     //Mining Symbol.
          2:  ColorTPA:= FindObjectInObject(TPA, 2413294, 10, 10, 5, [0.2, 0.2]);     //Bank Symbol.
          3:  ColorTPA:= FindObjectInObject(TPA, 13679255, 10, 10, 5, [0.2, 0.2]);    //Transport Symbol.
          4:  ColorTPA:= FindObjectInObject(TPA, 2369228, 10, 10, 5, [0.2, 0.2]);     //CastleWars Symbol.
          5:  ColorTPA:= FindObjectInObject(TPA, 9002045, 10, 10, 5, [0.2, 0.2]);     //Summoning Symbol.
        end;
        Result := (Length(ColorTPA) > 0);
        if Result then
        begin
          Point:= MiddleTPA(ColorTPA);
          Dist := Distance(MMCX, MMCY, Point.X, Point.Y);
          Exit;
        end;
      end;
    end;
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Apr 2012
    Posts
    157
    Mentioned
    10 Post(s)
    Quoted
    57 Post(s)

    Default

    Oh excellent! I think that's EXACTLY what I need!

    Thank you!

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

    Default

    Quote Originally Posted by serajin View Post
    Oh excellent! I think that's EXACTLY what I need!

    Thank you!
    Check the post I edited it.. Maybe mine was too complexed.. I posted a version by Flight which is pretty clean and simple.. It's only one function.

    Myself I make things a bit hard.. so you might want to check that last post I made since I edited it. If you use Flight's, don't forget to credit him.
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Apr 2012
    Posts
    157
    Mentioned
    10 Post(s)
    Quoted
    57 Post(s)

    Default

    Ofcourse! Credit to everyone! I'll go ahead and look at both.

    Is there a place where these little helpful functions are already placed? Or is it just like, grabbing them from other scripts, saving them out, and using them later?

  8. #8
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    ...or you could just use the various TPA methods included within Simba:
    • RAaSTPAEx / RAaSTPA / ReArrangeandShortenArrayEx / ReArrangeandShortenArray
    • NearbyPointInArrayEx / NearbyPointInArray
    • SplitTPAEx / SplitTPA / TPAtoATPAEx / TPAtoATPA


    See: http://docs.villavu.com/simba/scriptref/tpa.html for more methods as-well as information on each individual function.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  9. #9
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by serajin View Post
    Ofcourse! Credit to everyone! I'll go ahead and look at both.

    Is there a place where these little helpful functions are already placed? Or is it just like, grabbing them from other scripts, saving them out, and using them later?
    If you go here you will find a lot of useful functions in the SRL Snippets section as well as some in the Suggestions section.

    Also, even though you have found the solution, I think this is EXACTLY what you were looking for: http://villavu.com/forum/showthread.php?t=81393

  10. #10
    Join Date
    Feb 2012
    Location
    SRL Jail
    Posts
    1,319
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    These two could help you:
    Simba Code:
    //FoundSymbol By Flight:
      Function FoundSymbol(Ident: Integer; var X, Y, Dist: Integer): Boolean;
      var
        B: TBox;
        TPA: TPointArray;
        L,i,CTS: Integer;
        ATPA,ATPA2: T2DPointArray;
      begin
        CTS := GetColorToleranceSpeed;
        ColorToleranceSpeed(2);
        FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
        FilterPointsPie(TPA, 0.0, 360.0, 0.0, 70.0, MMCX, MMCY);
        ColorToleranceSpeed(CTS);
        if Length(TPA) < 1 then
          Exit;
        ATPA := TPAtoATPAEx(TPA, 10, 10);
        L := High(ATPA);
        SetArrayLength(ATPA2, L+1);
        for i := 0 to L do
        begin
          B := GetTPABounds(ATPA[i]);
          with B do
          begin
            if (Ident = 1) then
              FindColorsTolerance(ATPA2[i], 4672833, B.X1, B.Y1, B.X2, B.Y2, 10)    //Transporter Symbol.
            else if(Ident = 2) then
              FindColorsTolerance(ATPA2[i], 16279333, B.X1, B.Y1, B.X2, B.Y2, 10)   //Water Symbol..
            else if (Ident = 3) then
              FindColorsTolerance(ATPA2[i], 2413294, B.X1, B.Y1, B.X2, B.Y2, 5);   //Bank Symbol..
            FFinder:= 'Found Symbol';
            Result := (Length(ATPA2[i]) > 0);
            if Result then
            begin
              MiddleTPAEx(ATPA2[i], X, Y);
              Dist := Distance(MMCX, MMCY, X, Y);
              Exit;
            end;
          end;
        end;
      end;

    And the one by me:
    Simba Code:
    Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
    var
      CTS, L, I: Integer;
      TPACopy: TPointArray;
      ATPA, ATPA2: T2DPointArray;
      B: TBox;
    begin
      CTS:= GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(Speed[0], Speed[1]);

      if (Length(TPA) < 1) then
        Exit;

      TPACopy:= CopyTPA(TPA);
      if (Length(TPACopy) < 1) then
        Exit;

      ATPA:= TPAToATPAEx(TPACopy, Width, Height);
      SortATPASize(ATPA, True);
      L := High(ATPA);
      SetArrayLength(ATPA2, L+1);

      For I:= 0 To L do
      begin
        B := GetTPABounds(ATPA[I]);
        with B do
        begin
          FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
          if (Length(ATPA2[I]) < 1) then
            Continue;
        end;
      end;
      if (Length(ATPA2) > 0) then
        Result:= MergeATPA(ATPA2)
      else
        Result:= [];

      ColorToleranceSpeed(CTS);
      SetColorSpeed2Modifiers(0.02, 0.02);
    end;

    Function FoundSymbol(Ident: Integer; var Point: TPoint; var Dist: Integer): Boolean;
    var
      CTS, I, L: Integer;
      TPA, ColorTPA: TPointArray;
      ATPA: T2DPointArray;
    begin
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      FindColorsTolerance(TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
      FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
      ColorToleranceSpeed(CTS);
      if Length(TPA) < 1 then
        Exit;

      ATPA:= TPAToATPAEx(TPA, 10, 10);
      L:= High(ATPA);
      For I:= 0 To L Do
      begin
        case Ident of
          1:  ColorTPA:= FindObjectInObject(TPA, 1260388, 10, 10, 5, [0.2, 0.2]);     //Mining Symbol.
          2:  ColorTPA:= FindObjectInObject(TPA, 2413294, 10, 10, 5, [0.2, 0.2]);     //Bank Symbol.
          3:  ColorTPA:= FindObjectInObject(TPA, 13679255, 10, 10, 5, [0.2, 0.2]);    //Transport Symbol.
          4:  ColorTPA:= FindObjectInObject(TPA, 2369228, 10, 10, 5, [0.2, 0.2]);     //CastleWars Symbol.
          5:  ColorTPA:= FindObjectInObject(TPA, 9002045, 10, 10, 5, [0.2, 0.2]);     //Summoning Symbol.
        end;
        Result := (Length(ColorTPA) > 0);
        if Result then
        begin
          Point:= MiddleTPA(ColorTPA);
          Dist := Distance(MMCX, MMCY, Point.X, Point.Y);
          Exit;
        end;
      end;
    end;
    why not just
    Simba Code:
    findsymbol('bank');
    ? I don't see why you need a TPA for that...

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
  •