SA-MP Forums Archive
How can I detect the closest object? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How can I detect the closest object? (/showthread.php?tid=420093)



How can I detect the closest object? - Denying - 03.03.2013

Just a little not at the beginning: I searched for a tutorial for this everywhere and could not find.

My question is how can I detect the closest created object to me?

Let's say I made a command which is /make atm, the command creates an ATM object at the player pos, but let's say the player did not notice where he was standing or anything and the ATM is not at the correct place..
What I want to do is to create a /remove atm command but I do not know how to detect the closest ATM.

Thank you in advance.


Re: How can I detect the closest object? - Kyle - 03.03.2013

Loop the object co-ordinates through an array, then save the closest object id by comparing distances.


Re: How can I detect the closest object? - Denying - 03.03.2013

Does that mean I will have to save every object's coordinates globaly and seperatly?


Re: How can I detect the closest object? - Denying - 03.03.2013

I can't think of a way to make it dynamic as I want, what I mean is when I save the object's ID I will constantly have to change the variable which I save in, else it would delete and replace the object ID or whatnot.. Can anyone just give me a suggesstion of how to do it? I will figure out the rest.

I just want to be able to /make atm, and then /remove atm to the closest ATM.. any ideas?


Re: How can I detect the closest object? - ¤Adas¤ - 03.03.2013

This function might help you.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ) return floatsqroot(floatadd(floatpower(floatsub(X, PointX), 2.0), floatadd(floatpower(floatsub(Y, PointY), 2.0), floatpower(floatsub(Z, PointZ), 2.0))));
You just compare the distance between you and all objects, then you can choose the nearest one.


Re: How can I detect the closest object? - Denying - 04.03.2013

Does that mean I will have to know each and every mapped object coordinates and compare them?