AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting players in a specified area [advanced] (https://forums.alliedmods.net/showthread.php?t=171761)

tuty 11-10-2011 14:48

Getting players in a specified area [advanced]
 
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 :).

http://i44.tinypic.com/102joe1.png

Flipper_SPb 11-10-2011 14:54

Re: Getting players in a specified area [advanced]
 
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

drekes 11-10-2011 15:42

Re: Getting players in a specified area [advanced]
 
is_in_viewcone() maybe ?

tuty 11-10-2011 15:50

Re: Getting players in a specified area [advanced]
 
lol i totaly forgot that native, and btw, what is the default value for that viewcone check?

Sylwester 11-10-2011 16:35

Re: Getting players in a specified area [advanced]
 
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 


nikhilgupta345 11-10-2011 21:09

Re: Getting players in a specified area [advanced]
 
Quote:

Originally Posted by KillLikoe (Post 1594295)
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.

KillLikoe 11-10-2011 21:22

Re: Getting players in a specified area [advanced]
 
oh fuck, sorry i didnt read it


All times are GMT -4. The time now is 14:21.

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