No Custom Reloading Sound with SWEP

Here is my code:
[LUA] if SERVER then
AddCSLuaFile( “shared.lua” )
AddCSLuaFile( “RazorShared.lua” )
end

SWEP.HoldType = “ar2”

if CLIENT then

SWEP.PrintName = “HK G36C”
SWEP.Slot = 2

SWEP.Icon = “vgui/ttt/icon_Famas”
end

SWEP.Base = “weapon_tttbase”

SWEP.Kind = WEAPON_HEAVY
SWEP.WeaponID = Weapon_G36C

SWEP.Primary.Damage = 25
SWEP.Primary.Delay = 0.10
SWEP.Primary.Cone = 0.05
SWEP.Primary.ClipSize = 30
SWEP.Primary.ClipMax = 217
SWEP.Primary.DefaultClip = 30
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = “smg1”
SWEP.Primary.Recoil = 0.15
SWEP.Primary.Sound = Sound( “RazorSWEP/G36C/G36C-1.wav” )

function SWEP:Deploy()
self:EmitSound(“weapos_aug.deploy”)

return self.BaseClass.Deploy(self)
end

function SWEP:Reload()
self:EmitSound(“weapos_aug.magout”)

return self.BaseClass.Reload(self)
end

function SWEP:

SWEP.AllowDrop = true

SWEP.AutoSpawnable = true

SWEP.AmmoEnt = “item_ammo_smg1_ttt”

SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 70
SWEP.ViewModel = “models/RazorSWEP/v_G36C.mdl”
SWEP.WorldModel = “models/RazorSWEP/w_G36C.mdl”

SWEP.IronSightsPos = Vector(-2.669, -5.1, -1.28)

SWEP.IronSightsAng = Vector(-0.301, -2.11, 0)

SWEP.DeploySpeed = 2

function SWEP:GetHeadshotMultiplier(victim, dmginfo)
local att = dmginfo:GetAttacker()
if not IsValid(att) then return 2 end

local dist = victim:GetPos():Distance(att:GetPos())
local d = math.max(0, dist - 150)

– decay from 3.2 to 1.7
return 1.7 + math.max(0, (1.5 - 0.002 * (d ^ 1.25)))
end

–Crotch Gun Fix
SWEP.Offset = {
Pos = {
Up = 0,
Right = 1,
Forward = -3,
},
Ang = {
Up = 0,
Right = 0,
Forward = 0,
}
}

function SWEP:DrawWorldModel( )
local hand, offset, rotate

if not IsValid( self.Owner ) then
self:DrawModel( )
return
end

if not self.Hand then
self.Hand = self.Owner:LookupAttachment( “anim_attachment_rh” )
end

hand = self.Owner:GetAttachment( self.Hand )

if not hand then
self:DrawModel( )
return
end

offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up

hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )

self:SetRenderOrigin( hand.Pos + offset )
self:SetRenderAngles( hand.Ang )

self:DrawModel( )
end
[/LUA]

I am new to coding and I can not seem to get the reloading sound working. I am sorry if this question has been asked multiple times, its just that Gmod is pretty difficult to code with CSS weapons.

I’d recommend getting to know how soundscripts work, makes life a whole lot easier

Could you please tell how? I really want to know this is too frustrating.

[editline]29th August 2014[/editline]

This is what I have a lua file in lua/autorun:
[LUA]
//870MCS

sound.Add({
name = “Weapos_M3.Pump”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/870/870_pump.wav”

})

sound.Add({
name = “Weapos_M3.Insertshell”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/870/870_insertshell.wav”
})

//INTERVENTION

sound.Add({
name = “Weapon_INT.Clipin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Clipin.wav”
})

sound.Add({
name = “Weapon_INT.Clipout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Clipout.wav”
})

sound.Add({
name = “Weapon_INT.bolt”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Bolt.wav”
})

sound.Add({
name = “Weapon_INT.Draw”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Draw.wav”
})

//KAR98K

sound.Add({
name = “Weapon_KAR.clipout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/KAR98K/KARClipout.wav”
})

