Raised This Month: $ Target: $400
 0% 

Getting players in a specified area [advanced]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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