AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Detect Player is near to another player (https://forums.alliedmods.net/showthread.php?t=293917)

Papero 02-14-2017 16:00

Detect Player is near to another player
 
Hi,
Is there a way to do this:

Player A is near to Player B > Do somethink
Player A is no longer near to Player B > Do somethink

Mitchell 02-14-2017 17:02

Re: Detect Player is near to another player
 
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.

starsfan 04-05-2017 22:06

Re: Detect Player is near to another player
 
Quote:

Originally Posted by Papero (Post 2495453)
Hi,
Is there a way to do this:

Player A is near to Player B > Do somethink
Player A is no longer near to Player B > Do somethink

Do you still need help with this?

Papero 04-06-2017 12:25

Re: Detect Player is near to another player
 
Maybe but i saw that you are banned then...
I wasn't working on that project xD

fakuivan 04-07-2017 08:58

Re: Detect Player is near to another player
 
Quote:

Originally Posted by Mitchell (Post 2495463)
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.

SHUFEN 04-07-2017 12:53

Re: Detect Player is near to another player
 
Quote:

Originally Posted by fakuivan (Post 2510057)
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.

We don't need to care load of computations if set false to param3 of GetVectorDistance, i think.

fakuivan 04-07-2017 20:24

Re: Detect Player is near to another player
 
GetVectorDistance' third parameter is ``squared``, if you set it to false, you'll need to square the number that you are comparing against (just once tho). This effectively cuts the number of square roots calculated to 0. That's exactly what I said on the previous post.

Mitchell 04-07-2017 20:30

Re: Detect Player is near to another player
 
Quote:

Originally Posted by fakuivan (Post 2510057)
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.

I never actually gave an code example of GetVectorDistance.


All times are GMT -4. The time now is 11:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.