SRL Archive - Help

Walking to the closest Point?


Mat

2012-03-21 03:05:24

I have say 10 SPS Points and the character spawns around the whole area, how would I have it walk to the closest one to it?
Point (1)

Point(2)
You(2.7)
Point(3)
you'd want it to go to three, is this possible?
Thanks
Mat

Flight

2012-03-21 03:39:10

Gimme a second and I'll whip something up for ya.

Edit:
Give this a whirl:

Function SPS_GetClosestPoint(PArr: TPointArray): TPoint;
Var
Me: TPoint;
begin
Me := SPS_GetMyPos;
SortTPAFrom(PArr, Me);
Result := PArr[0];
end;

Daniel

2012-03-21 03:44:27

From: Flight
Gimme a second and I'll whip something up for ya.


One second is well over.

Flight

2012-03-21 03:47:24

From: Daniel
One second is well over.


Atleast it wouldn't take me an hour. :garfield: I'm gonna get on the IRC, we can fight there noob.

Mat

2012-03-21 09:18:51

From: Flight
Gimme a second and I'll whip something up for ya.

Edit:
Give this a whirl:

Function SPS_GetClosestPoint(PArr: TPointArray): TPoint;
Var
Me: TPoint;
begin
Me := SPS_GetMyPos;
SortTPAFrom(PArr, Me);
Result := PArr[0];
end;

Can you expalin how it works? please <3

Er1k

2012-03-21 09:40:09

SortTPAFrom returns the sorted TPointArray, closest to your position first. Array[0] is the answer to your question

Flight

2012-03-21 09:51:57

From: Er1k
SortTPAFrom returns the sorted TPointArray, closest to your position first. Array[0] is the answer to your question


Yep pretty much.

First, we define our own player's position on the MM (Me := SPS_GetMyPos), this will be a TPoint. Next, we use the nifty little procedure "SortTPAFrom" which has 2 parameters: the first is the given TPointArray. Two steps are done here, first you feed your TPA into the procedure and in that same parameter your TPA will be given back to you, but in a sorted (by distance) form. The second parameter is the point you want to start the sorting from. In this case we use our player's location (Me).

At this point, our TPointArray has been sorted by distance from our player. And as you know, every array starts at 0, with 0 being the first in the array. So… PArr[0] must be the closest point to our player because its first on our sorted array. The second closest point would be PArr[1], third would be PArr[2], ect… You get the idea. ;)

Sin

2012-03-21 09:54:03

Woo, thanks Flight, unknowingly you solved the final part of my puzzle in SPS walking for my Frost Dragons script <3

Mat

2012-03-21 10:56:54

Sweet thanks flight this is gonna come in handy for changing the way my abyss script works <3

Flight

2012-03-21 12:15:21

From: Mat
Sweet thanks flight this is gonna come in handy for changing the way my abyss script works <3


I look forward to seeing that. I noticed you removed it from your thread so I posted a reply as why you removed it. I was hoping to use it and perhaps help you speed it up where possible.

Mat

2012-03-21 15:20:20

From: Flight
I look forward to seeing that. I noticed you removed it from your thread so I posted a reply as why you removed it. I was hoping to use it and perhaps help you speed it up where possible.

Sure I'll figure out how to add this function and then re update.

Wyn

2012-03-21 15:26:25

From: Sin
Woo, thanks Flight, unknowingly you solved the final part of my puzzle in SPS walking for my Frost Dragons script <3


Don't you release it lol.


Seriously, Don't.

Mat

2012-03-21 16:02:42

Lol^^ Flight the main Problem is the object finding inside abyss I am finding them but because I'm having to check for all of them its rather slow, any idea's of speeding it up?
Well Prob not you need to see the code :P