If it works, it works. You can add the line anywhere between/above/below these lines:
PHP Code:
if(victim == attacker) return HAM_IGNORED; //self damage
if(inflictor != attacker) return HAM_IGNORED; //prevent from other damage like bazooka, tripmine we need knife damage only
if(!is_user_connected(attacker)) return HAM_IGNORED; //non-player damage
if(get_user_weapon(attacker) != CSW_KNIFE) return HAM_IGNORED; //current weapon is not knife