AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player attacked from behind? (https://forums.alliedmods.net/showthread.php?t=192984)

Gadzislaw007 08-15-2012 14:16

Player attacked from behind?
 
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?

Liverwiz 08-15-2012 16:21

Re: Player attacked from behind?
 
Ham_TraceAttack gives you the vector from which the player was attacked.

Exolent[jNr] 08-15-2012 16:23

Re: Player attacked from behind?
 
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.

Gadzislaw007 08-15-2012 16:51

Re: Player attacked from behind?
 
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
            



Exolent[jNr] 08-15-2012 16:58

Re: Player attacked from behind?
 
Quote:

Originally Posted by Gadzislaw007 (Post 1772379)
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.

Gadzislaw007 08-16-2012 13:25

Re: Player attacked from behind?
 
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?

SpaceRip 08-17-2012 08:37

Re: Player attacked from behind?
 
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 


Gadzislaw007 08-17-2012 10:37

Re: Player attacked from behind?
 
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.

Exolent[jNr] 08-17-2012 11:33

Re: Player attacked from behind?
 
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 }

Gadzislaw007 08-17-2012 12:16

Re: Player attacked from behind?
 
Thanks, but Can you say what is wrong in my second try? :)


All times are GMT -4. The time now is 05:49.

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