SRL Archive - Help and Support

InTriangle and FixMouse


FrÕzÑ_§ÕµL

2008-01-09 03:58:39

Greetings!
I am creating… well attempting anyway, probably out of my league… a procedure that moves the mouse a certain amount depending on the distance and direction of the flag when an object is clicked, this is in order to keep the mouse on a tree. I have used InTriangle, and split the minimap into 4 segments. However there are two things I would like to know:

1. When you use FlagDistance, does it get the flag from its top or where? Because I need the bottom, so I have put it as x - 12.

2. It takes too long for SCAR to complete :p anyone got some ideas of how to speed the following up? (I am up for using point in box, anything, just need it to complete lol)


//minimap travels 4 pixels per second - probably useless.
//x dist per mm pixel is 7.6 ?
//y dist per mm pixel is 17.3 ?
//Replaced both of the above with 1.5 for testing as they went massive lol. Still trying to find the right number.

Procedure FixMouse;
var
Dist : Integer;

Begin
if (FindColor(x, y, 255, 559, 0, 735, 166)) then //FlagDistance, needed to use the x and y from FindColor.
Begin
DecEx(x, 12);
Dist := Distance(x, y, MMCX, MMCY);
end;
//Clicked n-e
if InTriangle(x, y, MMCX, MMCY, (MMX1 + MMX2)/2, MMY1, (MMY1 + MMY2)/2, MMX2) then
Begin
GetMousePos(x, y);
MMouse(x - Round(Dist*1.5), y + Round(Dist*1.5), 0, 0);
Flag;
Exit;
end;
//Clicked e-s
if InTriangle(x, y, MMCX, MMCY, (MMY1 + MMY2)/2, MMX2, (MMX1 + MMX2)/2, MMY2) then
Begin
GetMousePos(x, y);
MMouse(x - Round(Dist*1.5), y - Round(Dist*1.5), 0, 0);
Flag;
Exit;
end;
//Clicked s-w
if InTriangle(x, y, MMCX, MMCY, (MMX1 + MMX2)/2, MMY2, (MMY1 + MMY2)/2, MMX1) then
Begin
GetMousePos(x, y);
MMouse(x + Round(Dist*1.5), y - Round(Dist*1.5), 0, 0);
Flag;
Exit;
end;
//Clicked w-n
if InTriangle(x, y, MMCX, MMCY, (MMY1 + MMY2)/2, MMX1, (MMX1 + MMX2)/2, MMY1) then
Begin
GetMousePos(x, y);
MMouse(x + Round(Dist*1.5), y + Round(Dist*1.5), 0, 0);
Flag;
Exit;
end;
Flag;
end;

As you can see, most of the InTriangle's are the same, the only difference is the +'s and -'s… so a case might be possible… but I'm not sure how to do a case of InTriangle lol?

n3ss3s

2008-01-09 05:49:26

I can't go test this, login server offline, but something like this:

Function FindFlag(Var X, Y: Integer): Boolean;
Var
TPAA: Array of TPointArray;
R: TPointArray;
Begin
FindColorsSpiralTolerance(MMCX, MMCY, R, 255, MMX1, MMY1, MMX2, MMY2);
FilterPointsPie(R, 1, 360, 1, 65, MMCX, MMCY);
TPAA := SplitTPA(R);
SortATPASize(TPAA, True);
Try
Result := MiddleTPAEx(TPAA[0], X, Y);
Except
Writeln('FLAG NOT FOUND.');
End;
End;


Procedure FixMouse;
Begin
Repeat
If FindFlag(X, Y) Then
Begin
Dx := MMCX - X;
Dy := MMCY - Y;
Z := ArcTan(Dy / Dx);
GetMousePos(mX, mY);
rX := mX + Round(2 * Cos(Z));
rY := mY + Round(2 * Sin(Z));
MoveMouse(rX, ry);
End Else
Break;
Until(Not(FlagPresent));
End;

Should in theory work, just gotta adjust couple values there..

Santa_Clause

2008-01-09 08:32:44

N3ss3s, you still managed to use a TPA to find the colour 255 on minimap…weird. Nice idea by the way.

n3ss3s

2008-01-09 09:26:54

Lol, if I'd use FindColor for it, I'd get the most top-left one, if I'd use spiral, I'd get the one closest to me, I want the middle of the flag :)

FrÕzÑ_§ÕµL

2008-01-09 13:09:31

… Wow I have no idea lmao but I'll try it out, thank you :)

Edit: Sorry n3ss3s but you have made it that while flag is present it slides the mouse on a perfect little angle way off into the mountains until MR Flaggy goes home for the night :rolleyes: that means that walking and running to an object will cause the mouse to go different distances, while the screen shift is actually the same… Nice try, looked good :p and I can't really edit cause I don't know how to use ArcTan, cos or sin :confused:

I am going to try something using your FindFlag and InAngle, as that is easier than an entire traingle I am sure :) plus allows me to narrow it to slots of 45' with out hurting my head :D (where is the degrees symbol on a keyboard :o)

ZephyrsFury

2008-01-09 21:20:29

The top of the flag is 14 pixels above the bottom of the flag.


function FindTheFlag(var x, y: Integer): Boolean;
begin
if (FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2)) then
begin
Result := True;
y := y + 14;
end;
end;

