Raised This Month: $ Target: $400
 0% 

Player attacked from behind?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-15-2012 , 14:16   Player attacked from behind?
Reply With Quote #1

Is there any possibility to check if enemy was attacked from behind?
How can I possibly check if player was visible or something like this ;d.

Tried that way:
http://forums.alliedmods.net/showthr...player+visible
But it's too hard for me to do. If there was any library to include with that function I'd be happy.
Anyone knows anything bout that?
Gadzislaw007 is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-15-2012 , 16:21   Re: Player attacked from behind?
Reply With Quote #2

Ham_TraceAttack gives you the vector from which the player was attacked.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-15-2012 , 16:23   Re: Player attacked from behind?
Reply With Quote #3

As Liverwiz stated, you have a directional vector of the attack.
You can also get the direction that the victim is aiming.

With those 2 vectors, you can use xs_vec_angle() to see the angle between the attack and the aim.

I would say if the resulting angle is less than 45 degrees, then player was attacked from behind.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-15-2012 , 16:51   Re: Player attacked from behind?
Reply With Quote #4

Yah, I realized that while ago ;D.
Thanks for help anyway.

PHP Code:
            new Float:AngleA[3], Float:AngleV[3]
            
            
entity_get_vector(attackerEV_VEC_v_angleAngleA)
            
entity_get_vector(victimEV_VEC_v_angleAngleV)
            
            new 
angle floatround(AngleA[1]) - floatround(AngleV[1])
            if ((
angle 65) && (angle > -65))
            {
                
CODE HERE
            

Gadzislaw007 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-15-2012 , 16:58   Re: Player attacked from behind?
Reply With Quote #5

Quote:
Originally Posted by Gadzislaw007 View Post
Yah, I realized that while ago ;D.
Thanks for help anyway.

PHP Code:
            new Float:AngleA[3], Float:AngleV[3]
            
            
entity_get_vector(attackerEV_VEC_v_angleAngleA)
            
entity_get_vector(victimEV_VEC_v_angleAngleV)
            
            new 
angle floatround(AngleA[1]) - floatround(AngleV[1])
            if ((
angle 65) && (angle > -65))
            {
                
CODE HERE
            

Not quite. If a user is looking at -160 degrees and the other is at 160 degrees, that is 40 degrees difference but your plugin would think it is either 320 or -320 degrees.

If you don't use the method I described, then you have to do a bunch of checks for that math to work.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-16-2012 , 13:25   Re: Player attacked from behind?
Reply With Quote #6

PHP Code:
            new Float:AngleA[3], Float:AngleV[3]
            
            
entity_get_vector(attackerEV_VEC_v_angleAngleA)
            
entity_get_vector(victimEV_VEC_v_angleAngleV)
            new 
a1a2
            a1 
floatround(AngleA[1])
            
a2 floatround(AngleV[1])

            new 
angle a2 a1
            
            
if (((angle 70) && (angle > -70)) || ((angle 310 && angle 360)) || ((angle < -310 && angle > -360)))
            {
                
CODE HERE
            

What about now?

Last edited by Gadzislaw007; 08-16-2012 at 13:45.
Gadzislaw007 is offline
SpaceRip
Junior Member
Join Date: Aug 2012
Old 08-17-2012 , 08:37   Re: Player attacked from behind?
Reply With Quote #7

new Float:AngleA[3], Float:AngleV[3]



PHP Code:
new Float:a[3], Float:b[3], Float:d
entity_get_vector
(attackerEV_VEC_v_anglea
entity_get_vector(victimEV_VEC_v_angleb)
a[1] -b[1]
if ( 
40.0 && > -40.0 || 180.0 && 140.0 || < -140.0 && > -180.0 )
    
// behind attack 

Last edited by SpaceRip; 08-17-2012 at 08:38.
SpaceRip is offline
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-17-2012 , 10:37   Re: Player attacked from behind?
Reply With Quote #8

Well that's actually same way as I did. I just changed form (-180,180) to (0,360) firstly to make it more clear to me.

Last edited by Gadzislaw007; 08-17-2012 at 10:38.
Gadzislaw007 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-17-2012 , 11:33   Re: Player attacked from behind?
Reply With Quote #9

Code:
new Float:vecVictim[ 3 ], Float:vecAttack[ 3 ]; pev( victim  , pev_v_angle, vecVictim ); pev( attacker, pev_v_angle, vecAttack ); engfunc( EngFunc_MakeVectors, vecVictim ); global_get( glb_v_forward, vecVictim ); engfunc( EngFunc_MakeVectors, vecAttack ); global_get( glb_v_forward, vecAttack ); new Float:degrees = xs_vec_angle( vecVictim, vecAttack ); if( degrees <= 40.0 ) {     // Attacked from behind }

EDIT: Or if you must...

Code:
new Float:vecVictim[ 3 ], Float:vecAttack[ 3 ]; pev( victim  , pev_v_angle, vecVictim ); pev( attacker, pev_v_angle, vecAttack ); new Float:flAngles[ 2 ]; flAngles[ 0 ] = vecVictim[ 1 ]; flAngles[ 1 ] = vecAttack[ 1 ]; new iHigher = ( flAngles[ 0 ] < flAngles[ 1 ] ) ? 1 : 0; new iLower  = 1 - iHigher; if( ( flAngles[ iHigher ] - flAngles[ iLower ] ) <= 40.0 ||  ( 360.0 - flAngles[ iHigher ] + flAngles[ iLower ] ) <= 40.0 ) {     // Attacked from behind }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 08-17-2012 at 11:41.
Exolent[jNr] is offline
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 08-17-2012 , 12:16   Re: Player attacked from behind?
Reply With Quote #10

Thanks, but Can you say what is wrong in my second try?
Gadzislaw007 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 05:49.


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