PDA

View Full Version : [Snippet] SlideMouseUptext



Wardancer
02-17-2013, 07:37 PM
Figured I should start posting some custom functions I wrote. I'll do my best not to spam this forum with them.

First function I'd like to share is, as the name indicates, a mouse function that drags the mouse from one point to another and stops if it finds a particular uptext. I wrote this function out of laziness (would've had to make like 5 different and extremely precise TPA functions instead) and I quickly found out that it has a few interesting uses. Obviously, for the SlideMouseUpText function to work, I had to slightly edit the other functions called by it:


function WindMouseUptext(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: extended; Uptext : String) : Boolean;
var
veloX, veloY, windX, windY, veloMag, dist, randomDist, lastDist, step: extended;
lastX, lastY: integer;
sqrt2, sqrt3, sqrt5: extended;
begin
try
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
while hypot(xs - xe, ys - ye) > 1 do
begin
if IsUpText(Uptext) then
begin
Result := True;
Exit;
end;
dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, 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;
if (maxStep < 3) then
begin
maxStep:= random(3) + 3.0;
end else
begin
maxStep:= maxStep / sqrt5;
end;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - 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));
step:= hypot(xs - lastX, ys - lastY);
wait(round((maxWait - minWait) * (step / maxStep) + minWait));
lastdist:= dist;
end;
if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));
except
end;
end;

function MMouseUptext(x, y, rx, ry: integer; Uptext: string) : Boolean;
var
cx, cy: integer;
randSpeed: Extended;
{$IFDEF UseLaptopMouse}
seg, e, f, g, nx, ny, hypo: Integer;
a, b, c: Extended;
Miss: Boolean;
{$ENDIF}
begin
GetMousePos(cx, cy);
{$IFDEF UseLaptopMouse}
miss := (Random(LMouse_MissChance) = 0);
e:= 0;
a:= x - cx;
b:= y - cy;
c:= Pow(a,2) + Pow(b,2)
hypo:= Round(Sqrt(c));
case hypo of
0: Exit;
1..225: seg:=1;
226..600: seg:= Random(2) + 1;
601..1800: seg:= random(3) + 2;
else seg := 5;
end;
f := Round( a / seg);
g := Round( b / seg);
repeat
if IsUpText(Uptext) then
begin
Result := True;
Exit;
end;
Wait(30 + random(50));
{Begin: Modified from MMouse by Benland100}
randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
getMousePos(cx,cy);
nx:= (cx + (f * e)) + random(rx);
ny:= (cy + (g * e)) + random(ry);
{End: Modified from MMouse by Benland100}
if Miss then
begin
nx:= nx + RandomRange(rx, rx * 2);
ny:= ny + RandomRange(ry, ry * 2);
end;
WindMouse(cx,cy,nx,ny,11.0,8.0,10.0/randSpeed,12.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
e:= e + 1;
until(e = seg);
GetMousePos(cx, cy);
if not PointInBox(Point(cx, cy), IntToBox(x, y, x + rx, y + ry)) then
begin
Wait(30 + random(30));
WindMouse(cx,cy,(x + random(rx)),(y + random(ry)),11.0,6.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
end;
{$ELSE}
randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
X := x + random(rx);
Y := y + random(ry);
if WindMouseUptext(cx,cy,x,y,9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed,Uptext) then
Result := True;
{$ENDIF}
end;

function SlideMouseUptext(StartX, StartY, SRandX, SRandY, EndX, EndY, ERandX, ERandY: Integer; Uptext: String) : Boolean; //Finally it
var
j : Integer;
begin
MMouse(StartX, StartY, SRandX, SRandY);
Wait(150 + Random(20));
j := MouseSpeed;
MouseSpeed := 5 + Random(5);
if MMouseUptext(EndX, EndY, ERandX, ERandY, Uptext) then
Result := true;
MouseSpeed := j;
end;


Of course, a lot of things can be edited based on what you need. As some might see, it isn't designed for the laptop mouse, but very little change would need to be done for it to work. One last note, I don't suggest using HumanMMouse for this function as it curves a lot and pretty much ruins your line.