Raised This Month: $ Target: $400
 0% 

finding if player is near to the area


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FunkyBboy
New Member
Join Date: Nov 2013
Old 11-27-2013 , 18:01   finding if player is near to the area
Reply With Quote #1

Its my first post so i will say hello at thw begining.

Lets say i have list of positions on map (x, y, z and x2, y2, z2 - square). What i need to do to find if player is near to this area?
FunkyBboy is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 11-27-2013 , 18:12   Re: finding if player is near to the area
Reply With Quote #2

First of all, you need to find the entity's position.

http://docs.sourcemod.net/api/index....ad=show&id=87&

for more info wait for someone else, I'm not sure so I don't wanna make you wrong.

Last edited by LambdaLambda; 11-27-2013 at 18:13.
LambdaLambda is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 11-27-2013 , 18:34   Re: finding if player is near to the area
Reply With Quote #3

Here is some slightly modified code I have used to do this:

PHP Code:
//Change this to the center point of the area checking for.
new Float:vec[3] = { 0.00.00.0 };

for (new 
i=1i<=MAXPLAYERSi++)
{
    
//Skip dead and unconnected players
    
if(!IsClientInGame(i) || !IsPlayerAlive(i)) continue;
    
    new 
Float:pos[3];
    
GetClientEyePosition(ipos);
    
    new 
Float:distance GetVectorDistance(vecpos);
    
    if(
distance 420.0)
    {
        
PrintToServer("%N is within 420 units from %f,%f,%f"ivec[0], vec[1], vec[2]);
    }


Last edited by NIGathan; 11-27-2013 at 18:36.
NIGathan is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 11-27-2013 , 23:57   Re: finding if player is near to the area
Reply With Quote #4

Technically you should use the absolute origin for this and not eye's position. You want to know how far "the feet have to get" and not the eyes.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 11-27-2013 at 23:57.
Dr. Greg House is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-28-2013 , 02:17   Re: finding if player is near to the area
Reply With Quote #5

...I'm too lazy to look up the specifics, but TR_TraceHull should be able to be used to find out if a player is within a certain distance.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 11-28-2013 , 05:15   Re: finding if player is near to the area
Reply With Quote #6

from what I undestand, he have a list of areas and he wants to find the nearest. Am I right?
LambdaLambda is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 11-28-2013 , 11:34   Re: finding if player is near to the area
Reply With Quote #7

Edict_GetClosest
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Reply



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 01:15.


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