Results 1 to 14 of 14

Thread: Count color in dynamic area

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

    Default Count color in dynamic area

    So I was messing around with count color, and I was wondering how would I look for a count of color that appear within lets say a 5x5 pixel range anywere on the screen, instead of it just looking for count pixels in one area.

    Best code I got is:

    Simba Code:
    program new;
    {$i srl/srl.simba}
    const
      TOL = 15;
      ONE = 12761001;    // each word is 40 14846307


    var
      CountOne, FileFind: Integer;

    begin
      MouseSpeed := 15;
      ClearDebug;
      // 0 0 1914 1041
      CountOne := CountColorTolerance(ONE, 0, 0, 1914, 1041, TOL);

      FileFind := CountOne/33;

      Writeln('There are about ' + IntToStr(FileFind) + ' .jar documents on the desktop');
      Writeln('There are ' + IntToStr(CountOne) + ' Pixels that are ' + IntToStr(ONE) + ' color');

    end.

  2. #2
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    So basically search the whole client and determine how many objects are within a range of color counts?
    TPA can be more accurate here, by grouping the close ones as ATPA, then determine the number of objects by looping and checking the InRange(Length(ATPA[i]), mincount, maxcount).

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

    Default

    To continue with what riwu said, nothing stops you from adding count color to your TPA function to further narrow down your search. You can turn a coordinate into a TBox.

    Example:

    Simba Code:
    Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));

    This makes a TBox from a TPoint. You can use count colour after this.

    All that being said, this might be going overboard and stick to only TPA if it works.

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

    Default

    Quote Originally Posted by Wardancer View Post
    To continue with what riwu said, nothing stops you from adding count color to your TPA function to further narrow down your search. You can turn a coordinate into a TBox.

    Example:

    Simba Code:
    Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));

    This makes a TBox from a TPoint. You can use count colour after this.

    All that being said, this might be going overboard and stick to only TPA if it works.
    I only know how to use TPA's to click a color like this:

    Simba Code:
    program ClickSpot;
    {$i srl/srl.simba}
    Procedure FindBankTPA;
    var
      tmpCTS, l, r:Integer;
      BankTPA:TPointArray;
    begin
      MouseSpeed:=15;
      tmpCTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.19, 0.91);
      if FindColorsTolerance(BankTPA, 3954018, 8, 25, 518, 359, 3) then
        begin
        SetColorToleranceSpeed(tmpCTS);
        SetToleranceSpeed2Modifiers(0.02, 0.02);
        L := High(BankTPA);

        //wait(randomrange(60, 100));
        mmouse((BankTPA[r].x), (BankTPA[r].y), 2, 2);
        wait(randomrange(100, 150));
        clickmouse2(mouse_left);
        wait(randomrange(2000, 2500));
        end;
    end;
    begin
    FindBankPA;
    end.

    How would i split those

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

    Default

    Your code basically defeat the purpose of a TPA function. TPA stands for an array of TPoints. The way you use it, you only use a single TP. You need to add a loop to go through each TP found.

    Example:

    Simba Code:
    function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
    var
       a : Integer;
      TPA  : TPointArray;
      ATPA : T2DPointArray;
      MP   : TPoint;
      tmpCTS : Integer;
      Box  : TBox;
    begin
     if not LoggedIn then Exit;
     tmpCTS := GetColorToleranceSpeed;
     ColorToleranceSpeed(2);
     SetColorSpeed2Modifiers(Obj.Hue, Obj.Sat);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, Obj.Col, X1, Y1, X2, Y2, Obj.Tol);
      SortTPAFrom(TPA, point(MSCX,MSCY));
      ATPA := TPAtoATPAEx(TPA, 15, 15);
      for a := 0 to High(ATPA) do
      begin
        MP := MiddleTPA(ATPA[a]);
        if MP.x = 0 then
          Continue;
        Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
        MMouse(MP.x,MP.y,4,4);
        if(WaitUpText(Obj.UpText, 400))then
        begin
          x := MP.x; y := MP.y;
          Result := True
          Break;
        end;
      end;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2,0.2);
    end;

    To add CountColor in your function, you call add a line in the loop similar to:

    Simba Code:
    if CountColorTolerance(Color, Box.x1, Box.y1, Box.x2, Box.y2, Tolerance) < 100 then
      Continue;

    EDIT: Just to make sure "Continue;" is understood... what it does is basically skip the rest of the loop and go directly to the next TP. For example, if you were at the TPA[3] and you get it to Continue, it would jump straight to TPA[4] starting at the beginning of the loop.

    This explanation is HORRIBLY worded, but hopefully you do understand.

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

    Default

    Quote Originally Posted by Wardancer View Post
    Your code basically defeat the purpose of a TPA function. TPA stands for an array of TPoints. The way you use it, you only use a single TP. You need to add a loop to go through each TP found.

    Example:

    Simba Code:
    function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
    var
       a : Integer;
      TPA  : TPointArray;
      ATPA : T2DPointArray;
      MP   : TPoint;
      tmpCTS : Integer;
      Box  : TBox;
    begin
     if not LoggedIn then Exit;
     tmpCTS := GetColorToleranceSpeed;
     ColorToleranceSpeed(2);
     SetColorSpeed2Modifiers(Obj.Hue, Obj.Sat);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, Obj.Col, X1, Y1, X2, Y2, Obj.Tol);
      SortTPAFrom(TPA, point(MSCX,MSCY));
      ATPA := TPAtoATPAEx(TPA, 15, 15);
      for a := 0 to High(ATPA) do
      begin
        MP := MiddleTPA(ATPA[a]);
        if MP.x = 0 then
          Continue;
        Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
        MMouse(MP.x,MP.y,4,4);
        if(WaitUpText(Obj.UpText, 400))then
        begin
          x := MP.x; y := MP.y;
          Result := True
          Break;
        end;
      end;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2,0.2);
    end;

    To add CountColor in your function, you call add a line in the loop similar to:

    Simba Code:
    if CountColorTolerance(Color, Box.x1, Box.y1, Box.x2, Box.y2, Tolerance) < 100 then
      Continue;

    EDIT: Just to make sure "Continue;" is understood... what it does is basically skip the rest of the loop and go directly to the next TP. For example, if you were at the TPA[3] and you get it to Continue, it would jump straight to TPA[4] starting at the beginning of the loop.

    This explanation is HORRIBLY worded, but hopefully you do understand.
    I get an error when i run it:


    Code:
    [Error] (5:46): Unknown type 'MSObject' at line 4
    Compiling failed.
    Simba Code:
    Program click;
    {$i srl/srl.simba}

    function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
    var
       a : Integer;
      TPA  : TPointArray;
      ATPA : T2DPointArray;
      MP   : TPoint;
      tmpCTS : Integer;
      Box  : TBox;
    begin
     tmpCTS := GetColorToleranceSpeed;
     ColorToleranceSpeed(2);
     SetColorSpeed2Modifiers(0.19, 0.91);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
      SortTPAFrom(TPA, point(MSCX,MSCY));
      ATPA := TPAtoATPAEx(TPA, 15, 15);
      for a := 0 to High(ATPA) do
      begin
        MP := MiddleTPA(ATPA[a]);
        if MP.x = 0 then
          Continue;
        Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
        MMouse(MP.x,MP.y,4,4);
        begin
          x := MP.x; y := MP.y;
          Result := True
          Break;
        end;
      end;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2,0.2);
    end;
    Procedure Clickit;
    begin
    FindObject;
    end;
    begin
    Clickit;
    end.

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

    Default

    You have to understand that MSObject is a global record I use for my scripts. I'm feeling a bit lazy to explain so the easier way would be for you to remove the variables from the function and directly put them in the function itself. If you prefer, this is my generic TPA finding function. I use it for all my basic searches. Well, actually, I no more use this particular one, but it used to be my generic function so I could search multiple items with it.

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

    Default

    Quote Originally Posted by Wardancer View Post
    You have to understand that MSObject is a global record I use for my scripts. I'm feeling a bit lazy to explain so the easier way would be for you to remove the variables from the function and directly put them in the function itself. If you prefer, this is my generic TPA finding function. I use it for all my basic searches. Well, actually, I no more use this particular one, but it used to be my generic function so I could search multiple items with it.
    So.. what do i do with it?

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

    Default

    Simply remove all the variables after FindObject (the stuff in parenthesis) and add your clicking to the function.

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

    Default

    I'm still getting a invalid number of parameters at line 38 when I cut them out:

    Simba Code:
    Program click;
    {$i srl/srl.simba}

    function FindObject(var x, y : Integer) : Boolean;
    var
       a : Integer;
      TPA  : TPointArray;
      ATPA : T2DPointArray;
      MP   : TPoint;
      tmpCTS : Integer;
      Box  : TBox;
    begin
     tmpCTS := GetColorToleranceSpeed;
     ColorToleranceSpeed(2);
     SetColorSpeed2Modifiers(0.19, 0.91);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
      SortTPAFrom(TPA, point(MSCX,MSCY));
      ATPA := TPAtoATPAEx(TPA, 15, 15);
      for a := 0 to High(ATPA) do
      begin
        MP := MiddleTPA(ATPA[a]);
        if MP.x = 0 then
          Continue;
        Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
        MMouse(MP.x,MP.y,4,4);
        begin
          x := MP.x; y := MP.y;
          Result := True
          Break;
        end;
      end;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2,0.2);
    end;
    Procedure Clickit;
    begin
    FindObject;
    end;
    begin
    Clickit;
    end.

    Line 38

    Simba Code:
    FindObject;

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

    Default

    Quote Originally Posted by rjj95 View Post
    I'm still getting a invalid number of parameters at line 38 when I cut them out:

    Simba Code:
    Program click;
    {$i srl/srl.simba}

    function FindObject(var x, y : Integer) : Boolean;
    var
       a : Integer;
      TPA  : TPointArray;
      ATPA : T2DPointArray;
      MP   : TPoint;
      tmpCTS : Integer;
      Box  : TBox;
    begin
     tmpCTS := GetColorToleranceSpeed;
     ColorToleranceSpeed(2);
     SetColorSpeed2Modifiers(0.19, 0.91);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
      SortTPAFrom(TPA, point(MSCX,MSCY));
      ATPA := TPAtoATPAEx(TPA, 15, 15);
      for a := 0 to High(ATPA) do
      begin
        MP := MiddleTPA(ATPA[a]);
        if MP.x = 0 then
          Continue;
        Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
        MMouse(MP.x,MP.y,4,4);
        begin
          x := MP.x; y := MP.y;
          Result := True
          Break;
        end;
      end;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2,0.2);
    end;
    Procedure Clickit;
    begin
    FindObject;
    end;
    begin
    Clickit;
    end.

    Line 38

    Simba Code:
    FindObject;
    That's because you aren't sending the integers when you call FindObject as it isn't a procedure, it's a function.

    Forum account issues? Please send me a PM

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

    Default

    I guess there has to be a short explanation of what the information in parenthesis next to a procedure or a function means.

    Let's take the original FindObject function:

    Simba Code:
    function FindObject(var x, y : Integer; X1, Y1, X2, Y2:integer)          //Removed the record not to confuse you

    Variables/information put in parenthesis can serve two purposes. One is to "feed" the function, telling it what to do. The other is to return a value (you'll see "var" before the actual variables in those cases). It goes without saying that you need to tell your function as many variables as the number of parameters it asks for else it just won't work. It'll need some feeding or something to give its feedback to.

    In this particular case, you kept the var x, y in the FindObject function. Therefore, you absolutely MUST have a variable ready so the function gives you a feedback for these two variables. In other words, FindObject by itself can't work, but FindObject(x, y) would (assuming you defined x and y as variables.

    I really hope that you'll understand this explanation and not just blindly copy the fix. It'll help a great deal into helping you make your own core functions for your scripts.

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

    Default

    Lol, chris GTFO if your going to go onto the help section and expect people to know what their doing, im in the help section for a reason


    Also, im still getting the same error when ever i try to do the function

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

    Default

    We explained exactly what you did wrong. I don't see how else I could explain it. Re-read our posts.

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
  •