sound.Add({
name = “Weapon_KAR.bolt”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/KAR98K/KARBolt.wav”
})

sound.Add({
name = “Weapon_KAR.draw”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/KAR98K/KARDeploy.wav”
})

sound.Add({
name = “Weapon_KAR.Clipin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/KAR98K/KARClipin.wav”
})

//KSG-12

sound.Add({
name = “ksg12.Pump”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_ksg12/mw3_ksg12_pump.wav”
})

sound.Add({
name = “ksg12.Insertshell”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_ksg12/mw3_ksg12_insertshell.wav”
})

sound.Add({
name = “ksg12.Pump2”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_ksg12/mw3_ksg12_pump2.wav”
})

sound.Add({
name = “MW3.Deploy”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Draw.wav”
})

//PKP Pecheneg

sound.Add({
name = “MW3_PKP_Pecheneg.Coverup”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_coverup.wav”
})

sound.Add({
name = “MW3_PKP_Pecheneg.Chainout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_chainout.wav”
})

sound.Add({
name = “W3_PKP_Pecheneg.Boxout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boxout.wav”
})

sound.Add({
name = “MW3_PKP_Pecheneg.Boxin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boxin.wav”
})

sound.Add({
name = “MW3_PKP_Pecheneg.Chainin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_chainin.wav”
})

sound.Add({
name = “MW3_PKP_Pecheneg.Coverdown”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_coverdown.wav”
})

sound.Add({
name = “MW3_PKP_Pecheneg.Boltpull”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boltpull.wav”
})

sound.Add({
name = “MW3.Deploy”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Intervention/Draw.wav”
})

//Spas12

sound.Add({
name = “Weapon_12.Pump”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Spas12/spas_pump.wav”
})

sound.Add({
name = “Weapon_12.Insertshell”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/Spas12/spas_insertshell.wav”
})

//SCAR-H

sound.Add({
name = “Weapon_SCAR.Clipout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/scar-h/SCAR_clipout.wav”
})

sound.Add({
name = “Weapon_SCAR.Clipin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/scar-h/SCAR_clipin.wav”
})

sound.Add({
name = “Weapon_SCAR.ClothMovement1”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/scar-h/SCAR_ClothMovement1.wav”
})

sound.Add({
name = “Weapon_SCAR.BoltTap”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/scar-h/SCAR_BoltTap.wav”
})

sound.Add({
name = “Weapon_SCAR.BoltRelease”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/scar-h/SCAR_BoltRelease.wav”
})

//G36C

sound.Add({
name = “weapos_aug.deploy”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/draw.wav”
})

sound.Add({
name = “weapos_aug.handle”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/handle.wav”
})

sound.Add({
name = “weapos_aug.cloth”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/cloth.wav”
})

sound.Add({
name = “weapos_aug.cloth2”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/cloth2.wav”
})

sound.Add({
name = “weapos_aug.magout”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/magout.wav”
})

sound.Add({
name = “weapos_aug.magin”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/magin.wav”
})

sound.Add({
name = “weapos_aug.boltpull”,
channel = CHAN_ITEM,
volume = 1.0,
sound = “RazorSWEP/G36C/boltpull.wav”
})
[/LUA]
I have hexed all the .mdl files to the exact name of the sound but that did not work.

Sound scripts aren’t written like that anymore. You can’t just take the script txt file and put that into a lua file.

Instead you should do this:
Create a lua file and name it whatever you like.
Put this code into the lua file.


local ReloadSound = {}
//KSG-12
ReloadSound["ksg12.Pump"] = "RazorSWEP/mw3_ksg12/mw3_ksg12_pump.wav" 
ReloadSound["ksg12.Insertshell"] = "RazorSWEP/mw3_ksg12/mw3_ksg12_insertshell.wav"

At the very top of the script, you should have the line “local ReloadSound”, but substitute “ReloadSound” with the name of the actual lua file. You only need to have “Local ReloadSound” written once at the very top. I keep it “ReloadSound” so I know what the file does.
Then just follow what I did up there for each sound. You can also do this for firing sounds.

