View Single Post
fakuivan
Senior Member
Join Date: Nov 2015
Old 04-07-2017 , 08:58   Re: Detect Player is near to another player
Reply With Quote #5

Quote:
Originally Posted by Mitchell View Post
You could do a multidimensional array:
bool plyNearAnother[MAXPLAYERS+1][MAXPLAYERS+1];
Then OnPlayerRunCmd store the m_vecOrigin of the client
then loop through the rest of the clients and compare the positions together using GetVectorDistance to get their distance.
If plyNearAnother[client][other] == true && distance > MaxDistance: // Player left the distance of the other.
If plyNearAnother[client][other] == false && distance <= MaxDistance: // Player is now close to the other player.
You might want to compare the distance as a power of 2, to avoid potentially doing (MAXPLAYERS+1)*(MAXPLAYERS+1)*10 square roots a second.
__________________

Last edited by fakuivan; 04-07-2017 at 10:33.
fakuivan is offline