PDA

View Full Version : [TuT]Using Pixelshift for animation



Flight
02-04-2012, 05:48 AM
I actually quickly wrote this out for one person, briefly explaining how you can use SRL's Pixelshift to detect animation; in this case our own player's animation.
Originally posted here: http://villavu.com/forum/showthread.php?t=72792


Animation detection through Pixelshift
By Flight


I'll give you a crash course on pixelshift, just not using those two functions. First of all, pixelshift, I believe, will count the amount of changing pixels within a certain box region over a certain amount of time. So let's say you wanted to check if your player is doing an animation, so let's use this function: (my own "Is Mining" function)

Function Mining: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(245, 130, 285, 195);
Result := (AveragePixelShift(PBox, 250, 500) > 400);
end;

In this function you can see it uses 'AveragePixelShift' with the parameters (Box, waitPerLoop, maxTime) and returns a boolean (True of False). "Box" is the box region the function will record your pixelshift (change in pixels). "waitPerLoop" I'm not 100% sure, but 250 seems to be just right. "maxTime" is the length of each loop it checks for pixelshift.

Since we're checking for player animation it would only make sense to have the 'Box' we record pixelshift be a box around our player, right? So let's use this box: (245, 130, 285, 195), it's directly around our player. So we have our box region, we have the 'waitPerLoop' (I just leave it 250), and you see I, be default, have 500 as the 'maxTime', which means each length of recording pixelshift will be 500 milliseconds (half a second).

The function 'AveragePixelShift' will return an integer, which will be our average amount of pixelshift within that box in 500 milliseconds. In the function I provided it will check if that number is over 400, in which case the function would return True that our player is using the Mining animation. Should that number be under 400 then it'll return false because chances are we're just standing idle, right?

Anyways, I hope that helps. Here's a test script I use to constantly print out the player's pixelshift. You can use it to determine what's a good number to use to detect if you're doing a certain animation:

program PrintMyPixels;
{$DEFINE SMART}

{$i SRL/srl.simba}

Procedure DebugShiftCount;
var
PBox: TBox;
begin
PBox := IntToBox(245, 130, 285, 195);
Writeln(IntToStr(AveragePixelShift(PBox, 250, 500)));
end;


begin
Smart_Server := 86;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
setupSRL();

Repeat
DebugShiftCount;
Until(False);
end.


~Cheerz

I Am Legend
02-04-2012, 06:07 AM
thanks

RyGuy
02-04-2012, 06:13 AM
Thanks Flight! ^^

NickMystre
02-04-2012, 07:16 AM
"waitPerLoop" I'm not 100% sure, but 250 seems to be just right.

For those of us (that would be me and any others that would like to join me) that still battle to take in the finer details of the animation includes, why don't we just ask Coh3n and/or marpis to explain these for us?

E: On the grand scale of things - I can appreciate that perhaps animation.simba is not the most complex coding out there, but I am willing to bet that there are many who would like a blow by blow breakdown on the functions.

Kyle Undefined
02-05-2012, 08:18 PM
Awesome tutorial Flight! I love PixelShift!

poopy2177
02-05-2012, 09:12 PM
Just what I was looking for! ty

NexPB
02-13-2012, 09:26 PM
Great tut man :D

Inception
02-13-2012, 09:27 PM
This is a great tutorial!

Jagex_Fagex
02-22-2012, 10:43 AM
Awesome, very helpful!

EDIT: Also, 650 seems to work better than 400 for the mining function

bable fittle
02-29-2012, 09:27 PM
This is what I have been waiting for to finally make a firemaking script! Thanks!

riwu
03-20-2012, 12:21 PM
just wondering..under what situation would this be more efficient than using GetXPBar?

masterBB
03-20-2012, 12:24 PM
just wondering..under what situation would this be more efficient than using GetXPBar?

When you are cutting magic trees. It may take a minute before you get a log, this one will be faster.

Flight
03-20-2012, 12:53 PM
When you are cutting magic trees. It may take a minute before you get a log, this one will be faster.

Yep yep, rocktails / sharks as well. Low-level'ed woodcutters chopping high level trees, low-level'ed miners mining high level ores, ect...

riwu
03-20-2012, 12:53 PM
When you are cutting magic trees. It may take a minute before you get a log, this one will be faster.

ah thx +Rep! basically any animating activity that gains multiple xp/click.

eska
03-22-2012, 06:47 AM
Pixel shift seems so scary at first but now it looks ridiculously easy. Maybe you made it look easier than it is though :p

P1nky
03-22-2012, 07:10 AM
Great to use, currently using on a upcoming script. And this tut explains it all! Good job:)

Sassakill
04-18-2012, 12:29 PM
Thank you Flight!
Helped me out a great bit! :D

Era Xz
04-18-2012, 08:07 PM
Dam genius! Thanks a lot ;)
This will replace my poor is walking function which checked for SPS location every sec

Oxygen
04-18-2012, 08:15 PM
Great tutorial!

Sirenia
05-20-2012, 01:41 PM
Helped alot!

cadet54
05-25-2012, 07:46 PM
Thanks very much, another method of checking if the character is cutting, mining fishing or what ever and a few other things that can come in handy.
Thanks again :)

