SRL Archive - Research & Development Lounge

Mousing Moving Objects


Camel

2015-01-30 18:08:48

I've been experimenting around with the mousing procedure we all use. I've modified it to update the position of the point its mousing at while its moving there, allowing me to fairly accurately mouse moving objects.

Before I continue, all credit for this post goes to @Flight and @BenLand100 as they wrote humanwindMouse and I just modified/bastardized it.

Anyway, here is a video of the code doing things. This video has incredibly low quality, you might need to fullscreen it to see what is actually happening.

[video=youtube;D8FHXCZillE]https://www.youtube.com/watch?v=D8FHXCZillE[/video]

Obviously, the air altar isn't moving, i'm just playing with the camera so relative to you its moving. I couldn't find an object that moves around fast enough to show off what this can actually do. But hopefully you get the picture.

Here is all the code used in the video.

This is the modified HumanWindMouse. I pass it a procedure to update the TPoint and I changed a few things in it as well.
procedure Mmoving(xs, ys, gravity, wind, minwait, maxwait, targetArea : Extended; updateP : procedure(var p : TPoint));
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,lastDist,D: extended;
lastX,lastY,MSP,W,TDist: integer;
pointi : TPoint;
T : LongWord;
sqrt2,sqrt3,sqrt5,maxStep,rCnc: extended;
begin
MSP := mouseSpeed;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);

updateP(pointI);
if PointI.x = -1 then
exit;


TDist := distance(round(xs), round(ys), pointI.x, pointI.y);
t := getSystemTime() + 10000;
repeat
if (getSystemTime() > t) then
break;


updateP(pointI);
if PointI.x = -1 then
exit;

dist:= hypot(xs - pointI.x, ys - pointI.y);

wind:= minE(wind, dist);
if (dist < 1) then
dist := 1;

D := (round((round(TDist)*0.3))/7);
if (D > 25) then
D := 25;
if (D < 5) then
D := 5;

rCnc := random(6);
if (rCnc = 1) then
D := randomRange(2,3);

if (D <= round(dist)) then
maxStep := D
else
maxStep := round(dist);

if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
end;

veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (PointI.x - xs) / dist;
veloY:= veloY + gravity * (PointI.y - ys) / dist;

if (hypot(veloX, veloY) > maxStep) then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;

lastX:= round(xs);
lastY:= round(ys);
xs:= xs + veloX;
ys:= ys + veloY;

if (lastX <> round(xs)) or (lastY <> round(ys)) then
moveMouse(round(xs), round(ys));

W := (random((round(100/MSP)))*6);
if (W < 5) then
W := 5;
W := round(W*0.9);
wait(W);
lastdist:= dist;
until(hypot(xs - PointI.x, ys - PointI.y) < 3);

mouseSpeed := MSP;
end;

I also made a procedure to make using the above procedure easier. (just like we do with the actual humanWindMouse)


procedure mMovingObject(button: integer; updateP : procedure(var p : TPoint));
var
randSpeed: extended;
x,y,ms: integer;
begin
if (button = MOUSE_NONE) then
exit;

ms := mouseSpeed;
randSpeed := (random(mouseSpeed) / 2.0 + mouseSpeed) / 10.0;
getMousePos(x,y);

Mmoving(x, y, MOUSE_HUMAN, 5, 10.0/randSpeed, 15.0/randSpeed, 10.0*randSpeed, @updateP);

mouseSpeed := ms;
fastClick(button);
end;

And then the procedure that gives the TPoint for the air altar.

procedure findAltar(var p : TPoint);
var
TPA : TPointARray;
x,y : integer;

begin

findColorsSpiralTolerance(x,y,TPA,13480323,mainscreen.getBounds(),7,colorSetting(2, 0.45, 0.85));
if (Length(TPA) < 1) then
begin
p.x := -1;
end;

p := middleTPA(TPA);
end;

And the program.


begin
SetupSRL();
mMovingObject(MOUSE_RIGHT,@findAltar);
end.

