```lua
local icol = Color(255, 255, 255, 255)
if CLIENT then
    local weapons = {"m9k_1887winchester", "m9k_1897winchester", "m9k_ares_shrike", "m9k_aw50", "m9k_barret_m82", "m9k_browningauto5", "m9k_contender", "m9k_dbarrel", "m9k_dragunov", "m9k_fg42", "m9k_intervention", "m9k_ithacam37", "m9k_jackhammer", "m9k_m3", "m9k_m24", "m9k_m60", "m9k_m98b", "m9k_m249lmg", "m9k_m1918bar", "m9k_minigun", "m9k_mossberg590", "m9k_psg1", "m9k_remington870", "m9k_remington7615p", "m9k_sl8", "m9k_svu", "m9k_usas", "m9k_spas12", "m9k_svt40", "m9k_striker12", "m9k_pkm"}
    for _, weapon in ipairs(weapons) do
        killicon.Add(weapon, "vgui/hud/" .. weapon, icol)
    end
end

local FCVAR_FLAGS = {FCVAR_REPLICATED, FCVAR_NOTIFY, FCVAR_ARCHIVE}
local function CreateConfigVar(name, defaultValue, flags, description)
    if GetConVar(name) == nil then
        CreateConVar(name, defaultValue, flags, description)
        print(name .. " con var created")
    end
end

local configVars = {{"DebugM9K", "0", "Debugging for some m9k stuff, turning it on won't change much."}, {"M9KWeaponStrip", "0", "Allow empty weapon stripping? 1 for true, 0 for false"}, {"M9KDisablePenetration", "0", "Disable Penetration and Ricochets? 1 for true, 0 for false"}, {"M9KDynamicRecoil", "1", "Use Aim-modifying recoil? 1 for true, 0 for false"}, {"M9KAmmoDetonation", "1", "Enable detonatable M9K Ammo crates? 1 for true, 0 for false."}, {"M9KDamageMultiplier", "1", "Multiplier for M9K bullet damage."}, {"M9KDefaultClip", "-1", "How many clips will a weapon spawn with? Negative reverts to default values."}, {"M9KUniqueSlots", "1", "Give M9K Weapons unique slots? 1 for true, 2 for false. A map change may be required."}}
for _, var in ipairs(configVars) do
    CreateConfigVar(var[1], var[2], FCVAR_FLAGS, var[3])
end

if not game.SinglePlayer() then
    CreateConfigVar("M9KClientGasDisable", "0", FCVAR_FLAGS, "Turn off gas effect for all clients? 1 for yes, 0 for no.")
    if SERVER then
        local function ClientSideGasDisabler()
            timer.Create("ClientGasBroadcastTimer", 15, 0, function() BroadcastLua("RunConsoleCommand(\"M9KGasEffect\", \"0\")") end)
        end

        if GetConVar("M9KClientGasDisable"):GetBool() then ClientSideGasDisabler() end
        local function M9K_Svr_Gas_Change_Callback(cvar, previous, new)
            if tobool(new) then
                ClientSideGasDisabler()
                BroadcastLua("print(\"Gas effects disabled on this server!\")")
            else
                BroadcastLua("print(\"Gas effects re-enabled on this server.\")")
                BroadcastLua("print(\"You may turn on M9KGasEffect if you wish.\")")
                if timer.Exists("ClientGasBroadcastTimer") then timer.Remove("ClientGasBroadcastTimer") end
            end
        end

        cvars.AddChangeCallback("M9KClientGasDisable", M9K_Svr_Gas_Change_Callback)
    end

    if CLIENT then CreateConfigVar("M9KGasEffect", "1", {true, true}, "Use gas effect when shooting? 1 for true, 0 for false") end
else
    CreateConfigVar("M9KGasEffect", "1", FCVAR_FLAGS, "Use gas effect when shooting? 1 for true, 0 for false")
end

local defaultVolume = 1.0
local defaultChannel = CHAN_ITEM
local function addSound(soundData)
    if not soundData.name or not soundData.soundFile then
        return
    end

    sound.Add({
        name = soundData.name,
        channel = soundData.channel or defaultChannel,
        volume = soundData.volume or defaultVolume,
        level = soundData.level or 75,
        pitch = soundData.pitch or {95, 110},
        sound = soundData.soundFile
    })
end

local function createSoundData(name, channel, soundFile)
    return {
        name = name,
        channel = channel,
        soundFile = soundFile
    }
end

local pkmSounds = {
    createSoundData(
        "pkm.single",
        CHAN_USER_BASE + 10,
        {
            "weapons/pkm/pkm-1.wav",
            "weapons/pkm/pkm-2.wav",
            "weapons/pkm/pkm-3.wav",
            "weapons/pkm/pkm-4.wav",
            "weapons/pkm/pkm-5.wav"
        }
    ),
    createSoundData("Weapon_PKM.Cloth", nil, "weapons/pkm/pkm_cloth.mp3"),
    createSoundData("Weapon_PKM.Coverup", nil, "weapons/pkm/pkm_coverup.mp3"),
    createSoundData("Weapon_PKM.Bullet", nil, "weapons/pkm/pkm_bullet.mp3"),
    createSoundData("Weapon_PKM.Boxout", nil, "weapons/pkm/pkm_boxout.mp3"),
    createSoundData("Weapon_PKM.Boxin", nil, "weapons/pkm/pkm_boxin.mp3"),
    createSoundData("Weapon_PKM.Chain", nil, "weapons/pkm/pkm_chain.mp3"),
    createSoundData("Weapon_PKM.Coverdown", nil, "weapons/pkm/pkm_coverdown.mp3"),
    createSoundData("Weapon_PKM.Coversmack", nil, "weapons/pkm/pkm_coversmack.mp3"),
    createSoundData("Weapon_PKM.Bolt", nil, "weapons/pkm/pkm_bolt.mp3"),
    createSoundData("Weapon_PKM.Draw", nil, "weapons/pkm/pkm_draw.mp3")
}
local svt40Sounds = {
    createSoundData("Weapon_SVT40.single", CHAN_USER_BASE + 10, "weapons/svt40/g3sg1-1.wav"),
    createSoundData("Weapon_SVT40.Cloth1", nil, "weapons/svt40/g3sg1_cloth1.mp3"),
    createSoundData("Weapon_SVT40.Cloth2", nil, "weapons/svt40/g3sg1_cloth2.mp3"),
    createSoundData("Weapon_SVT40.Clipout", nil, "weapons/svt40/g3sg1_clipout.mp3"),
    createSoundData("Weapon_SVT40.Clipin", nil, "weapons/svt40/g3sg1_clipin.mp3"),
    createSoundData("Weapon_SVT40.ClipTap", nil, "weapons/svt40/g3sg1_cliptap.mp3"),
    createSoundData("Weapon_SVT40.SlideBack", nil, "weapons/svt40/g3sg1_slide_b.mp3"),
    createSoundData("Weapon_SVT40.SlideForward", nil, "weapons/svt40/g3sg1_slide_f.mp3")
}
local spas12Sounds = {
    createSoundData("spas_12_shoty.Single", CHAN_USER_BASE + 10, "weapons/spas_12/xm1014-1.wav"),
    createSoundData("spas_12_shoty.insert", nil, "weapons/spas_12/xm_insert.mp3"),
    createSoundData("spas_12_shoty.cock", nil, "weapons/spas_12/xm_cock.mp3")
}
local usasSounds = {
    createSoundData("Weapon_usas.Single", CHAN_USER_BASE + 10, "weapons/usas12/xm1014-1.wav"),
    createSoundData("Weapon_usas.clipin", nil, "weapons/usas12/magin.mp3"),
    createSoundData("Weapon_usas.clipout", nil, "weapons/usas12/magout.mp3"),
    createSoundData("Weapon_usas.draw", nil, "weapons/usas12/draw.mp3")
}
local remingtonSounds = {
    createSoundData("Weapon_7615P.Single", CHAN_USER_BASE + 10, "weapons/7615p/scout_fire-1.wav"),
    createSoundData("Weapon_7615P.Clipin", nil, "weapons/7615p/sg550_clipin.mp3"),
    createSoundData("Weapon_7615P.Clipout", nil, "weapons/7615p/sg550_clipout.mp3"),
    createSoundData("Weapon_7615P.Pump", nil, "weapons/7615p/m3_pump.mp3")
}
local svuSounds = {
    createSoundData("Weapon_SVU.Single", CHAN_USER_BASE + 10, "weapons/svu/g3sg1-1.wav"),
    createSoundData("Weapon_SVU.Clipin", nil, "weapons/svu/g3sg1_clipin.mp3"),
    createSoundData("Weapon_SVU.Clipout", nil, "weapons/svu/g3sg1_clipout.mp3"),
    createSoundData("Weapon_SVU.Slide", nil, "weapons/svu/g3sg1_slide.mp3")
}
local win94Sounds = {
    createSoundData("Weapon_Win94.Single", CHAN_USER_BASE + 10, "weapons/win94/scout_fire-1.wav"),
    createSoundData("Weapon_Win94.Bolt", nil, "weapons/win94/scout_bolt.mp3"),
    createSoundData("weapons/hamburgpling.wav", nil, "weapons/win94/hamburgpling.mp3"),
    createSoundData("Weapon_Win94.Clipout", nil, "weapons/win94/scout_clipout.mp3")
}
local striker12Sounds = {
    createSoundData("ShotStriker12.Single", CHAN_USER_BASE + 10, "weapons/striker12/xm1014-1.wav"),
    createSoundData("ShotStriker12.Deploy", nil, "weapons/striker12/deploy.mp3"),
    createSoundData("ShotStriker12.InsertShell", nil, "weapons/striker12/m3_insertshell.mp3")
}
local awpSounds = {
    createSoundData("Weaponaw50.Single", CHAN_USER_BASE + 10, "weapons/aw50/awp_fire.wav"),
    createSoundData("Weaponaw50.clipin", nil, "weapons/aw50/awp_magin.mp3"),
    createSoundData("Weaponaw50.clipout", nil, "weapons/aw50/awp_magout.mp3"),
    createSoundData("Weaponaw50.boltback", nil, "weapons/aw50/m24_boltback.mp3"),
    createSoundData("Weaponaw50.boltforward", nil, "weapons/aw50/m24_boltforward.mp3")
}
local psgSounds = {
    createSoundData("Weapon_psg_1.Single", CHAN_USER_BASE + 10, "weapons/psg1/g3sg1-1.wav"),
    createSoundData("Weapon_psg_1.Back", nil, "weapons/psg1/psg_boltpull.mp3"),
    createSoundData("Weapon_psg_1.Clipout", nil, "weapons/psg1/psg_clipout.mp3"),
    createSoundData("Weapon_psg_1.Clipin", nil, "weapons/psg1/psg_clipin.mp3"),
    createSoundData("Weapon_psg_1.Forward", nil, "weapons/psg1/psg_boltrelease.mp3"),
    createSoundData("Weapon_psg_1.Deploy", nil, "weapons/psg1/deploy1.mp3")
}
local contender_g2Sounds = {
    createSoundData(
        "contender_g2.Single",
        CHAN_USER_BASE + 10,
        {"weapons/g2contender/scout-1.wav", "weapons/g2contender/scout-2.wav", "weapons/g2contender/scout-3.wav"}
    ),
    createSoundData(
        "contender_g2.Hammer",
        CHAN_USER_BASE + 1,
        {"weapons/g2contender/Cock-1.mp3", "weapons/g2contender/Cock-2.mp3"}
    ),
    createSoundData("contender_g2.Open", CHAN_ITEM, "weapons/g2contender/open_chamber.mp3"),
    createSoundData("contender_g2.Shellout", CHAN_USER_BASE + 1, "weapons/g2contender/Bullet_out.mp3"),
    createSoundData("contender_g2.Shellin", CHAN_ITEM, "weapons/g2contender/Bullet_in.mp3"),
    createSoundData("contender_g2.Close", CHAN_ITEM, "weapons/g2contender/close_chamber.mp3"),
    createSoundData(
        "contender_g2.Shell",
        CHAN_USER_BASE + 2,
        {
            "weapons/g2contender/pl_shell1.mp3",
            "weapons/g2contender/pl_shell2.mp3",
            "weapons/g2contender/pl_shell3.mp3",
            "weapons/g2contender/pl_shell4.mp3"
        }
    )
}
local m98Sounds = {
    createSoundData("M98.Single", CHAN_USER_BASE + 10, "weapons/M98/shot-1.wav"),
    createSoundData("M98_Bolt", nil, "weapons/M98/bolt.mp3"),
    createSoundData("M98_Handle", nil, "weapons/M98/handle.mp3"),
    createSoundData("M98_Deploy", nil, "weapons/M98/draw.mp3"),
    createSoundData("M98_Draw", nil, "weapons/M98/draw_2.mp3"),
    createSoundData("M98_Foley", nil, "weapons/M98/foley.mp3"),
    createSoundData("M98_Clipout", nil, "weapons/M98/clipout.mp3"),
    createSoundData("M98_Clipin", nil, "weapons/M98/clipin.mp3"),
    createSoundData("M98_Boltback", nil, "weapons/M98/boltback.mp3"),
    createSoundData("M98_Boltforward", nil, "weapons/M98/boltforward.mp3")
}
local barretM82Sounds = {
    createSoundData("BarretM82.Single", CHAN_USER_BASE + 10, "weapons/M82/barret50-1.wav"),
    createSoundData("Weapon_M82.Boltup", nil, "weapons/M82/boltup.mp3"),
    createSoundData("Weapon_M82.Clipin", nil, "weapons/M82/clipin.mp3"),
    createSoundData("Weapon_M82.Clipout", nil, "weapons/M82/clipout.mp3"),
    createSoundData("Weapon_M82.Boltdown", nil, "weapons/M82/boltdown.mp3")
}
local dmgfokM24SNSounds = {
    createSoundData("Dmgfok_M24SN.Single", CHAN_USER_BASE + 10, "weapons/dmg_m24/awp1.wav"),
    createSoundData("Dmgfok_M24SN.Clipin", nil, "weapons/dmg_m24/m24_magin.mp3"),
    createSoundData("Dmgfok_M24SN.Clipout", nil, "weapons/dmg_m24/m24_magout.mp3"),
    createSoundData("Dmgfok_M24SN.Boltback", nil, "weapons/dmg_m24/m24_boltback.mp3"),
    createSoundData("Dmgfok_M24SN.Boltforward", nil, "weapons/dmg_m24/m24_boltforward.mp3")
}
local svdSounds = {
    createSoundData("Weapon_svd01.Single", CHAN_USER_BASE + 10, "weapons/SVD/g3sg1-1.wav"),
    createSoundData("Weapon_SVD.Foley", nil, "weapons/SVD/foley.mp3"),
    createSoundData("Weapon_SVD.Handle", nil, "weapons/SVD/handle.mp3"),
    createSoundData("Weapon_SVD.Clipout", nil, "weapons/SVD/Clipout.mp3"),
    createSoundData("Weapon_SVD.Cliptap", nil, "weapons/SVD/Cliptap.mp3"),
    createSoundData("Weapon_SVD.Clipin", nil, "weapons/SVD/ClipIn.mp3"),
    createSoundData("Weapon_SVD.Slideback", nil, "weapons/SVD/SlideBack.mp3"),
    createSoundData("Weapon_SVD.SlideForward", nil, "weapons/SVD/SlideForward.mp3"),
    createSoundData("Weapon_SVD.Draw", nil, "weapons/SVD/Draw.mp3")
}
local hkSL8Sounds = {
    createSoundData(
        "Weapon_hksl8.Single",
        CHAN_USER_BASE + 10,
        {
            "weapons/hksl8/SG552-1.wav",
            "weapons/hksl8/SG552-2.wav",
            "weapons/hksl8/SG552-3.wav",
            "weapons/hksl8/SG552-4.wav"
        }
    ),
    createSoundData("sl8.Draw", nil, "weapons/hksl8/draw.mp3"),
    createSoundData("sl8.Safety", nil, "weapons/hksl8/safety.mp3"),
    createSoundData("sl8.Magout", nil, "weapons/hksl8/magout.mp3"),
    createSoundData("sl8.MagFiddle", nil, "weapons/hksl8/magfiddle.mp3"),
    createSoundData("sl8.MagIn", nil, "weapons/hksl8/magin.mp3"),
    createSoundData("sl8.BoltBack", nil, "weapons/hksl8/boltback.mp3"),
    createSoundData("sl8.Boltforward", nil, "weapons/hksl8/boltforward.mp3")
}
local interventionSounds = {
    createSoundData("Weapon_INT.Single", CHAN_USER_BASE + 10, "weapons/fokku_tc_intrv/int1.wav"),
    createSoundData("Weapon_INT.Deploy", nil, "weapons/fokku_tc_intrv/int_deploy.mp3"),
    createSoundData("Weapon_INT.Bolt", nil, "weapons/fokku_tc_intrv/int_bolt.mp3"),
    createSoundData("Weapon_INT.Clipout", nil, "weapons/fokku_tc_intrv/int_clipout.mp3"),
    createSoundData("Weapon_INT.Clipin", nil, "weapons/fokku_tc_intrv/int_clipin.mp3")
}
local winchester1887Sounds = {
    createSoundData("1887winch.Single", CHAN_USER_BASE + 10, "weapons/1887winchester/1887-1.wav"),
    createSoundData("1887winch.Insertshell", nil, "weapons/1887winchester/1887_insertshell.mp3"),
    createSoundData("1887winch.Pump", nil, "weapons/1887winchester/1887pump1.mp3"),
    createSoundData("1887pump2.Pump", nil, "weapons/1887winchester/1887pump2.mp3")
}
local trench97Sounds = {
    createSoundData("Trench_97.Single", CHAN_USER_BASE + 10, "weapons/1897trench/m3-1.wav"),
    createSoundData("Trench_97.Insertshell", nil, "weapons/1897trench/m3_insertshell.mp3"),
    createSoundData("Trench_97.Pump", nil, "weapons/1897trench/m3_pump.mp3"),
    createSoundData("Trench_07.Pump", nil, "weapons/1897trench/1897_deploy.mp3")
}
local browningA5Sounds = {
    createSoundData("Weapon_a5.Single", CHAN_USER_BASE + 10, "weapons/browninga5/xm1014-1.wav"),
    createSoundData("Weapon_bauto5.InsertShell", nil, "weapons/browninga5/xm1014_insertshell.mp3"),
    createSoundData("Weapon_a5.back", nil, "weapons/browninga5/xm1014_check.mp3"),
    createSoundData("Weapon_a5.draw", nil, "weapons/browninga5/xm1014_deploy.mp3")
}
local doubleBarrelSounds = {
    createSoundData("Double_Barrel.Single", CHAN_USER_BASE + 10, "weapons/dbarrel/xm1014-1.wav"),
    createSoundData("dbarrel_dblast", CHAN_USER_BASE + 10, "weapons/dbarrel/dblast.wav"),
    createSoundData("Double_Barrel.InsertShell", nil, "weapons/dbarrel/xm1014_insertshell.mp3"),
    createSoundData("Double_Barrel.barreldown", nil, "weapons/dbarrel/barreldown.mp3"),
    createSoundData("Double_Barrel.barrelup", nil, "weapons/dbarrel/barrelup.mp3")
}
local jackhammerSounds = {
    createSoundData("Weapon_Jackhammer.Single", CHAN_USER_BASE + 10, "weapons/jackhammer/xm1014-1.wav"),
    createSoundData("Weapon_Jackhammer.Clipout", nil, "weapons/jackhammer/clipout.mp3"),
    createSoundData("Weapon_Jackhammer.Clipin", nil, "weapons/jackhammer/magtap.mp3"),
    createSoundData("Weapon_Jackhammer.Forearm", nil, "weapons/jackhammer/boltcatch.mp3"),
    createSoundData("Weapon_Jackhammer.Cloth", nil, "weapons/jackhammer/cloth.mp3")
}
local ithacaM37Sounds = {
    createSoundData("IthacaM37.Single", CHAN_USER_BASE + 10, "weapons/m37/m3-1.wav"),
    createSoundData("IthacaM37.Insertshell", nil, "weapons/m37/m3_insertshell.mp3"),
    createSoundData("IthacaM37.Pump", nil, "weapons/m37/m3_pump.mp3")
}
local mberg590Sounds = {
    createSoundData("Mberg_590.Single", CHAN_USER_BASE + 10, "weapons/590/m3-1.wav"),
    createSoundData("Mberg_590.Insertshell", nil, "weapons/590/m3_insertshell.mp3"),
    createSoundData("Mberg_590.Pump", nil, "weapons/590/m3_pump.mp3"),
    createSoundData("Mberg_590.Bullet", nil, "weapons/590/m3_bullet.mp3"),
    createSoundData("Mberg_590.Draw", nil, "weapons/590/m3_draw.mp3")
}
local shrikeSounds = {
    createSoundData("Weapon_shrk.Single", CHAN_USER_BASE + 10, "weapons/shrike/shrike-1.wav"),
    createSoundData("Weapon_shrk.bOut", nil, "weapons/shrike/boxout.mp3"),
    createSoundData("Weapon_shrk.Button", nil, "weapons/shrike/button.mp3"),
    createSoundData("Weapon_shrk.cUp", nil, "weapons/shrike/coverup.mp3"),
    createSoundData("Weapon_shrk.Bullet1", nil, "weapons/shrike/bullet.mp3"),
    createSoundData("Weapon_shrk.bIn", nil, "weapons/shrike/boxin.mp3"),
    createSoundData("Weapon_shrk.Bullet2", nil, "weapons/shrike/bullet.mp3"),
    createSoundData("Weapon_shrk.cDown", nil, "weapons/shrike/coverdown.mp3"),
    createSoundData("Weapon_shrk.Ready", nil, "weapons/shrike/ready.mp3")
}
local m60Sounds = {
    createSoundData("Weapon_M_60.Single", CHAN_USER_BASE + 10, "weapons/m60/m60-1.wav"),
    createSoundData("Weapon_M_60.Coverup", nil, "weapons/m60/m60_coverup.mp3"),
    createSoundData("Weapon_M_60.Boxout", nil, "weapons/m60/m60_boxout.mp3"),
    createSoundData("Weapon_M_60.Boxin", nil, "weapons/m60/m60_boxin.mp3"),
    createSoundData("Weapon_M_60.Chain", nil, "weapons/m60/m60_chain.mp3"),
    createSoundData("Weapon_M_60.Coverdown", nil, "weapons/m60/m60_coverdown.mp3")
}
local m249Sounds = {
    createSoundData("Weapon_249M.Single", CHAN_USER_BASE + 10, "weapons/schmung.M249/m249-1.wav"),
    createSoundData("Weapon_249M.Coverdown", nil, "weapons/schmung.M249/m249_coverdown.mp3"),
    createSoundData("Weapon_249M.Chain", nil, "weapons/schmung.M249/m249_chain.mp3"),
    createSoundData("Weapon_249M.Coverup", nil, "weapons/schmung.M249/m249_coverup.mp3"),
    createSoundData("Weapon_249M.Boxout", nil, "weapons/schmung.M249/m249_boxout.mp3"),
    createSoundData("Weapon_Flakk249.Magin", nil, "weapons/schmung.M249/magin.mp3"),
    createSoundData("Weapon_Flakk249.Boltpull", nil, "weapons/schmung.M249/boltpull.mp3"),
    createSoundData("Weapon_Flakk249.Boltrel", nil, "weapons/schmung.M249/boltrel.mp3")
}
local blackVulcanSounds = {
    createSoundData("BlackVulcan.Single", CHAN_USER_BASE + 10, "weapons/minigun/mini-1.wav"),
    createSoundData("BlackVulcan.Boxout", nil, "weapons/minigun/mini_boxout.mp3"),
    createSoundData("BlackVulcan.Coverup", nil, "weapons/minigun/mini_coverup.mp3"),
    createSoundData("BlackVulcan.Boxin", nil, "weapons/minigun/mini_boxin.mp3"),
    createSoundData("BlackVulcan.Chain", nil, "weapons/minigun/mini_chain.mp3"),
    createSoundData("BlackVulcan.Coverdown", nil, "weapons/minigun/mini_coverdown.mp3")
}
local fg42Sounds = {
    createSoundData("FG42_weapon.Single", CHAN_USER_BASE + 10, "weapons/fg42/ak47-1.wav"),
    createSoundData("FG42_weapon.Clipout", nil, "weapons/fg42/ak47_clipout.mp3"),
    createSoundData("FG42_weapon.Clipin", nil, "weapons/fg42/ak47_clipin.mp3"),
    createSoundData("FG42_weapon.BoltPull", nil, "weapons/fg42/ak47_boltpull.mp3")
}
local bar1Sounds = {
    createSoundData("Weapon_bar1.clipin", nil, "weapons/jen.ak/mag.in.mp3"),
    createSoundData("Weapon_bar1.clipout", nil, "weapons/jen.ak/mag.out.mp3"),
    createSoundData("Weapon_bar1.mag.tap", nil, "weapons/jen.ak/mag.tap.mp3"),
    createSoundData("Weapon_bar1.boltpull", nil, "weapons/jen.ak/bolt.pull.mp3"),
    createSoundData("Weapon_bar1.bolt.rel", nil, "weapons/jen.ak/bolt.rel.mp3"),
    createSoundData("Weapon_bar1.Single", CHAN_USER_BASE + 10, "weapons/jen.ak/fire.wav"),
    createSoundData("3rd_Weapon_bar1.Single", CHAN_USER_BASE + 10, "weapons/jen.ak/fire.wav")
}
local rem870Sounds = {
    createSoundData("WepRem870.single", CHAN_USER_BASE + 10, "weapons/tact870/m3-1.wav"),
    createSoundData("WepRem870.pump", nil, "weapons/tact870/m3_pump.mp3"),
    createSoundData("WepRem870.Insertshell", nil, "weapons/tact870/m3_insertshell.mp3")
}
local benelliM3Sounds = {
    createSoundData("BenelliM3.single", CHAN_USER_BASE + 10, "weapons/BenelliM3/m3-1.wav"),
    createSoundData("BenelliM3.insertshell", nil, "weapons/BenelliM3/m3_insertshell.mp3"),
    createSoundData("BenelliM3.Pump", nil, "weapons/BenelliM3/m3_pump.mp3")
}
local soundGroups = {pkmSounds, svt40Sounds, spas12Sounds, usasSounds, remingtonSounds, svuSounds, win94Sounds, striker12Sounds, awpSounds, psgSounds, contender_g2Sounds, m98Sounds, barretM82Sounds, dmgfokM24SNSounds, svdSounds, hkSL8Sounds, interventionSounds, winchester1887Sounds, trench97Sounds, browningA5Sounds, doubleBarrelSounds, jackhammerSounds, ithacaM37Sounds, mberg590Sounds, shrikeSounds, m60Sounds, m249Sounds, blackVulcanSounds, fg42Sounds, bar1Sounds, rem870Sounds, benelliM3Sounds}
for _, soundGroup in ipairs(soundGroups) do
    for _, soundData in ipairs(soundGroup) do
        addSound(soundData)
    end
end

local m9knpw = {"m9k_davy_crockett_explo", "m9k_gdcwa_matador_90mm", "m9k_gdcwa_rpg_heat", "m9k_improvised_explosive", "m9k_launched_davycrockett", "m9k_launched_ex41", "m9k_launched_m79", "m9k_m202_rocket", "m9k_mad_c4", "m9k_milkor_nade", "m9k_nervegasnade", "m9k_nitro_vapor", "m9k_oribital_cannon", "m9k_poison_parent", "m9k_proxy", "m9k_released_poison", "m9k_sent_nuke_radiation", "m9k_thrown_harpoon", "m9k_thrown_knife", "m9k_thrown_m61", "m9k_thrown_nitrox", "m9k_thrown_spec_knife", "m9k_thrown_sticky_grenade", "bb_dod_bazooka_rocket", "bb_dod_panzershreck_rocket", "bb_garand_riflenade", "bb_k98_riflenade", "bb_planted_dod_tnt", "bb_thrownalliedfrag", "bb_thrownaxisfrag", "bb_thrownsmoke_axis", "bb_thrownaxisfrag", "bb_planted_alt_c4", "bb_planted_css_c4", "bb_throwncssfrag", "bb_throwncsssmoke", "m9k_ammo_40mm", "m9k_ammo_40mm_single", "m9k_ammo_357", "m9k_ammo_ar2", "m9k_ammo_buckshot", "m9k_ammo_c4", "m9k_ammo_frags", "m9k_ammo_ieds", "m9k_ammo_nervegas", "m9k_ammo_nuke", "m9k_ammo_pistol", "m9k_ammo_proxmines", "m9k_ammo_rockets", "m9k_ammo_smg", "m9k_ammo_sniper_rounds", "m9k_ammo_stickynades", "m9k_ammo_winchester"}
function PocketM9KWeapons(ply, wep)
    if not IsValid(wep) then return end
    local class = wep:GetClass()
    return not table.HasValue(m9knpw, class)
end

hook.Add("canPocket", "PocketM9KWeapons", PocketM9KWeapons)
heavy_autorun_mounted = true
```
Optimize the code and fix possible bugs, write a complete code implementation