Oh, ok I’ll try that and see what happens.

[editline]29th August 2014[/editline]

Did you mean if I did this for example:
[LUA]
local RazorSound = {}
[/LUA]
then all the lines have to be like this?
[LUA]
//KSG-12
RazorSound[“ksg12.Pump”] = “RazorSWEP/mw3_ksg12/mw3_ksg12_pump.wav”
RazorSound[“ksg12.Insertshell”] = “RazorSWEP/mw3_ksg12/mw3_ksg12_insertshell.wav”
[/LUA]
Also do I just drop this into lua/autorun for the server?

I tried what you told me but it just does not seem to work. I made the lua file and dumped it into lua/autorun, and it still didn’t play any reloading sounds.

Try adding this to the bottom of your script and see if it works.


local tbl = {channel = CHAN_STATIC,
	volume = 1,
	soundlevel = 70,
	pitchstart = 100,
	pitchend = 100}
	
for k, v in pairs(RazorSound) do
	tbl.name = k
	tbl.sound = v
	
	sound.Add(tbl)
end

local snd.Add = sound.Add

tbl = {channel = CHAN_STATIC,
	volume = 1,
	soundlevel = 70,
	pitchstart = 100,
	pitchend = 100}
	
function AddReloadSound(event, sound)
	tbl.name = event
	tbl.sound = sound
	
	snd.Add(tbl)
end

Credit for this piece of code goes to LEETNOOB, which came from his Customizable Weaponry pack.

EDIT: You can put this in either the lua/autorun/client(so only the player who is reloading will hear the sounds) or just the lua/autorun/ (which means everyone on the server will hear it, including the player reloading. The sound should get quieter the further away someone is from the person who is reloading).

Still have nothing, is it my gun codes?
Heres the weapon lua:
[LUA]
AddCSLuaFile()

SWEP.HoldType = “ar2”

if CLIENT then
SWEP.PrintName = “CheyTec Intervention”
SWEP.Slot = 2
SWEP.Icon = “vgui/ttt/icon_scout”
end

SWEP.Base = “weapon_tttbase”
SWEP.Spawnable = true

SWEP.Kind = WEAPON_HEAVY
SWEP.WeaponID = Sniper_Intervention

SWEP.Primary.Delay = 1
SWEP.Primary.Recoil = 7
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “357”
SWEP.Primary.Damage = 70
SWEP.Primary.Cone = 0.005
SWEP.Primary.ClipSize = 5
SWEP.Primary.ClipMax = 40
SWEP.Primary.DefaultClip = 5

SWEP.HeadshotMultiplier = 1.5

SWEP.AutoSpawnable = true
SWEP.AmmoEnt = “item_ammo_357_ttt”

SWEP.UseHands = true
SWEP.ViewModelFlip = true
SWEP.ViewModelFOV = 70
SWEP.ViewModel = Model(“models/RazorSWEP/v_INTERVENTION.mdl”)
SWEP.WorldModel = Model(“models/RazorSWEP/w_INTERVENTION.mdl”)

SWEP.Primary.Sound = Sound(“RazorSWEP/Intervention/Fire.wav”)
SWEP.DeploySpeed = 2

function SWEP:Deploy()
self:EmitSound(“RazorSWEP/Intervention/Deploy.wav”)

return self.BaseClass.Deploy(self)
end

SWEP.Secondary.Sound = Sound(“Default.Zoom”)

SWEP.IronSightsPos = Vector(-11.961, -20, 1.679)
SWEP.IronSightsAng = Vector(0, 0, 0)

function SWEP:SetZoom(state)
if CLIENT then
return
elseif IsValid(self.Owner) and self.Owner:IsPlayer() then
if state then
self.Owner:SetFOV(20, 0.3)
else
self.Owner:SetFOV(0, 0.2)
end
end
end

– Add some zoom to ironsights for this gun
function SWEP:SecondaryAttack()
if not self.IronSightsPos then return end
if self:GetNextSecondaryFire() > CurTime() then return end

local bIronsights = not self:GetIronsights()

