AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect damage (https://forums.alliedmods.net/showthread.php?t=159438)

reinert 06-17-2011 05:21

Detect damage
 
How to detect a weapon with which was damage done ?

Like I've plugin that deals extra damage if you are with knife, but it hooks like
if(AttackerWeapon == CSW_KNIFE)

and there is a bug when I throw HE, and instantly switch my gun to knife, it deals KNIFE damage, even if it was done by HE.

Hunter-Digital 06-17-2011 06:30

Re: Detect damage
 
Hook damage with ham and...

Just making sure you know, first you must make sure attacker is a player (1 <= attacker <= g_iMaxPlayers)

In the ham called function you get the "inflictor" input, you can check that against "attacker", if they're equal, the attacker used a weapon, if it's not, the attacker used a nade or something else to attack.

Then you can just get_user_weapon()...

reinert 06-17-2011 07:48

Re: Detect damage
 
Like this: ?

PHP Code:

RegisterHam(Ham_TakeDamage"player""Ham_DamageKNIFE")

public 
Ham_DamageKNIFE(idinflictorattackerFloat:damagedamagebits)
{
    if ( !(
<= attacker <= g_maxplayers) || !g_KNIFE[attacker])
            return 
HAM_IGNORED;
        
    if(
inflictor == attacker)
    {
        new 
weaponx get_user_weapon(attacker__);
        if( 
weaponx == CSW_KNIFE && get_user_team(attacker) == 2)
        {
        
SetHamParamFloat(4damage get_pcvar_float(damage_knife)); //Knife damage
        
return HAM_HANDLED;
        }
    }
    return 
HAM_IGNORED;



bibu 06-17-2011 12:34

Re: Detect damage
 
Simple, try it. :)


All times are GMT -4. The time now is 23:30.

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