Raised This Month: $32 Target: $400
 8% 

[CS] Detecting backstab


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lazarev
Veteran Member
Join Date: Sep 2008
Old 04-04-2013 , 07:35   [CS] Detecting backstab
Reply With Quote #1

PHP Code:
        new Floatvec2LOS[2];
        new 
FloatvecForward[3];
        new 
FloatvecForward2D[2];

        
velocity_by_aimiAttacker1vecForward );
      
        
xs_vec_make2dvecForwardvec2LOS );
        
xs_vec_normalizevec2LOSvec2LOS );
    
        
peviVictimpev_anglesvecForward );
        
engfuncEngFunc_MakeVectorsvecForward );
        
global_getglb_v_forwardvecForward );
        
        
xs_vec_make2dvecForwardvecForward2D );
        if( 
xs_vec_dotvec2LOSvecForward2D ) > 0.8 )
        {
           
// iAttacker has backstabbed iVictim
        

Credits to: Arkshine for CS-SDK and micapat for CKnife::Stab fix in CS-SDK

Last edited by lazarev; 04-15-2013 at 14:33.
lazarev is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-04-2013 , 12:34   Re: [SNIPPET] CS Knife backstab detection (SDK way).
Reply With Quote #2

You can optimize this :
PHP Code:
        peviAttackerpev_v_anglevecForward );
        
engfuncEngFunc_MakeVectorsvecForward );
        
global_getglb_v_forwardvecForward ); 
and this

PHP Code:
        peviVictimpev_anglesvecForward );
        
engfuncEngFunc_MakeVectorsvecForward );
        
global_getglb_v_forwardvecForward ); 
Doing this :
PHP Code:
velocity_by_aim(iAttacker1vecForward ); 
and this :
PHP Code:
velocity_by_aim(iVictim1vecForward ); 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
lazarev
Veteran Member
Join Date: Sep 2008
Old 04-04-2013 , 12:53   Re: [SNIPPET] CS Knife backstab detection (SDK way).
Reply With Quote #3

@ConnorMcLeod - Are you sure that I can use velocity_by_aim() for victim since it grabs pev_v_angle parameter but not pev_angles? Thanks for the tip though

Last edited by lazarev; 04-04-2013 at 13:22.
lazarev is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-04-2013 , 13:32   Re: [SNIPPET] CS Knife backstab detection (SDK way).
Reply With Quote #4

You are right, hadn't see this.

Anyway, rather than MakeAngle + global_get, you should use anglevectors

PHP Code:
angle_vector(vecForwardANGLEVECTOR_FORWARDvecForward); 
You save 1 native call.
Not sure if you can use same variable though, should be ok.


More generally, use angle_vector when you only need 1 dimension/axe/call how you want, and use EngFunc_AngleVectors when you need 2 or 3 dimensions, then you don't need to use global_get.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-15-2013 , 18:01   Re: [CS] Detecting backstab
Reply With Quote #5

I'm using another solution to detect if someone got backstabbed and it worked proper. But take a look below. Keep in mind that I've created this solutions many months ago, so I can't remember on every single damage

Spoiler
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 04-17-2013 at 04:44.
Leon M. is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 04-16-2013 , 12:12   Re: [CS] Detecting backstab
Reply With Quote #6

if (g_iPlayerWeapon[iAttacker] == CSW_KNIFE)

may be get_user_weapon?
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-16-2013 , 17:23   Re: [CS] Detecting backstab
Reply With Quote #7

Oh yes, get_user_weapon will work too. I just needed a global var since I'm alter some things in client_PreThink(id) depending on the weapon ;)

Edited my suggestion and added server messages if you want to hook other events
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 04-17-2013 at 04:45.
Leon M. is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-17-2013 , 15:00   Re: [CS] Detecting backstab
Reply With Quote #8

get_user_aiming is bad to use, because the attacker doesn't need to aim at the hitbox (if you're really close to the enemy, you will hit them even when aiming next to them)
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-18-2013 , 10:22   Re: [CS] Detecting backstab
Reply With Quote #9

Doesn't matter much for testing purpose
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
fl0werD
Senior Member
Join Date: May 2011
Old 04-19-2013 , 10:09   Re: [CS] Detecting backstab
Reply With Quote #10

PHP Code:
GetCenter(iEntityvecSrc);
GetCenter(iPlayervecEnd);
    
xs_vec_sub(vecEndvecSrcvecEnd);
xs_vec_normalize(vecEndvecEnd);

pev(iEntitypev_anglesvecAngle);
engfunc(EngFunc_MakeVectorsvecAngle);

global_get(glb_v_forwardvecForward);
xs_vec_mul_scalar(vecEnd, -1.0vecEnd);
               
if (
xs_vec_dot(vecForwardvecEnd) > 0.3)
{
    
flDamage WEAPON_DAMAGE_BACK;


PHP Code:
GetCenter(iEntityFloatvecSrc[3])
{
    new 
FloatvecAbsMax[3], FloatvecAbsMin[3];

    
pev(iEntitypev_absmaxvecAbsMax)
    
pev(iEntitypev_absminvecAbsMin)

    
xs_vec_add(vecAbsMaxvecAbsMinvecSrc)
    
xs_vec_mul_scalar(vecSrc0.5vecSrc)

By KORD_12.7

Last edited by fl0werD; 04-19-2013 at 10:22.
fl0werD is offline
Send a message via ICQ to fl0werD
Reply


Thread Tools
Display Modes

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 16:25.


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