Help needed with SWEP

I am trying to make a replica of Opposing Force’s Knife and it doesn’t work correctly, as it does no damage and doesn’t create decals.


AddCSLuaFile()
 
SWEP.HoldType                   = "knife"
 
if CLIENT then
    SWEP.PrintName               = "Knife"                      
    SWEP.Author                  = "Falkok15"
    SWEP.Slot                    = 0
    SWEP.ViewModelFOV    = 100
end
 
SWEP.Base                       = "weapon_base"
SWEP.Category                   = "Opposing Force"
 
SWEP.Spawnable                  = true
SWEP.AdminSpawnable             = true
SWEP.UseHands                                   = true
 
SWEP.ViewModel                  = "models/weapons/OF/v_knife.mdl"
SWEP.WorldModel                 = "models/weapons/OF/w_knife.mdl"
 
SWEP.Weight                     = 3
SWEP.AutoSwitchTo               = false
SWEP.AutoSwitchFrom             = false
SWEP.mode                                               = "default"
SWEP.Primary.Sound              = Sound("CombatKnifeHitFlesh.wav")
SWEP.Primary.Special            = Sound("CombatKnifeFire.wav")
SWEP.Primary.Damage             = math.random (10,40)
SWEP.Secondary.Damage           = math.random (40,60)
SWEP.Primary.ClipSize           = -1
SWEP.Primary.Delay              = .5
SWEP.Secondary.Delay            = 1
SWEP.Primary.DefaultClip        = -1
SWEP.Primary.Automatic          = true
SWEP.Primary.Ammo               = "none"
SWEP.Secondary.Ammo             = "none"
SWEP.HitDist                    = 60
 
 
function SWEP:Initialize()
        self:SetWeaponHoldType(self.HoldType)
        util.PrecacheSound(self.Primary.Sound)
        util.PrecacheSound(self.Primary.Special)
end
 
function SWEP:Deploy()
        self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
        self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
        if self.mode == "silenced" then
                self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
                self.Weapon:SendWeaponAnim(ACT_VM_DRAW_SILENCED)
        end
end
       
function SWEP:PrimaryAttack()
        self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
        self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_1)
        self.Owner:SetAnimation(PLAYER_ATTACK1)
        if SERVER then self.Owner:EmitSound(self.Primary.Special) end
                self.attackdelay = CurTime() +.25
        if self.mode == "silenced" then
                self.Weapon:SetNextPrimaryFire(CurTime() + self.Secondary.Delay)
                self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_2)
                self.Owner:SetAnimation(PLAYER_ATTACK1)
        self.attackdelay = CurTime() +.5
end
end
 
function SWEP:SecondaryAttack()
        self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
        self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
        if self.mode == "default" then
                self.mode = "silenced"
                self.Weapon:SendWeaponAnim(ACT_VM_ATTACH_SILENCER)
        elseif self.mode == "silenced" then
                self.mode = "default"
                self.Weapon:SendWeaponAnim(ACT_VM_DETACH_SILENCER)
        end
end
 
function SWEP:FireDelay()
        if self.attackdelay and CurTime() > self.attackdelay then
                self.attackdelay = nil
                self:Melee()
        end    
        if self.mode == "silenced" then
                if self.attackdelay and CurTime() > self.attackdelay then
                        self.attackdelay = nil
                        self:Melee2()
                end
        end
end
 
 
function SWEP:Melee()  
        local ang = self.Owner:GetAimVector()
        local spos = self.Owner:GetShootPos()
        local trace = {}
                trace.start = spos
                trace.endpos = spos + (ang * self.HitDist)
                trace.filter = self.Owner
                local tr = util.TraceLine(trace)
       
        local bullet = {}
                bullet.Num = 1
                bullet.Src = self.Owner:GetShootPos()
                bullet.Dir = self.Owner:GetAimVector()
                bullet.Spread = Vector(0,0,0)
                bullet.Tracer = 0
                bullet.Force = 3
                bullet.Damage = self.Primary.Damage
 
        if tr.HitWorld and !tr.MatType == (tr.MatType == MAT_GRATE) then
                if SERVER then self.Owner:EmitSound(self.Primary.Sound) end
                self.Owner:FireBullets(bullet)
        elseif tr.HitNonWorld then
                self.Owner:FireBullets(bullet)
        end
end
 
function SWEP:Melee2() 
        local ang = self.Owner:GetAimVector()
        local spos = self.Owner:GetShootPos()
        local trace = {}
                trace.start = spos
                trace.endpos = spos + (ang * self.HitDist)
                trace.filter = self.Owner
                local tr = util.TraceLine(trace)
       
        local bullet = {}
                bullet.Num = 1
                bullet.Src = self.Owner:GetShootPos()
                bullet.Dir = self.Owner:GetAimVector()
                bullet.Spread = Vector(0,0,0)
                bullet.Tracer = 0
                bullet.Force = 3
                bullet.Damage = self.Secondary.Damage
        if tr.HitWorld and !tr.MatType == (tr.MatType == MAT_GRATE) then
                if SERVER then self.Owner:EmitSound(self.Primary.Sound) end
                self.Owner:FireBullets(bullet)
        elseif tr.HitNonWorld then
                self.Owner:FireBullets(bullet)
        end
end

That’s because you are never calling SWEP:FireDelay.

Already tried FireDelay after Self.attackdelay = CurTime() +.25 and Self.attackdelay = CurTime() +.5 but it fired instantly without delay

Bullet in melee weapon? LOL
Im using DamageInfo in think function.
Something like that
[lua]
local dmginfo = DamageInfo()
dmginfo:SetDamage(20)
dmginfo:SetDamageType(DMG_CLUB)
dmginfo:SetAttacker(self.Owner)
dmginfo:SetInflictor(self.Weapon)
tr.Entity:TakeDamageInfo(dmginfo)
[/lua]
tr is trace of attack

AirBlack, that could easily make someone damage another person from an extremely far distance.

Doesn’t work, so anyone else have help?

You may need to network the actual decal being created at the trace.HitPos using: