AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hit/Knife in back/rear ? (https://forums.alliedmods.net/showthread.php?t=242561)

waza123a 06-21-2014 08:31

Hit/Knife in back/rear ?
 
1 Attachment(s)
Is there a way to detect, if player was kicked/shoot/knifed in back/rear ?

meTaLiCroSS 06-21-2014 10:42

Re: Hit/Knife in back/rear ?
 
You can try to hook TraceAttack on "player", check if player was attacked with knife.

When dealing dmg with a knife stab, it hurts 65hp points, but if it's from behind, this gets mult by 3, so the total damage done it's 195hp points. There wouldn't be other greater dmg value, so you can use it to check.

Or also, you can imitate engine's way to check if player attacked behind another:

PHP Code:

    UTIL_MakeVectorsm_pPlayer->pev->v_angle ); 
    
// and later...

    
float flDamage 65.0;
        if( 
pEntity && pEntity->IsPlayer() )        
    {            
        
Vector2D vec2LOS;            
        
Vector vecForward gpGlobals->v_forward;
        
UTIL_MakeVectorsm_pPlayer->pev->angles );
        
vec2LOS vecForward.Make2D();            
        
vec2LOS vec2LOS.Normalize();
        if( 
DotProductvec2LOSgpGlobals->v_forward.Make2D() ) > 0.8 )            
        {                    
            
flDamage *= 3.0;            
        }        
    }
        
UTIL_MakeVectorsm_pPlayer->pev->v_angle );        
    
ClearMultiDamage();
        
pEntity->TraceAttackm_pPlayer->pevflDamagegpGlobals->v_forward, &trDMG_NEVERGIB DMG_BULLET );        
    
ApplyMultiDamagem_pPlayer->pevm_pPlayer->pev ); 


waza123a 06-21-2014 10:52

Re: Hit/Knife in back/rear ?
 
it's very interesting, but its 2014y, and no one ever want to check "hit in back" ? maybe there is some released code somewhere.. ?

of course i will try to create that function with damage *3, thanks for idea.

Black Rose 06-21-2014 10:56

Re: Hit/Knife in back/rear ?
 
I didn't make it. Found it somewhere.
Code:
bool:IsBackstab(const attacker, const victim) {         new Float: vec1[3];     new Float: vec2[3];         velocity_by_aim(attacker, 1, vec1);         new Float:invlen = xs_rsqrt(vec1[0] * vec1[0] + vec1[1] * vec1[1]);     vec1[0] *= invlen;     vec1[1] *= invlen;         pev(victim, pev_angles, vec2);     angle_vector(vec2, ANGLEVECTOR_FORWARD, vec2);         return vec1[0] * vec2[0] + vec1[1] * vec2[1] > 0.8 ? true : false; }

waza123a 06-21-2014 11:00

Re: Hit/Knife in back/rear ?
 
awesome, thanks! will try

meTaLiCroSS 06-21-2014 17:06

Re: Hit/Knife in back/rear ?
 
PHP Code:

public OnTraceAttack(iVictimiAttackerFloat:flDamageFloat:vecDirection[3], iTrHandlebitsDamageType)
{
    if(
bitsDamageType == (DMG_BULLET|DMG_NEVERGIB// specific knife damage mask
    
&& is_user_alive(iAttacker// some dmgs can be done while user is dead, so you are checking if attacker it's player also
    
&& get_user_weapon(iAttacker) == CSW_KNIFE
    
&& flDamage == 192.0)
    {
        
client_print(0print_chat"Hey! I've attacked you from behind 6969")
    }




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

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