1. ## getShiftedPixels();

AFAIK all of the pixelShift functions just give you an integer. I wanted the actual points (and bitmaps are weird), so I made this.
It's surprisingly good at finding NPCs when combined with MM2MS().
Simba Code:
function getShiftedPixels(b: TBoxArray; time: integer): TPointArray;var  i: integer;  cols1, cols2: TIntegerArray;  tpa: TPointArray;begin  tpa := b.toTPA();  cols1 := getColors(tpa, false);  wait(time);  cols2 := getColors(tpa, false);  for i := 0 to high(tpa) do    if cols1[i] <> cols2[i] then result.append(tpa[i]);end;

2. Nice. You could use inbuilt Simba functions to speed up the process.

3. Originally Posted by Daniel
Nice. You could use inbuilt Simba functions to speed up the process.
Wait how would that work? There's just one TPA.

4. I actually think this is a really clever idea, never thought of it before, but as with what Daniel said, is it slow? I could see speed being an issue..

5. Originally Posted by elfyyy
I actually think this is a really clever idea, never thought of it before, but as with what Daniel said, is it slow? I could see speed being an issue..
It's plenty fast for me. I'm using 50ms and it feels instant.

edit: @elfyyy @Daniel
This is on my crappy laptop using
Simba Code:
getShiftedPixels([mainscreen.getBounds()], 100);
Takes about 40ms to get the entire mainscreen, which is only 222k integers to compare in the WORST possible case. It's very easy to reduce that number.

The fact that it's so simple makes me feel both very smart and very stupid. @bonsai This will make auto-coloring so easy.

That's how the motion detect in bonsaifighter works too but I used bitmaps. I also used the "motion colors" to pre-seed the color list.

7. Originally Posted by bonsai

That's how the motion detect in bonsaifighter works too but I used bitmaps. I also used the "motion colors" to pre-seed the color list.
I saw that you used pixelshift but I didn't look thoroughly enough to see exactly what it was doing. I figured you must have been doing something like this. What are the advantages of bitmaps? I was a little confused when I looked at some of the functions in Simba.
I've been running a 150-line combat script with this all day and it can compete with my 1k line auto-color script. It kinda feels wrong..
I'll probably start a new auto-color script using SRL-6 CTS2 functions once I mess with this a bit more.

8. Originally Posted by Citrus
I saw that you used pixelshift but I didn't look thoroughly enough to see exactly what it was doing. I figured you must have been doing something like this. What are the advantages of bitmaps? I was a little confused when I looked at some of the functions in Simba.
I've been running a 150-line combat script with this all day and it can compete with my 1k line auto-color script. It kinda feels wrong..
I'll probably start a new auto-color script using SRL-6 CTS2 functions once I mess with this a bit more.
It's two ways of getting at the same data. I guess it would come down to performance. getcolors is looking at the screen bitmap too. To get best performance, which may be needed, a plugin would be best. That way it can work outside the interpreter.

The problem with motion is it requires the npc to move! And you need to filter out the false results like streams or lights.

For best motion detection you need to look at multiple snaps and keep merging things into a background image. See how cool slacky's demo was in that other thread. That's what you get from background analysis. But of course the second you move it all goes out the window.

Let me know what problems you're having with bitmaps. Here's a bitmap version of your snip. Start it when already logged in:

Simba Code:
program motion;{$DEFINE SMART}{$include_once srl-6/srl.simba}var   orig, current, diff, w, h, x, y: integer;begin   smartPlugins := ['d3d9.dll'];   smartEnableDrawing := true;   SetupSRL();   GetClientDimensions(w, h);   SmartSetEnabled(__smartCurrentTarget, false);   while (true) do   begin      orig := BitmapFromClient(0, 0, w-1, h-1);      wait(60);      current := BitmapFromClient(0, 0, w-1, h-1);      diff := CreateBitmap(w, h);      for x := 0 to w-1 do         for y := 0 to h-1 do            if (FastGetPixel(orig, x, y) <> FastGetPixel(current, x, y)) then               FastSetPixel(diff, x, y, 255);                     smartImage.drawBitmap(diff, point(0, 0));      FreeBitmap(orig);      FreeBitmap(current);      FreeBitmap(diff);   end;end.
Last edited by bonsai; 09-20-2015 at 10:45 AM.

9. Originally Posted by bonsai
It's two ways of getting at the same data. I guess it would come down to performance. getcolors is looking at the screen bitmap too. To get best performance, which may be needed, a plugin would be best. That way it can work outside the interpreter.

The problem with motion is it requires the npc to move! And you need to filter out the false results like streams or lights.