function FindFlagDistance: Integer;
var
Tx, Ty: Integer;
begin
if (FindTheFlag(Tx, Ty)) then
Result := Distance(MMCX, MMCY, Tx, Ty)
else Result := -1;
end;

Oh and with your procedure you're trying to make. I don't fully understand it. Maybe you could clarify it a bit.

FrÕzÑ_§ÕµL

2008-01-09 21:24:39

My purpose is when you click a tree the screen shifts and the mouse movess off tree and script has to re-search and re-click. Also I have my yew cutter move to the other tree as soon as you finish cutting one for my next version, so you can understand that can cause some problems without this procedure. Well I have made this now… not tested yet :
{*************************************************************************************************
Procedure FixMouse;
By: Fr0zN_S0uL
Description: Moves mouse based on flag distance and direction.
*************************************************************************************************}

Procedure FixMouse;
var
MMCenter : TPoint;
A1, A2 : Extended;

Begin
If Not(FindFlag(x, y)) then exit;
Dist := FlagDistance;
MMCenter := IntToPoint(MMCX, MMCY);
A1 := 0;
A2 := 45;
Repeat
if InAngle(MMCenter, A1, A2, 72, 72, x, y) then
Begin
case A1 of
0: Begin
fx := 0 - Round(1.5*Dist);
fy := 3*Dist;
end;
45: Begin
fx := 0 - 3*Dist;
fy := Round(1.5*Dist);
end;
90: Begin
fx := 0 - 3*Dist;
fy := 0 - Round(1.5*Dist);
end;
135: Begin
fx := 0 - Round(1.5*Dist);
fy := 0 - 3*Dist;
end;
180: Begin
fx := Round(1.5*Dist);
fy := 0 - 3*Dist;
end;
225: Begin
fx := 3*Dist;
fy := 0 - Round(1.5*Dist);
end;
270: Begin
fx := 3*Dist;
fy := 0 - Round(1.5*Dist);
end;
315: Begin
fx := 0 + Round(1.5*Dist);
fy := 0 - 3*Dist;
end;
end;
GetMousePos(x, y);
MMouse(x + fx, y + fy, 2, 2);
Break;
end;
IncEx(A1, 45);
IncEx(A2, 45);
until(A1 = 360);
Writeln('Fixed at ' + FloatToStr(A1) + ' Degrees');
FFlag(0);
end

Special Ed

2008-01-09 21:37:25

If the above didn't make sense look at it this way…

  • Your 5 squares away from the tree…
  • You click on the Tree…
  • Your screen moves and your character moves towards the tree, but your mouse doesn't
  • Now your mouse isn't where the tree is now because it doesn't move.

This procedure is "hopefully" going to make the mouse move… as the character does, so you don't have to re-find the tree after you move.

ZephyrsFury

2008-01-09 21:42:52

So why are you moving the mouse on the minimap?

n3ss3s

2008-01-10 07:55:10


Edit: Sorry n3ss3s but you have made it that while flag is present it slides the mouse on a perfect little angle way off into the mountains until MR Flaggy goes home for the night that means that walking and running to an object will cause the mouse to go different distances, while the screen shift is actually the same… Nice try, looked good and I can't really edit cause I don't know how to use ArcTan, cos or sin


Hehe, yes, its because of the values, it needs the

"If Degrees(z) < 0 Then Z := Z + 360;"

and other stuff done to the angles… (the 360 was just an example, can't remember was it 90 or 360..)


@Zephyr:
GetMousePos(x, y);


Who talked about MM?


Also, fr0zn, SRL contains the FlagDistance function :p

ZephyrsFury

2008-01-10 08:00:23

From: n3ss3s
Hehe, yes, its because of the values, it needs the

"If Degrees(z) < 0 Then Z := Z + 360;"

and other stuff done to the angles… (the 360 was just an example, can't remember was it 90 or 360..)


@Zephyr:

Who talked about MM?


Also, fr0zn, SRL contains the FlagDistance function :p


Yea yea I understand now. The problem with FlagDistance is it measures the distance from the colour 255 which is the top of the flag.

And regarding what you're trying to do, I think you should look at SB100's PowerSkills. His UpdateCoords procedure does something similar to what you're trying to do. The only thing is the mouse doesn't follow the tree but I wouldn't think I legit player would follow the tree anyway would they?

n3ss3s

2008-01-10 08:06:25

Lol, I'm just asking that are you sure you don't want to use the traditional way? :p

You knew you can just do

FindColorSpiralTolerance(ReturnX, ReturnY, Color, ReturnX - 20, ReturnY - 20, ReturnX + 20, ReturnY + 20, 5);


While FlagPresent


:p

No need for minimap shizzle, I just expected you know that works even better x)

FrÕzÑ_§ÕµL

2008-01-11 13:28:27

Yea I just gave up :p by the time the maximum of 2000ms it takes for the flag to disappear SCAR hasn't even passed my first loop :rolleyes: so I'll just give up. I'll check out that UpdateCoords though, thanks everyone for the help :)

n3ss3s

2008-01-11 14:08:40

I'll check out that UpdateCoords though


just do


procedure track(var StartX, StartY; Color, Tol: Integer);
Begin
while FlagPresent Do
FindColorsSpiralTolerance(StartX, StartY, Color, x1, y1, x2, y2, Tol);
end;

R0b0t1

2008-01-11 19:29:02

Every few milliseconds, subtract from the mouses position. Every 50 milliseconds, check what color the mouse is on… Would that work?