Results 1 to 11 of 11

Thread: Do you use PixelShift to click a moving object?

  1. #1
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default Do you use PixelShift to click a moving object?

    As title states - I was trying to go through the includes but I'm struggling to determine what exactly I'm looking for. I'm thinking pixelshift might be it.

    Currently I have the following script - which it works perfectly fine albeit miss clicking every so often. My main concern is though is for smaller objects that would be moving in the future, I don't think it'd ever be able to click on something unless it came to a complete standstill.

    Edit: Also if anyone has some input on the progress to my first script using SRL please leave as much constructive criticism as you can!

    Simba Code:
    program SheepShearer;
    {$DEFINE SMART}
    {$i srl-6/srl.simba}

    Function clickSheep(): boolean;
    var x, y: integer;
    begin
    if  mainScreen.findObject(x, y, 16777215, 0, ['Shear Sheep'], MOUSE_RIGHT) then
      begin
        writeln('Right-clicked Sheep - Selecting to Shear Sheep');
        result := chooseOption.select(['hear Shee']);
      end;
    end;

    Function Shear(): boolean;
    var
      currentCount: integer;
    begin
      while (not tabBackPack.isFull()) do
        begin
          currentCount :=tabBackpack.count();
          if (clickSheep()) then
          begin
            writeln('Waiting while shearing');
            tabBackPack.waitForShift(5000);
          end else
          begin
            writeln('Cannot find Sheep, exiting');
            exit(false);
          end;
        end;

      result := true;
    end;

    //If pack full > bank

    begin
      clearDebug();
      setupSRL();
      repeat
        Shear()
      until false;
    end.
    Last edited by BlitzKrieger; 12-10-2016 at 07:37 PM.

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

    Default

    pixelshift will tell you whether or not something is moving, but it won't tell you where to find things that are moving.
    Here is a good post if you want to use motion detection.

  3. #3
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    @Citrus;
    Thanks, much appreciated! I think I'm going to work on trying to finish this up first (hopefully it goes as smoothly) and then I'll start messing around with the other stuff (such as that) and try to make it better. I'm a little confused on some of the posts though and how it works exactly. Will have to delve a little deeper probably.

    Also, given that it's misclicking just with the code below - it seems like maybe it's just slow. Obviously it needs to process it but is there any way to speed this up? It's not like I have a lot of code but a couple ms could be the difference so maybe I'm not doing something "correctly". *shrug*
    Simba Code:
    mainScreen.findObject(x, y, 16777215, 0, ['Shear Sheep'], MOUSE_RIGHT)
    Last edited by BlitzKrieger; 12-11-2016 at 05:03 AM.

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

    Default

    Quote Originally Posted by BlitzKrieger View Post
    Also, given that it's misclicking just with the code below - it seems like maybe it's just slow. Obviously it needs to process it but is there any way to speed this up? It's not like I have a lot of code but a couple ms could be the difference so maybe I'm not doing something "correctly". *shrug*
    Simba Code:
    mainScreen.findObject(x, y, 16777215, 0, ['Shear Sheep'], MOUSE_RIGHT)
    I've never used findObject, but I think the fact that you're searching for a single color with 0 tolerance will really hurt your results.
    Check out section 6 of this tutorial for better color finding methods.

  5. #5
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    @Citrus;

    Well I actually walked through (can't post links yet fml) thread id:110116 Finding colors using bitmaps/masks by bonsai (with very high success on other objects) although with Sheep not so much as there's literally only one unique color. My other results with tolerance set to 3 was a brown color and a gray but this picked up A LOT of background colors. With color tolerance 5 there were about 60 colors to select from but again - it picked up A LOT of background colors.

    Edit: Not relevant but I also apparently can't post bugs yet. Guess I'll try to update this MM_SYMBOL. Haven't messed with DTMs yet!
    aaannnndd apparently DTM is not the same at BitmapFromString..
    Last edited by BlitzKrieger; 12-11-2016 at 05:13 PM.

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

    Default

    I did a little comparison because I was bored.

    Color:


    Motion detection (no plugin):


    Color:
    Simba Code:
    procedure trackSheep();
    var
      b: TBox := mainscreen.getBounds;
      tpa, tpa2: TPointArray;
      atpa: T2DPointArray;
    begin
      findColors(tpa, 14079702, b);
      findColorsTolerance(tpa2, 13553620, b, 6);
      tpa := combineTPA(tpa, tpa2);
      findColorsTolerance(tpa2, 13421522, b, 14);
      tpa := combineTPA(tpa, tpa2);
      findColorsTolerance(tpa2, 12434374, b, 16);
      tpa := combineTPA(tpa, tpa2);
      atpa := clusterTPA(tpa, 3);
      filterTPAsBetween(atpa, 0, 90);
      tpa := mergeATPA(atpa);

      //smartImage.clear();
      //smartImage.drawTPA(tpa, clAqua);
    end;

    Motion:
    Simba Code:
    function motion(b: TBox; time: integer; skip: integer = 0): TPointArray;
    var
      i, c, x, y, bmp1, bmp2: integer;
    begin
      bmp1 := bitmapFromClient(b.x1, b.y1, b.x2, b.y2);
      wait(time);
      bmp2 := bitmapFromClient(b.x1, b.y1, b.x2, b.y2);
      setLength(result, ((b.x2 - b.x1) * (b.y2 - b.y1)));
      for x := 0 to (b.x2 - b.x1) do
      begin
        for y := 0 to (b.y2 - b.y1) do
        begin
          if (fastGetPixel(bmp1, x, y) <> fastGetPixel(bmp2, x, y)) then
          begin
            result[c] := point(x, y);
            inc(c);
          end;
          inc(y, skip);
        end;
        inc(x, skip);
      end;

      setLength(result, c);
      offsetTPA(result, point(b.x1, b.Y1));

      freeBitmap(bmp1);
      freeBitmap(bmp2);
    end;

    procedure trackSheep();
    var
      b: TBox := mainscreen.getBounds;
      tpa: TPointArray;
    begin
      tpa := motion(b, 27, 0);

      //smartImage.clear();
      //smartImage.drawTPA(tpa, clOrange);
    end;

    Motion detection usually looks a bit better than this, but sheep are weird and I didn't use a plugin.
    Last edited by Citrus; 12-12-2016 at 01:55 AM.

  7. #7
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    @Citrus;

    Very interesting thanks for sharing. I'll have to experiment around with Debugging a bit. Seems extremely useful to learn. How are you getting it to black out like that? I've enabled smartDrawing and have been messing with smartImage.debugATPA(ATPA) with no luck. Looking through Debug include right now.

    Yes Sheep are very weird..

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

    Default

    Quote Originally Posted by BlitzKrieger View Post
    @Citrus;

    Very interesting thanks for sharing. I'll have to experiment around with Debugging a bit. Seems extremely useful to learn. How are you getting it to black out like that? I've enabled smartDrawing and have been messing with smartImage.debugATPA(ATPA) with no luck. Looking through Debug include right now.

    Yes Sheep are very weird..
    Don't worry about the black, that's just how I made the gifs because I like how it looks
    With SRL-6 you can easily debug things, even while playing the game. I'll add in some debug to the code in my previous post.

    (if you really want, you can just use drawBox to make a black box covering the mainscreen, then draw whatever after that. set 'fill' to true and use '1' as the color)
    Last edited by Citrus; 12-12-2016 at 01:58 AM.

  9. #9
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    @Citrus;
    Struggling with this.

    Simba Code:
    program new;
    {$DEFINE SMART}
    {$i srl-6/srl.simba}

    begin
      SetupSRL();
      clearDebug();
      smartEnableDrawing := true;
      smartImage.drawBox(intToBox(0,0,100,100), true, clblack);
    end

    Get access violation as if it's not able to find it..? I know my resolutions messes a bit with where it thinks things are at but I was able to draw TPA's and ATPA's earlier without problems. What am I doing wrong?

    Edit: It takes me to Drawing -
    Error: Access violation at line 119
    Execution failed.
    The following bitmaps were not freed: [Minimap Mask]
    File[C:\Simba\Includes\SRL-6/logs/SRL log (11-12-16 at 08.34.51 PM).txt] has not been freed in the script, freeing it now.

    Edit: Fixed the resolution issue - unfortunately didn't help with this.

    NVM think i'm going to reinstall Simba. SPS is doing the following (only works right because it's repeating but it's broke due to that as I put in a failsafe to check the icons so it doesn't fully run to where I want it to. :/
    ---- Setup SRL in 0 Seconds
    -- setupSRL(): True
    -- sps.init()
    ---- Path exists (C:\Simba\Includes\SPS\img\runescape_other\SheepSh earerSPS.png)
    ---- Setup area "SheepShearerSPS" in 4294967342ms
    -- sps.init()
    ---- TRSGameTab.__initTabs(): Setup gametab properties
    -- sps.getPlayerPos(): result = {X = 406, Y = 298}, took 4294967609 ms
    ---- Waiting while the player is moving...
    -- sps.walkPath(): result = False
    Failed to run to the bank
    -- Succesfully freed SMART[5736]
    -- Freeing gametabs bitmaps...
    Successfully executed.

    *shrug* fingers crossed?
    Last edited by BlitzKrieger; 12-12-2016 at 03:41 AM.

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

    Default

    Quote Originally Posted by BlitzKrieger View Post
    ...
    Hmm. Idk if I can help much with this kind of thing. I had 'smartEnableDrawing := true;' before 'setupSRL();,' but I don't know if that matters.

  11. #11
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Hmm. Idk if I can help much with this kind of thing. I had 'smartEnableDrawing := true;' before 'setupSRL();,' but I don't know if that matters.
    Who knows, reinstall didn't help. Tried creating another topic for the SPS issue. I'm going to quadruple check my in game settings to make sure that's not causing any strange issues as well.

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
  •