For best motion detection you need to look at multiple snaps and keep merging things into a background image. See how cool slacky's demo was in that other thread. That's what you get from background analysis. But of course the second you move it all goes out the window.

Let me know what problems you're having with bitmaps. Here's a bitmap version of your snip. Start it when already logged in:
Non-movings npcs don't seem to be a problem in RS3. They all move a little even when they're standing still.
Filtering out non-npcs is easy with MM2MS();

I was getting confused by calculatePixelShift(), but your code helped. I did a little demo using this:
Simba Code:
procedure pixels3(b: TBoxArray; time: integer);var  orig, curr, diff: TIntegerArray;  w, h, x, y, i: integer;begin  setLength(orig, length(b));  setLength(curr, length(b));  setLength(diff, length(b));  for i := 0 to high(b) do    orig[i] := bitmapFromClient(b[i]);  wait(time);  for i := 0 to high(b) do    curr[i] := bitmapFromClient(b[i]);  for i := 0 to high(b) do  begin    w := b[i].getWidth();    h := b[i].getHeight();    diff[i] := createBitmap(w, h);    for x := 0 to w-1 do      for y := 0 to h-1 do        if (fastGetPixel(orig[i], x, y) <> fastGetPixel(curr[i], x, y)) then          fastSetPixel(diff[i], x, y, clLime);    smartImage.drawBitmap(diff[i], point(b[i].x1, b[i].y1));    smartImage.drawBox(b[i], false, clBlue);  end;  freeBitmaps(orig);  freeBitmaps(curr);  freeBitmaps(diff);end;

10. Originally Posted by Citrus
Wait how would that work? There's just one TPA.
Disregard what I said. For some reason, I thought GetColors returned a TPA and I didn't bother to check the data types. Geez, it's been a while.

11. @Citrus @Floor66

I've made once aplugin for motion detection, doing exactly the same, and it seems I've never published it on SRL :P So here is it:

CompareBmp.rar

Simba Code:
procedure CompareBmp( BitmapAreaColors1, BitmapAreaColors2 : T2dIntegerArray; MaxSize : integer; var _Result : TPointArray );

Simba Code:
function GetShiftedTPA ( Box : TBox; WaitTime : integer) : TPointArray;var bmp1, bmp2 , w ,h : integer;var BAC1,BAC2 :T2dIntArray;beginw := Box.x2 - Box.x1 - 1;h := Box.y2 - Box.y1 - 1;bmp1 :=  BitmapFromClient(Box.x1 , Box.y1 , Box.x2 , Box.y2); BAC1 :=  GetBitmapAreaColors(bmp1,0,0,w,h);wait (WaitTime);bmp2 :=  BitmapFromClient(Box.x1 , Box.y1 , Box.x2 , Box.y2); BAC2 :=  GetBitmapAreaColors(bmp1,0,0,w,h);CompareBmp(BAC1,BAC2,(w*h) div 2,Result);   //  (w*h) div 2  - means MaxSize is a half of boxFreeBitmap(bmp1);FreeBitmap(bmp2); end;

* What is MaxSize parameter? Sometimes it happens that colors in the whole screen are shifted e.x. due to some random overall brightness change. In this erroneousness situation function will detect that number of shifted pixels is too big and it will return an empty array ( of the length of 1 ).s
Last edited by bg5; 09-22-2015 at 10:10 AM.

12. Very interesting! I'm going to do some benchmarking :-)

13. Originally Posted by bg5
@Citrus @Floor66

I've made once aplugin for motion detection, doing exactly the same, and it seems I've never published it on SRL :P So here is it:

CompareBmp.rar

Simba Code:
procedure CompareBmp( BitmapAreaColors1, BitmapAreaColors2 : T2dIntegerArray; MaxSize : integer; var _Result : TPointArray );
Simba has bultin function named CalculatePixelShift which pretty much just counts the diff pixels between 2 bitmaps (there are a few others methods for this purpose in simba swell). So I am not sure what good this will do.

14. Originally Posted by slacky
Simba has bultin function named CalculatePixelShift which pretty much just counts the diff pixels between 2 bitmaps (there are a few others methods for this purpose in simba swell). So I am not sure what good this will do.
It doesn't count pixels, it returns TPA. TPA can be used then for further processing, much better and more flexible option then simple number of pixels on output (as OP mentioned).
Last edited by bg5; 09-22-2015 at 05:43 PM.

15. Originally Posted by bg5
It doesn't count pixels, it returns TPA. TPA can be used then for further processing, much better and more flexible option then simple number of pixels on output (as OP mentioned).