Need SWEP:PrimaryAttack() Coded

Hi, I’m pretty bad at coding sweps xD which is why I’m posting here, can someone code a SWEP:PrimaryAttack() function? For reference on how I want it here is my failed SWEP:PrimaryAttack() function.

[lua]
function SWEP:PrimaryAttack()

if ( self.ShootafterTakeout > CurTime() ) then return end		
self.Weapon:SetNextPrimaryFire( CurTime() + .4 )

local ply = self.Owner
local pos = ply:GetPos()
local ang = ply:GetAimVector()
local phtr = ply:GetEyeTrace()
local trace = util.TraceHull( tracedata )
local tr = util.TraceLine(trace)
local ph = phtr.Entity:GetPhysicsObject()

if (ply:GetPos() - tr.HitPos):Length() < 100 then


	
	if tr.Entity:IsPlayer() or string.find(tr.Entity:GetClass(),"npc") or string.find(tr.Entity:GetClass(),"prop_ragdoll") or tr.Entity.MatType == "MAT_GLASS" then
	
		if self.hit == 1 then
			self.Weapon:EmitSound( self.FleshHit1 )
			self.hit = 2
			
		elseif self.hit == 2 then
			self.Weapon:EmitSound( self.FleshHit2 )
			self.hit = 3
			
		elseif self.hit == 3 then
			self.Weapon:EmitSound( self.FleshHit3 )
			self.hit = 4
			
		else
			self.Weapon:EmitSound( self.FleshHit4 )
			self.hit = 1
		end
		
		ply:SetAnimation( PLAYER_ATTACK1 );
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
				
        local startpos = self.Owner:GetShootPos()
        local endpos = startpos + self.Owner:GetAimVector() * 75
        local minbox = Vector(-10,-10,-10)
        local maxbox = Vector(10,10,10)
        local damage = 15
        local dtype = DMG_SLASH
        local dforce = 5
        local damageall = true
        self.Owner:TraceHullAttack(startpos, endpos, minbox, maxbox, damage, dtype, dforce, damageall)

			
			
	else
		util.Decal("ManhackCut", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
		self.Weapon:EmitSound(self.WallSound,100,math.random(95,110))
		self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
		if not tr.HitWorld and not string.find(tr.Entity:GetClass(),"prop_static") then
			if SERVER then ph:ApplyForceCenter(self.Owner:GetAimVector()*5000) end
		end
	end


else
	self.Weapon:EmitSound(self.MissSound,100,math.random(90,120))
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	
end

self.Owner:SetAnimation( PLAYER_ATTACK1 ) --3rd Person Animation

end
[/lua]

Thanks