Raised This Month: $18 Target: $400
 4% 

Detect Player is near to another player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 02-14-2017 , 17:00   Detect Player is near to another player
Reply With Quote #1

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
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-14-2017 , 18:02   Re: Detect Player is near to another player
Reply With Quote #2

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.
Mitchell is offline
starsfan
BANNED
Join Date: Apr 2017
Location: Texas
Old 04-05-2017 , 23:06   Re: Detect Player is near to another player
Reply With Quote #3

Quote:
Originally Posted by Papero View Post
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?
starsfan is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 04-06-2017 , 13:25   Re: Detect Player is near to another player
Reply With Quote #4

Maybe but i saw that you are banned then...
I wasn't working on that project xD
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 04-07-2017 , 09: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 11:33.
fakuivan is offline
SHUFEN
Senior Member
Join Date: Jun 2014
Location: Japan, Tokyo
Old 04-07-2017 , 13:53   Re: Detect Player is near to another player
Reply With Quote #6

Quote:
Originally Posted by fakuivan View Post
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.

Last edited by SHUFEN; 04-07-2017 at 13:54.
SHUFEN is offline
Send a message via Skype™ to SHUFEN
fakuivan
Senior Member
Join Date: Nov 2015
Old 04-07-2017 , 21:24   Re: Detect Player is near to another player
Reply With Quote #7

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.
__________________

Last edited by fakuivan; 04-07-2017 at 21:24.
fakuivan is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 04-07-2017 , 21:30   Re: Detect Player is near to another player
Reply With Quote #8

Quote:
Originally Posted by fakuivan View Post
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.
Mitchell is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:53.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode