How can I detect the closest object?
#1

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.
Reply
#2

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

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

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?
Reply
#5

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.
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)