Raised This Month: $51 Target: $400
 12% 

[CSS] Detect when a player is knifed by a teammate


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Paaf
Member
Join Date: Dec 2010
Old 06-19-2012 , 14:04   [CSS] Detect when a player is knifed by a teammate
Reply With Quote #1

Hi there,

I'm trying to detect when a player is knifed by a teammate.
That's not that easy because the player is not hurt or anything...
No way to hook "player_hurt" or OnTakeDamage...

Have you got an idea ?
Paaf is offline
Razmo51
Senior Member
Join Date: Aug 2011
Location: Event "player_death
Old 06-19-2012 , 15:07   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #2

OnTakeDamage (from SDKhooks) works between teammate's damages
__________________
Sorry for my bad English, I'm Belgian
Razmo51 is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-19-2012 , 15:43   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #3

PHP Code:
#include <sourcemod>
#include <sdktools>

new g_iWeaponOffset = -1;

public 
OnPluginStart()
{
    
g_iWeaponOffset FindSendPropOffs("CBaseCombatCharacter""m_hMyWeapons");
}

public 
Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon)
{
    
// If player attack
    
if (buttons IN_ATTACK)
    {
        
// Check if he currently hold a knife
        
weapon GetEntDataEnt2(clientg_iWeaponOffset+(2*4));
        if(
weapon && IsValidEdict(weapon))
        {
            
decl String:weaponName[64];
            
GetEdictClassname(weaponweaponName,64);
            if(
StrEqual(weaponName"weapon_knife"))
            {
                
// Now check if the player is looking at a teamate
                
new target GetClientAimTarget(clienttrue);
                if (
target != -&& GetClientTeam(client) == GetClientTeam(target))
                {
                    
// Check the distance between the two player to see if the attack could be done, since I am not sure of the distance I will put a guess number but I'm sure u can figure it out
                    
decl Float:clientPos[3], Float:targetPos[3];
                    
GetClientAbsOrigin(clientclientPos);
                    
GetClientAbsOrigin(targettargetPos);
                    if (
GetVectorDistance(clientPostargetPos) <= 80.0)
                    {
                        
PrintToChat(client"I have knifed my teamate %N without friendly fire and detected it."target);
                    }
                }
            }
        }
    }

I did compile with not error but not tested it yet, it should work. Have fun.
Mathias. is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-19-2012 , 20:34   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #4

Okay I have tested my version and it do not work cause I use the same variable weapon and I use an other way to get the current player weapon. In the follow code it does everything you need but I have added blocking attack and since the GetClientAim is not perfect you absoluty need to aim correctly on the play to make it work. 120 units is a good distance because when the player run you can get it at this distance, but you can make it shorter between 80~120 depending on your use.

PHP Code:
#include <sourcemod>
#include <sdktools>

public Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon)
{

    
decl attacks;
    
// If player attack (append left or and right click)
    
if (buttons IN_ATTACK)
    {
        
attacks |= IN_ATTACK;
    }
    
    if (
buttons IN_ATTACK2)
    {
        
attacks |= IN_ATTACK2;
    }
    
    
// if attacks happened
    
if (attacks)
    {
        
// Check if he currently hold a knife
        
new iWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if(
iWeapon && IsValidEdict(iWeapon))
        {
            
decl String:weaponName[64];
            
GetEdictClassname(iWeaponweaponName,64);
            if(
StrEqual(weaponName"weapon_knife"))
            {
                
// Now check if the player is looking at a teamate
                
new target GetClientAimTarget(clienttrue);
                if (
target != -&& GetClientTeam(client) == GetClientTeam(target))
                {
                    
// Check the distance between the two player to see if the attack could be done, since I am not sure of the distance I will put a guess number but I'm sure u can figure it out
                    
decl Float:clientPos[3], Float:targetPos[3];
                    
GetClientAbsOrigin(clientclientPos);
                    
GetClientAbsOrigin(targettargetPos);
                    if (
GetVectorDistance(clientPostargetPos) <= 120.0)
                    {
                        
PrintToChat(client"Attack cancel on %N."target);
                        
buttons &= ~attacks;
                    }
                }
            }
        }
    }

Mathias. is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-20-2012 , 02:15   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #5

Here, all four SDKHook type what detect attack.
PHP Code:
#include <sourcemod>
#include <sdkhooks>

public OnPluginStart()
{
    
// Reload plugin during game ? Hook players again.
    
for(new 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            
OnClientPutInServer(i);
        }
    }
}

public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_TraceAttack,        TraceAttack);
    
SDKHook(clientSDKHook_TraceAttackPost,    TraceAttackPost);
    
SDKHook(clientSDKHook_OnTakeDamage,        OnTakeDamage);
    
SDKHook(clientSDKHook_OnTakeDamagePost,    OnTakeDamagePost);
}

public 
Action:TraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup)
{
    if(
attacker && attacker <= MaxClients// Attacker is one of client indexs
    
{
        if(
attacker != victim)    // Victim else than attacker himself
        
{
            if(
GetClientTeam(attacker) == GetClientTeam(victim))    // Both are same team
            
{
                
PrintToServer("TraceAttack %N %N"attackervictim);
            }
        }
    }
}

public 
TraceAttackPost(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup)
{
    if(
attacker && attacker <= MaxClients)
    {
        if(
attacker != victim)
        {
            if(
GetClientTeam(attacker) == GetClientTeam(victim))
            {
                
PrintToServer("TraceAttackPost %N %N"attackervictim);
            }
        }
    }
}

public 
Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if(
attacker && attacker <= MaxClients)
    {
        if(
attacker != victim)
        {
            if(
GetClientTeam(attacker) == GetClientTeam(victim))
            {
                
PrintToServer("OnTakeDamage %N %N"attackervictim);
            }
        }
    }
}

public 
OnTakeDamagePost(victimattackerinflictorFloat:damagedamagetype)
{
    if(
attacker && attacker <= MaxClients)
    {
        if(
attacker != victim)
        {
            if(
GetClientTeam(attacker) == GetClientTeam(victim))
            {
                
PrintToServer("OnTakeDamagePost %N %N"attackervictim);
            }
        }
    }

Bacardi is offline
Paaf
Member
Join Date: Dec 2010
Old 06-20-2012 , 03:22   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #6

Thx Bacardi, I will test those four SDKHook types and see if one of them can be used.

If not, I will use the code of Black-Rabbit. At least, I'm sure this way works, I just need to adjust the distance as you said. Thank you for your answer and testing

I will test this this afternoon and keep you informed.

Last edited by Paaf; 06-20-2012 at 03:23.
Paaf is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-20-2012 , 05:32   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #7

Quote:
Originally Posted by Paaf View Post
Thx Bacardi, I will test those four SDKHook types and see if one of them can be used.
Those will work if you not have outdated sdkhooks gamedata files.

Quote:
Originally Posted by Paaf View Post
If not, I will use the code of Black-Rabbit. At least, I'm sure this way works, I just need to adjust the distance as you said.
...I certainly would not use.
Bacardi is offline
Paaf
Member
Join Date: Dec 2010
Old 06-20-2012 , 12:34   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #8

Okey, after testing TraceAttack (from SDKHook) works perfectly :

Code:
SDKHook(client, SDKHook_TraceAttack, TraceAttack);
Thank you all for your answer !
Paaf is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-20-2012 , 12:45   Re: [CSS] Detect when a player is knifed by a teammate
Reply With Quote #9

This is nice to know.

Thank for sharing.
Black-Rabbit
Mathias. 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 12:16.


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