This is just the bare stuff, there is absolutely no failsafes in this, it just assumes the altar is in vision. It doesn't check mouseover text or really anything. To use this in a script, it would have to be modified to be able to deal with failure.


So yeah, I think this has potential for use in some things. Especially when its just an object with a very unique color.

KeepBotting

2015-01-30 18:17:25

Oh, wow. This is cool. Rep+, will use for sure.

Hoodz

2015-01-30 18:20:05

awesome!

Zef Style

2015-01-30 18:34:04

this is a very very nice idea, I will be using it :)…I was too lazy to make it myself

cosmasjdz

2015-01-31 01:02:43

Very nice. After work going to try it out. If it works then biggest flaw in my opinion which getting banned was not finding or failing toomuch on moving objects while going to waka tree and fairy rings would be fixed. Also in some ocassions drags finding, but made it way faster using mmtoms to generate search boxes for drag i want to get, so now not picking random or closes tpa in screen but mostly closest drag in space.

Zef Style

2015-01-31 20:59:16

is it possible to pass parameters like this?

for example:
mMovingObject(MOUSE_RIGHT,@findAltar(p));

I get errors..

slacky

2015-01-31 21:10:43

From: Zef Style
is it possible to pass parameters like this?

for example:
mMovingObject(MOUSE_RIGHT,@findAltar(p));

I get errors..

No.

KeepBotting

2015-01-31 21:12:39

From: Zef Style
is it possible to pass parameters like this?

for example:
mMovingObject(MOUSE_RIGHT,@findAltar(p));

I get errors..
I don't think so - you should be passing a function that outputs the TPoint 'p' so there's no need for you to pass the param to the function that you're already passing to mMovingObject()

E: Ninja'd by slacky

Zef Style

2015-01-31 21:21:09

I would like to be able to pass it the first found coords of the object, then have the @find function search for that object in a box that updates while the mouse moves..instead of searching the entire screen..

KeepBotting

2015-01-31 21:34:47

From: Zef Style
I would like to be able to pass it the first found coords of the object, then have the @find function search for that object in a box that updates while the mouse moves..instead of searching the entire screen..

You could do that internally in mMovingObject(), no? Add a new parameter, 'bounds' or similiar, it'd be a TBox. You'd have to search the whole screen first, but then update the TBox continually with the new bounds and search in there.

Zef Style

2015-01-31 22:59:01

From: KeepBotting
You could do that internally in mMovingObject(), no? Add a new parameter, 'bounds' or similiar, it'd be a TBox. You'd have to search the whole screen first, but then update the TBox continually with the new bounds and search in there.


that will not work mMovingObject just passes the @find to windmouse, the only way to do it would be to put it into the custom wind mouse..however, that would be quite inconvenient to have say 2-3 custom wind mouse functions in one script..haha

Olly

2015-02-01 03:16:06

You have to be careful, your find() procedure could use quite some time (in terms of a mouse wait) which would change how the mouse is handled. A regular mouse wait uses something like 5-16ms, if you add another 16ms on that you're adding alot more wait time between the mouse steps.

I was also doing something like this but with multithreading to find my moving NPC. :)

cosmasjdz

2015-02-01 03:55:05

From: Olly
You have to be careful, your find() procedure could use quite some time (in terms of a mouse wait) which would change how the mouse is handled. A regular mouse wait uses something like 5-16ms, if you add another 16ms on that you're adding alot more wait time between the mouse steps.

I was also doing something like this but with multithreading to find my moving NPC. :)


What you exzactly mean of multithreading? used something like sharetabs plugin in one to track object in another update mouse pos? I really need to make something like this to catch non unique object while running and rotating camera at once..

footballjds

2021-01-16 16:06:49

From: Olly
You have to be careful, your find() procedure could use quite some time (in terms of a mouse wait) which would change how the mouse is handled. A regular mouse wait uses something like 5-16ms, if you add another 16ms on that you're adding alot more wait time between the mouse steps.

I was also doing something like this but with multithreading to find my moving NPC. :)


Is multi-threading possible with SIMBA (for OSRS)(without a plugin)

Or are you just complaining?