PDA

View Full Version : [OGL] Walking v2



Swag Bag
07-14-2015, 10:28 PM
Over my vacation I took Ross; walking procedure https://villavu.com/forum/showthread.php?t=113404 and looked at it some more. My problem with it was that when walking to places the randomness would compound and I would end up further off track than I wanted. However without it I would click the same spots every time. I had a go at it and came up with a new approach. So here goes:
procedure tileWalkInterval(point : TPoint; r : Integer);
var
stepSize, rx, ry, toGoX, toGoY : Integer;
next : TPoint;
begin
stepSize := r + 7;
toGoX := point.X;
toGoY := point.Y;

repeat
rx := random(-r, r);
ry := random(-r, r);
next := [sgn(toGoX) * (min(abs(toGoX), stepSize)) + rx, sgn(toGoY) * (min(abs(toGoY), stepSize)) + ry];

walkTo(next);
waitFlag();

toGoX := toGoX - next.X;
toGoY := toGoY - next.Y;

until (abs(toGoX) <= r) and (abs(toGoY) <= r);
end;
This procedure is designed to walk a set of points or a long distance. It utilizes random numbers to walk different intervals and randomness for each point on the way. The way it works is it takes the point it is walking to and stores it in toGoX and toGoY. As it loops it subtracts what it has walked from toGoX and toGoY and repeats until it reaches its destination. If you plug in 0 for r it will be 100% accurate.

And the sgn function simply returns the sign of a number:
function sgn(x : Integer) : Integer;
begin
if x = 0 then
exit(0)
else
if x > 0 then
exit(1)
else
exit(-1);
end;

And here is the walkTo procedure I use:
procedure walkTo(point : TPoint);
begin
mouse.click(minimap.getScreenPosition(minimap.getL ocalPosition().adjustPosition(point.X, point.Y)), 1);
end;

Here is the waitFlag procedure Ross; wrote that goes with this:
procedure waitFlag;
begin
wait(250);
while (not ogl.getTextures(1275).isEmpty()) do
wait(500);
end;

And finally here is the tileWalk procedure that I modified. This is what you call in your program.
procedure tileWalk(r : Integer; points : TPointArray);
var
i : Integer;
next : TPoint;
begin
for i := 0 to high(points) do
begin
next := points[i];
tileWalkInterval(next, r);
end;
end;

As an example you would use this by calling the tileWalk procedure with your randomness and the array of Points (or point) to walk.
tileWalk(2, [[-3, -10], [-11, -10], [-25, -7], [-8, -16], [12, -12]]);
or you could do
tileWalk(5, [[100, 94]]);

I spent quite a bit of time brainstorming and optimizing the code for this so please let me know what you think about it and if there are any areas I can improve! Thanks again to Ross; for the original code and Clarity; for answering a couple questions.
(Here is my first go at writing the new procedure :D 26426)

srlMW
07-14-2015, 11:18 PM
Really great work man! :norris:

Incurable
07-17-2015, 02:21 AM
Great work mate, and an excellent contribution!

EDIT: I'd recommend turning tileWalk into a boolean function that returns false if it fails for some reason. :)

Swag Bag
07-17-2015, 02:43 AM
I'd recommend turning tileWalk into a boolean function that returns false if it fails for some reason. :)

I thought about it but there's not really any way I can think of that it would fail, unless the user accidentally put in [600000, 9345345] or something and it never stopped?

Obquility
07-17-2015, 02:58 AM
Meh. This is the problem with ogl. My vps does not support it, and I get fps lag on my home machine. Great contribution though, I'm sure this will come in handy sometime.

Swag Bag
07-17-2015, 03:28 AM
Meh. This is the problem with ogl. My vps does not support it, and I get fps lag on my home machine. Great contribution though, I'm sure this will come in handy sometime.

Yes there are problems with ogl, but hopefully it will be supported better in Windows 10 (I have no idea, praying), apparently it runs much smoother in Linux, or with better GPUs. Either way OGL is fun :)

Incurable
07-17-2015, 03:31 AM
unless the user accidentally put in [600000, 9345345] or something and it never stopped?

Which would be user error, but a fail situation nonetheless. I mainly posted that to remind you about failsafes, it's not necessarily needed when using ogLib, but it's good scripting practice and they should still be implemented wherever possible. :)