self:SetIronsights( bIronsights )

if SERVER then
    self:SetZoom(bIronsights)
 else
    self:EmitSound(self.Secondary.Sound)
end

self:SetNextSecondaryFire( CurTime() + 0.3)

end

function SWEP:PreDrop()
self:SetZoom(false)
self:SetIronsights(false)
return self.BaseClass.PreDrop(self)
end

local Time = CurTime()

function SWEP:Reload()
if ( self:Clip1() == self.Primary.ClipSize or self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
self:DefaultReload( ACT_VM_RELOAD )
self:SetIronsights( false )
self:SetZoom( false )
end

function SWEP:Holster()
self:SetIronsights(false)
self:SetZoom(false)
return true
end

if CLIENT then
local scope = surface.GetTextureID(“sprites/scope”)
function SWEP:DrawHUD()
if self:GetIronsights() then
surface.SetDrawColor( 0, 0, 0, 255 )

     local x = ScrW() / 2.0
     local y = ScrH() / 2.0
     local scope_size = ScrH()

     -- crosshair
     local gap = 80
     local length = scope_size
     surface.DrawLine( x - length, y, x - gap, y )
     surface.DrawLine( x + length, y, x + gap, y )
     surface.DrawLine( x, y - length, x, y - gap )
     surface.DrawLine( x, y + length, x, y + gap )

     gap = 0
     length = 50
     surface.DrawLine( x - length, y, x - gap, y )
     surface.DrawLine( x + length, y, x + gap, y )
     surface.DrawLine( x, y - length, x, y - gap )
     surface.DrawLine( x, y + length, x, y + gap )


     -- cover edges
     local sh = scope_size / 2
     local w = (x - sh) + 2
     surface.DrawRect(0, 0, w, scope_size)
     surface.DrawRect(x + sh - 2, 0, w, scope_size)

     surface.SetDrawColor(255, 0, 0, 255)
     surface.DrawLine(x, y, x + 1, y + 1)

     -- scope
     surface.SetTexture(scope)
     surface.SetDrawColor(255, 255, 255, 255)

     surface.DrawTexturedRectRotated(x, y, scope_size, scope_size, 0)

  else
     return self.BaseClass.DrawHUD(self)
  end

end

function SWEP:AdjustMouseSensitivity()
return (self:GetIronsights() and 0.2) or nil
end
end
[/LUA]
This is the sound lua you told me to make, I put it into lua/autorun:
[LUA]
local RazorSound = {}
//870
RazorSound[“Weapos_M3.Pump”] = “RazorSWEP/870/870_pump.wav”
RazorSound[“Weapos_M3.Insertshell”] = “RazorSWEP/870/870_insertshell.wav”
//INTERVENTION
RazorSound[“Weapon_INT.Clipin”] = “RazorSWEP/Intervention/Clipin.wav”
RazorSound[“Weapon_INT.Clipout”] = “RazorSWEP/Intervention/Clipout.wav”
RazorSound[“Weapon_INT.bolt”] = “RazorSWEP/Intervention/Bolt.wav”
RazorSound[“Weapon_INT.Draw”] = “RazorSWEP/Intervention/Draw.wav”
//KAR98K
RazorSound[“Weapon_KAR.Clipout”] = “RazorSWEP/KAR98K/KARClipout.wav”
RazorSound[“Weapon_KAR.bolt”] = “RazorSWEP/KAR98K/KARBolt.wav”
RazorSound[“Weapon_KAR.draw”] = “RazorSWEP/KAR98K/KARDeploy.wav”
RazorSound[“Weapon_KAR.Clipin”] = “RazorSWEP/KAR98K/KARClipin.wav”
//KSG-12
RazorSound[“ksg12.Pump”] = “RazorSWEP/mw3_ksg12/mw3_ksg12_pump.wav”
RazorSound[“ksg12.Insertshell”] = “RazorSWEP/mw3_ksg12/mw3_ksg12_insertshell.wav”
RazorSound[“ksg12.Pump2”] = “RazorSWEP/mw3_ksg12/mw3_ksg12_pump2.wav”
RazorSound[“ksg12.Deploy”] = “RazorSWEP/Intervention/Draw.wav”
//PKP Pecheneg
RazorSound[“MW3_PKP_Pecheneg.Coverup”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_coverup.wav”
RazorSound[“MW3_PKP_Pecheneg.Chainout”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_chainout.wav”
RazorSound[“MW3_PKP_Pecheneg.Boxout”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boxout.wav”
RazorSound[“MW3_PKP_Pecheneg.Boxin”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boxin.wav”
RazorSound[“MW3_PKP_Pecheneg.Chainin”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_chainin.wav”
RazorSound[“MW3_PKP_Pecheneg.Coverdown”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_coverdown.wav”
RazorSound[“MW3_PKP_Pecheneg.Boltpull”] = “RazorSWEP/mw3_pkp_pecheneg/mw3_pkp_pecheneg_boltpull.wav”
RazorSound[“MW3_PKP_Pecheneg.Deploy”] = “RazorSWEP/Intervention/Draw.wav”
//Spas12
RazorSound[“Weapon_12.Pump”] = “RazorSWEP/Spas12/spas_pump.wav”
RazorSound[“Weapon_12.Insertshell”] = “RazorSWEP/Spas12/spas_insertshell.wav”
//Scar-H
RazorSound[“Weapon_Scar.Clipout”] = “RazorSWEP/scar-h/SCAR_clipout.wav”
RazorSound[“Weapon_Scar.Clipin”] = “RazorSWEP/scar-h/SCAR_clipin.wav”
RazorSound[“Weapon_Scar.ClothMovement1”] = “RazorSWEP/scar-h/SCAR_ClothMovement1.wav”
RazorSound[“Weapon_Scar.BoltTap”] = “RazorSWEP/scar-h/SCAR_BoltTap.wav”
RazorSound[“Weapon_Scar.BoltRelease”] = “RazorSWEP/scar-h/SCAR_BoltRelease.wav”
//G36C
RazorSound[“Weapos_aug.deploy”] = “RazorSWEP/G36C/draw.wav”
RazorSound[“Weapos_aug.handle”] = “RazorSWEP/G36C/handle.wav”
RazorSound[“Weapos_aug.cloth”] = “RazorSWEP/G36C/cloth.wav”
RazorSound[“Weapos_aug.cloth2”] = “RazorSWEP/G36C/cloth2.wav”
RazorSound[“Weapos_aug.magout”] = “RazorSWEP/G36C/magout.wav”
RazorSound[“Weapos_aug.magin”] = “RazorSWEP/G36C/magin.wav”
RazorSound[“Weapos_aug.boltpull”] = “RazorSWEP/G36C/boltpull.wav”

local tbl = {channel = CHAN_STATIC,
volume = 1,
soundlevel = 70,
pitchstart = 100,
pitchend = 100}

for k, v in pairs(RazorSound) do
tbl.name = k
tbl.sound = v

sound.Add(tbl)

end

local snd.Add = sound.Add

tbl = {channel = CHAN_STATIC,
volume = 1,
soundlevel = 70,
pitchstart = 100,
pitchend = 100}

function AddReloadSound(event, sound)
tbl.name = event
tbl.sound = sound

snd.Add(tbl)

end
[/LUA]
My Sound files are kept in Sound/RazorSWEP/Intervention/
My Model files are kept in Models/RazorSWEP/

Does your firing sound work? Because it seems you didn’t reference it the same way you’re trying to reference the reload sounds.
What I mean is, you have “Weapon_INT.Clipin” for the clip in sound/event, but you didn’t do that for the firing sound.


SWEP.Primary.Sound			= Sound("Name")

Where instead of “Name” you should put the hexed “Weapon_Int.Single” or whatever the firing event was.

Normally when you do this, it references what reload sounds it uses as well.
Also, you can change the Deploy sound to


self:EmitSound("Weapon_INT.Draw")

See if that works.

Nope that didn’t work either.

The sound should use CHAN_WEAPON

It didn’t do anything different to any of the weapons. :I