Log in

View Full Version : SPS Position Tolerance?



Archaic
04-07-2012, 07:32 AM
I was just wondering: is there a way to add "position tolerance" to an SPS position? I.E. if I call the function:

SPS_GetMyPos;

and it gives me a value of:

1010, 1010

is there a way that I could create a function that returns true if my position is within + or - x units of a target position?

For instance if I have a target point of 1000, 1000 and GetMyPos returns a value of 1010, 1010 like above, how can I create a function that returns true because the point 1010, 1010 is within 10 units of the wanted position?

(More specifically if I'm using something along the lines of:

SPS_GetMyPos;
Location := toStr(SPS_GetMyPos);

if (Location = '(1000, 1000)') then
...
)

I know about regular SPS tolerance, but would that work in this instance perhaps?

m34tcode
04-07-2012, 07:34 AM
No, SPS returns the first close match, which is why in some places it will be off. It depends on whether the area your standing in when getMyPos is called, is 'Unique' enough to be recognised

EDIT: oh never mind I misunderstood you. Yes you can. Distance(x1,y1,x2,y2); Just plug your point, and the point to check for into that, and of the result is <2-3 your nearby.

eska
04-07-2012, 07:38 AM
I'm not quite sure it's what you are looking for, but this is how I detect if I'm in a certain area (prison) on ape atoll.

It's hard coded but you could change it to make it work with different point using parameters.

// *****
// * InPrison : Detect if we are in prison using SPS
// *
function InPrison: Boolean;

var
location: TPoint;
begin
location:= SPS_GetMyPos;

if ((location.x > 2895) and (location.x < 2955) and (location.y < 5530)
and (location.y > 5465)) then
Result:= true
end;


Heres the function I think you are looking for. I felt like it was cool so I made it very quickly from what I just showed you.
I think I'll need it in my arctic pine script :D

// *****
// * PositionTolerance : Returns true if you are within the tolerance of the
// * point you send in parameter. Usefull if you want to
// * know if you are relatively close to a point.
// *
function PositionTolerance(posX, posY, tol: Integer): Boolean;
var
location: TPoint;
begin
location:= SPS_GetMyPos;

Result:= ((location.x > (posX - tol)) and (location.x < (posX + tol)) and (location.y < (posY + tol))
and (location.y > (posY - tol)));
end;

m34tcode
04-07-2012, 07:40 AM
You could also use PointInBox, with the box being your SPS area, and the point being your current location

Archaic
04-07-2012, 10:01 PM
Thank you guys for the help!

Sir, a function like that is exactly what i was looking for--thanks!:) I'll edit it to my needs--looks awesome!