Melee attacks for LUA

So i’ve been looking at this for a while, and i want to know if there’s an easy way in LUA to handle melee hits, so i wont have to code responses to each material type, like the decals, effects, and sounds etc

or am i just going to have to deal with it

thanks

So what you are asking for is a Hook to handle damage dealt? Also, you seem to want to be able to from what I understand, get the materials of the SWEP used to attack someone as-well as the sounds?

Please do explain what you intend to do, and be more specific with the details please.

Well, what i want to know if there’s a built in function already to handle melee hits, exactly what happens when you hit something with a crowbar
i thought it would be logical that such a function would exist, and i though i should ask if it does first before spending time creating my own system

For the most part you have to handle all the impact effects yourself, but here is my melee base if you want to use it.
[lua]
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
if not IsFirstTimePredicted( ) then return end

if SERVER then
local trace = self.Owner:GetEyeTrace()
trace.Mask = {MASK_WATER, MASK_OPAQUE}

if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then
	self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
	self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet" .. math.random( 3, 5 ) .. ".wav")
	local dmg = DamageInfo()
	dmg:SetDamageType( DMG_SLASH | DMG_CLUB )
	dmg:SetDamage( self.Primary.Damage )
	dmg:SetDamagePosition( trace.HitPos )
	dmg:SetInflictor(self)
	dmg:SetAttacker(self:GetOwner())
	trace.Entity:TakeDamageInfo(dmg)
	local effect = EffectData()
		effect:SetOrigin(trace.HitPos)
	util.Effect("Impact", effect)
else
	self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
	self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
end
end

self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:DoAttackEvent( )

end
[/lua]

Alright now I understand, yes as Feihc has now made clear you do have to handle all the effects and sounds yourself.

So if you do not have any sounds to be emitted in your code, there will be none. If you have no effects / particles to be emitted in your code, again there will be none.

To really drive the nail in on the point here, if you didn’t declare DAMAGE in the code, the player / entity in the trace or within a specified radius would not be damaged.

Think of it like this, in less you know it’s handled elsewhere, assume you’re making it from scratch.

And yes, there is a function that handles melee hits, and in fact that function handles any kind of SWEP attack, SWEP:PrimaryAttack() OR SWEP:SecondaryAttack( ). Just remember to use these SWEP functions you must be using them within a custom SWEP file, also keep in mind the SWEP file is always in the shared instance.