Raised This Month: $ Target: $400
 0% 

Getting players in a specified area [advanced]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 11-10-2011 , 14:48   Getting players in a specified area [advanced]
Reply With Quote #1

Hi, for example, i have an red entity like in image. I make it think and so on..
How can i detect players that are in the green area from image? Something like a view cone .

__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 11-10-2011 , 14:54   Re: Getting players in a specified area [advanced]
Reply With Quote #2

I think, you can use find_ent_in_sphere() to find a player with some interval. If player was found, check the angle between direction to player and "view" vector of your entity. And do trace from entity to player
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 11-10-2011 , 15:42   Re: Getting players in a specified area [advanced]
Reply With Quote #3

is_in_viewcone() maybe ?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 11-10-2011 , 15:50   Re: Getting players in a specified area [advanced]
Reply With Quote #4

lol i totaly forgot that native, and btw, what is the default value for that viewcone check?
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-10-2011 , 16:35   Re: Getting players in a specified area [advanced]
Reply With Quote #5

In case you or someone else could not use is_in_viewcone, there is another way - you need to loop through all alive players and use something like this
PHP Code:
    #define MAX_ANGLE 3.1415 * 0.25  //these are radians, so PI (3.1415.....) equals 180 degrees
    
    
new Float:aim_vec[3//aim vector of an entity
    
new Float:tar_vec[3//vector pointing from entity to player (you get it when you subtract origins)
    
    //you can skip aim_distance if you use native that returns normalized vector (in that case aim_distance will be 1.0)
    
new Float:aim_distance floatsqroot(aim_vec[0]*aim_vec[0] + aim_vec[1]*aim_vec[1] + aim_vec[2]*aim_vec[2]) 
    new 
Float:tar_distance floatsqroot(tar_vec[0]*tar_vec[0] + tar_vec[1]*tar_vec[1] + tar_vec[2]*tar_vec[2])
    
    new 
Float:cos_val = (aim_vec[0]*tar_vec[0] + aim_vec[1]*tar_vec[1] + aim_vec[2]*tar_vec[2]) / (aim_distance*tar_distance)
    
//now cos_val stores cosine of an angle between aim_vec and tar_vec

    
new Float:angle floatacos(cos_val)
    if(
angle MAX_ANGLE)
        continue

    
//found matching player 
__________________
Impossible is Nothing
Sylwester is offline
Old 11-10-2011, 20:22
KillLikoe
This message has been deleted by KillLikoe. Reason: i didnt read all sylwester`s message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-10-2011 , 21:09   Re: Getting players in a specified area [advanced]
Reply With Quote #6

Quote:
Originally Posted by KillLikoe View Post
if(angle > MAX_ANGLE)
continue

this part you cant use it like that because you can only use continue on a cicle, you need to use return there
He said that you have to loop through all players and use that code. Continue is appropriate there.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
KillLikoe
BANNED
Join Date: Nov 2010
Location: Paraguay
Old 11-10-2011 , 21:22   Re: Getting players in a specified area [advanced]
Reply With Quote #7

oh fuck, sorry i didnt read it
KillLikoe 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 14:21.


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