Author Topic: Detecting when a player is within a certain distance of a Container Search  (Read 603 times)

I need to detect wether or not Players are a certain distance from a container search and then play a sound for that player, I am using this for a gun fire distance effect, If anyone thinks of a better way to this do tell.

Just make a larger search only for players and check the distance for each?

I guess it depends on the size you're thinking of, at some point it might be more efficient to loop over all clients and see if they have players.

I'm not looking for extreme distances, Just about 60 stud radius, However I cannot find out how to detect the radius a player is from the center of the Search.

You dont need to do a container search; just do a client loop and calculate the distance between the client's player and the player shooting. Based on said distance, then play the requisite sound on each client.

I'm not looking for extreme distances, Just about 60 stud radius, However I cannot find out how to detect the radius a player is from the center of the Search.

If the player was found by the search (using containerSearchNext()) then just call containerSearchCurrDist() to get the distance.

If you want to get the distance between some random position and a player, use vectorDist(%center, %player.getPosition())