Mat
06-20-2012, 08:35 PM
I'm still using this today :), I keep attempting to use it, now I am going to work on it :D
Thanks Flight :)
Mat

Footy
07-26-2012, 06:30 PM
Very very useful! Thanks flight!

Etrnl Fear
07-29-2012, 04:51 PM
Thanks for the tutorial!

But, would the variables (245, 130, 285, 195) need to be changed with the RS toolbar being imbedded into the RS applet?

Flight
07-30-2012, 01:34 AM
Thanks for the tutorial!

But, would the variables (245, 130, 285, 195) need to be changed with the RS toolbar being imbedded into the RS applet?

Nah, the current SRL & Simba already have adjustments in place; these parameters remain correct.

Etrnl Fear
07-31-2012, 01:54 AM
Sweet.

Thanks again. :)
+Rep

QQu
07-31-2012, 09:59 AM
Nice!

I still can't get it to work for chopping.. something like look for the tree (object) after the player stops the chopping animation. Anyone?

litoris
07-31-2012, 10:04 AM
Nice!

I still can't get it to work for chopping.. something like look for the tree (object) after the player stops the chopping animation. Anyone?

What part can you not get to work? If it can't detect when it's chopping, get the average pixelshift. There was a function for that.

QQu
07-31-2012, 10:45 AM
Function notSmashing : Boolean;
var
PBox : TBox;
begin
PBox := IntToBox(245, 190, 285, 195);
Result := (AveragePixelShift(PBox, 5000, 500) < 300);
end;


Does that seem right? :/

riwu
07-31-2012, 10:52 AM
Function notSmashing : Boolean;
var
PBox : TBox;
begin
PBox := IntToBox(245, 190, 285, 195);
Result := (AveragePixelShift(PBox, 5000, 500) < 300);
end;


Does that seem right? :/
Swap that 5000 with 500, Your waitPerLoop is longer than maxTime.

alucard123
09-26-2012, 01:40 AM
started using it =3 awesome

only problem is when some1 get too close and start atking my character wont move but shhhhhh

mounty
11-23-2012, 05:57 PM
This works great for woodcutting scripts. I've used it in my willow cutter. Works really well after adjusting the threshold. Has some minor problems when standing right next to people or behind large trees, but overall its a pretty handy tool.

Ian
11-30-2012, 01:50 AM
Thanks Flight, I'm using this in my fisher and it works like a charm :)

And that PixelShift finding tool is downright handy! Rep+

Rezozo
11-30-2012, 04:15 AM
Yea, this is where I got my chopping and mining checks from :D
I didn't even see/ read about the pixelshift finding tool. :p
~Rez

rj
12-17-2012, 09:43 PM
Great tut, I got my animation detection working good, but I have one queston, how would I make it click a lot faster after it no longer see's as much pixels shifting?
My code is:
program test;
{$i srl/srl.simba}
const
TREEX=120;
TREEY=81;
TREEX2=382;
TREEY2=226;
Function Choppin: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(249, 134, 277, 180);
Result := (AveragePixelShift(PBox, 200, 300) > 150);
Writeln(IntToStr(AveragePixelShift(PBox, 500, 650)));
end;
Procedure Woodchop;
var
X, Y: Integer;
begin
if (Choppin) then
begin
//writeln('Waiting to stop Cutting');
wait(100);
end else
begin
//writeln('Lets look for a Tree');
if FindColorTolerance(X,Y,12400,TREEX,TREEY,TREEX2,TR EEY2,10)then
MouseSpeed:=15;
mmouse(x, y,1,1);
Wait(350 + Random(150));
ClickMouse(X, Y, mouse_Left);
Wait(500 + Random(700));
end;
end;
begin
repeat
Woodchop;
until (IsKeyDown (114));
end.

Flight
12-18-2012, 02:03 AM
Try this bud:

program test;
{$i srl/srl.simba}

const
TREEX=120;
TREEY=81;
TREEX2=382;
TREEY2=226;

Function Choppin: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(249, 134, 277, 180);
Result := (AveragePixelShift(PBox, 200, 300) > 150);
Writeln(IntToStr(AveragePixelShift(PBox, 500, 650)));
end;

Procedure Woodchop;
var
X,Y: Integer;
begin
if (Choppin) then
begin
//writeln('Waiting to stop Cutting');
wait(100);
end else
begin
//writeln('Lets look for a Tree');
if FindColorTolerance(X,Y,12400,TREEX,TREEY,TREEX2,TR EEY2,10)then
begin
mmouse(x,y,1,1);
ClickMouse2(mouse_left)
WaitFunc(@Choppin, 10, 3000); //Wait for 3 seconds if we've started chopping.
end;
end;
end;

begin
SetupSRL;
MouseSpeed:=15;

repeat
Woodchop;
until (IsKeyDown (114));
end.

count to potato
06-17-2013, 08:06 PM
Could this be used to detect if an item has spawned on the ground in a specific spot? I'm a far way from implementing anything like this but I have been thinking about things scripts I make could accomplish. Thanks for the tut!!!

westkevin12
05-05-2014, 12:08 AM
I actually use this same code for my mining script. it's outdated now tho but going to get it running again.