Оптимизируй файлы сохранив логику и не ломая синхронизацию.
```lua
-- cl_fp.lua
stwFP = stwFP or {}
local fpEnabled = false

local nonFPWeapons = {
    weapon_physgun = true,
    gmod_tool = true,
    weapon_physcannon = true,
    gmod_camera = true,
}

-- Предварительно определенные таблицы для цветовой модификации
local blindColorModify = {
    ['$pp_colour_addr'] = 0,
    ['$pp_colour_addg'] = 0,
    ['$pp_colour_addb'] = 0,
    ['$pp_colour_brightness'] = -1,
    ['$pp_colour_contrast'] = 1,
    ['$pp_colour_colour'] = 1,
    ['$pp_colour_mulr'] = 0,
    ['$pp_colour_mulg'] = 0,
    ['$pp_colour_mulb'] = 0,
}

local fpColorModify = table.Copy(blindColorModify)

-- Кэширование названия кости головы
local headBoneName = 'ValveBiped.Bip01_Head1'

-- Функция скрытия или показа головы игрока
function stwFP.hideHead(hidden)
    local ply = LocalPlayer()
    if not IsValid(ply) then return end

    local bone = ply:LookupBone(headBoneName) or 0
    local scale = hidden and Vector(0.01, 0.01, 0.01) or Vector(1, 1, 1)
    ply:ManipulateBoneScale(bone, scale)

    ply.headHided = hidden
end

-- Функция применения или удаления эффекта ослепления
function stwFP.blind(applyBlind)
    if applyBlind then
        hook.Add('RenderScreenspaceEffects', 'qwb_fp_setBlind', function()
            DrawColorModify(blindColorModify)
        end)
    else
        hook.Remove('RenderScreenspaceEffects', 'qwb_fp_setBlind')
    end
end

-- Функция активации первого лица
function stwFP.startFP()
    fpEnabled = true
    if not LocalPlayer().headHided then
        stwFP.hideHead(true)
    end

    local texturesHit = false

    hook.Add('RenderScreenspaceEffects', 'qwb_fp_effects', function()
        if not texturesHit then return end
        DrawColorModify(fpColorModify)
    end)

    hook.Add('CalcView', 'qwb_fp_calcView', function(ply, origin, angles, fov, znear, zfar)
        if not IsValid(ply) or ply ~= LocalPlayer() then return end
        if not ply:LookupBone(headBoneName) then return end
        if not ply:Alive() then
            local ragdoll = ply:GetRagdollEntity()
            if IsValid(ragdoll) then
                local ragdollBone = ragdoll:LookupBone(headBoneName) or 0
                if ragdoll:GetManipulateBoneScale(ragdollBone) ~= Vector(0.01, 0.01, 0.01) then
                    ragdoll:ManipulateBoneScale(ragdollBone, Vector(0.01, 0.01, 0.01))
                end
                local pos, angRag = ragdoll:GetBonePosition(ragdollBone)
                return {
                    origin = pos,
                    angles = angRag + Angle(-90, 0, -90),
                    fov = fov,
                    drawviewer = false,
                }
            end
            return
        end

        local bonePos, _ = ply:GetBonePosition(ply:LookupBone(headBoneName))
        local cameraPos = bonePos + angles:Up() * 4 + ply:GetForward() * 1

        local filter = player.GetAll()
        table.insert(filter, ply:GetActiveWeapon())
        for _, ent in ipairs(ents.FindByClass('gmod_sent_vehicle_fphysics_base')) do
            table.insert(filter, ent)
        end

        local tr = util.TraceHull({
            start = bonePos,
            endpos = cameraPos,
            filter = filter,
            mins = Vector(-4.5, -4.5, -4.5),
            maxs = Vector(4.5, 4.5, 4.5),
        })

        cameraPos = tr.HitPos
        texturesHit = tr.Hit

        return {
            origin = cameraPos,
            angles = Angle(
                math.Clamp(angles.p, -65, 65),
                angles.y + math.sin(SysTime() / 1.5) * 0.5,
                angles.r + math.sin(SysTime()) * 0.5
            ),
            fov = fov,
            drawviewer = true,
        }
    end)

    hook.Add('InputMouseApply', 'qwb_fp_inputMouseApply', function(cmd, x, y, ang)
        ang.p = math.Clamp(ang.p + y / 50, -65, 65)
        ang.y = ang.y - x / 50
        cmd:SetViewAngles(ang)
        return true
    end)

    hook.Add('HUDShouldDraw', 'qwb_fp_hideCrosshair', function(name)
        if name == 'CHudCrosshair' then return false end
    end)
end

-- Функция отключения первого лица
function stwFP.stopFP()
    hook.Remove('CalcView', 'qwb_fp_calcView')
    hook.Remove('InputMouseApply', 'qwb_fp_inputMouseApply')
    hook.Remove('RenderScreenspaceEffects', 'qwb_fp_effects')
    hook.Remove('HUDShouldDraw', 'qwb_fp_hideCrosshair')

    fpEnabled = false
    if LocalPlayer().headHided then
        stwFP.hideHead(false)
    end
end

-- Хук для проверки возможности включения первого лица
hook.Add('qwb_fp_canEnableFP', 'qwb_fp_canEnableFP', function()
    local ply = LocalPlayer()
    if not IsValid(ply) then return false end

    local weapon = ply:GetActiveWeapon()
    if not IsValid(weapon) then return false end

    if GetViewEntity() ~= ply then return false end
    if nonFPWeapons[weapon:GetClass()] then return false end

    return true
end)

-- Хук Think для управления состоянием первого лица
hook.Add('Think', 'qwb_fp_think', function()
    local canEnable = hook.Run('qwb_fp_canEnableFP')
    if canEnable and not fpEnabled then
        stwFP.startFP()
    elseif not canEnable and fpEnabled then
        stwFP.stopFP()
    end

    local ply = LocalPlayer()
    if ply and IsValid(ply) and ply:Alive() and IsValid(ply:GetRagdollEntity()) then
        local ragdoll = ply:GetRagdollEntity()
        local bone = ragdoll:LookupBone(headBoneName) or 0
        if ragdoll:GetManipulateBoneScale(bone) ~= Vector(1, 1, 1) then
            ragdoll:ManipulateBoneScale(bone, Vector(1, 1, 1))
        end
    end
end)

-- Таймер для периодической проверки скрытия головы
timer.Create('qwb_fp_checkHead', 3.5, 0, function()
    local ply = LocalPlayer()
    if not (ply and IsValid(ply)) then return end
    if ply.headHided then
        local bone = ply:LookupBone(headBoneName) or 0
        if ply:GetManipulateBoneScale(bone) ~= Vector(0.01, 0.01, 0.01) then
            stwFP.hideHead(true)
        end
    end
end)
```
```
-- cl_init.lua
local firstPersonMode = CreateClientConVar('qwb_firstperson', 0, true, false, 'FirstPerson Mode (from the hip)', 0, 2)
local firstPersonZNear = CreateClientConVar('qwb_firstperson_znear', 1.75, true, false, 'FirstPerson ZNear', 1, 5)

net.Receive('qwb.setIronsight', function()
	local b = net.ReadBool()

	qwb.ironsighted = b
end)

local angle_zero = Angle()
local firstPersonOffset1 = Vector()
local firstPersonOffset2 = Vector(-2, 0, 5)

local headDefaultScale = Vector(1, 1, 1)
local headScale = Vector(0.01, 0.01, 0.01)

local function hideHead(ply, boneID)
	if not IsValid(ply) then return false end

	boneID = boneID or ply:LookupBone('ValveBiped.Bip01_Head1')
	if not boneID then return end

	local curHeadScale = ply:GetManipulateBoneScale(boneID)
	if curHeadScale ~= headScale then
		ply:ManipulateBoneScale(boneID, headScale)
	end
end

local function showHead(ply, boneID)
	if not IsValid(ply) then return false end

	boneID = boneID or ply:LookupBone('ValveBiped.Bip01_Head1')
	if not boneID then return end

	local curHeadScale = ply:GetManipulateBoneScale(boneID)
	if curHeadScale ~= headDefaultScale then
		ply:ManipulateBoneScale(boneID, headDefaultScale)
	end
end

local function shouldChangeCalcView(ply)
	if not IsValid(ply) then return false end
	if GetViewEntity() ~= LocalPlayer() then return false end
	if not ply:Alive() then return false end

	local weap = ply:GetActiveWeapon()
	if not IsValid(weap) or not weap.IsQWB then return false end

	return true
end

local firstPersonModes = {
	[0] = function(ply, origin, angles)
		local att = ply:GetAttachment( ply:LookupAttachment('eyes') )
		if not att then return end

		local pos, ang = LocalToWorld(firstPersonOffset1, angle_zero, att.Pos, att.Ang)
		return pos, ang
	end,

	[1] = function(ply, origin, angles)
		local att = ply:GetAttachment( ply:LookupAttachment('anim_attachment_head') )
		if not att then return end

		local pos, ang = LocalToWorld(firstPersonOffset2, angle_zero, att.Pos, angles)
		return pos, ang
	end,
}

local function getSightPos(ply)
	local weap = ply:GetActiveWeapon()
	local att = ply:GetAttachment( ply:LookupAttachment('anim_attachment_rh') )
	if not att then return end

	local offset = weap.IronsightOffset
	local angOffset = weap.IronsightAngle

	if weap.Attachments and weap._attachments and weap._attachments.sights then
		local id = weap._attachments.sights.id
		local data = weap.Attachments.sights[id]
		if data then
			local camOffset = data.sightCameraOffset
			if camOffset then
				offset = offset + camOffset
			end

			local camAngOffset = data.sightCameraAngleOffset
			if camAngOffset then
				angOffset = angOffset + camAngOffset
			end
		end
	end

	return LocalToWorld(offset, angOffset or angle_zero, att.Pos, att.Ang)
end

local function nonSightCalcView(ply, origin, angles, fov, znear, zfar)
	if not shouldChangeCalcView(ply) then
		qwb.ironsightLerpProgress = nil
		return
	end

	qwb.ironsightLerpProgress = qwb.ironsightLerpProgress or 0
	qwb.ironsightLerpProgress = math.Clamp(qwb.ironsightLerpProgress - (FrameTime() * 4), 0, 1)

	local mode = firstPersonMode:GetInt()

	local getPosFunc = firstPersonModes[mode]
	if not getPosFunc then return end

	local pos, ang = getPosFunc(ply, origin, angles)
	if not pos then return end

	local sightPos = getSightPos(ply) or origin
	pos = LerpVector(qwb.ironsightLerpProgress, pos, sightPos)

	return {
		origin = pos,
		angles = ang,
		fov = fov,
		drawviewer = true,
		znear = firstPersonZNear:GetFloat() or 1.75,
	}
end

timer.Create('qwb.headCheck', 0.5, 0, function()
	if not shouldChangeCalcView(LocalPlayer()) or (firstPersonMode:GetInt() ~= 1 and not qwb.ironsighted) then
		showHead(LocalPlayer())
	elseif shouldChangeCalcView(LocalPlayer()) and (firstPersonMode:GetInt() == 1 or qwb.ironsighted) then
		hideHead(LocalPlayer())
	end
end)

hook.Add('InputMouseApply', 'qwb.firstPerson', function(cmd, x, y, ang)
	local mode = firstPersonMode:GetInt()
	if mode ~= 1 then return end

	if not shouldChangeCalcView(LocalPlayer()) then return end

	ang.p = math.Clamp(ang.p + y / 50, -65, 65)
	ang.y = ang.y - x / 50
	cmd:SetViewAngles(ang)

	return true
end)

hook.Add('CalcView', 'qwb.ironsight', function(ply, origin, angles, fov, znear, zfar)
	if not qwb.ironsighted then return nonSightCalcView(ply, origin, angles, fov, znear, zfar) end

	if not shouldChangeCalcView(ply) or qwb.isPlayerRunning(ply) then
		qwb.ironsighted = nil
		qwb.ironsightLerpProgress = nil
		return
	end

	local pos, ang = getSightPos(ply)

	qwb.ironsightLerpProgress = qwb.ironsightLerpProgress or 0
	qwb.ironsightLerpProgress = math.Clamp(qwb.ironsightLerpProgress + (FrameTime() * 3), 0, 1)

	local mode = firstPersonMode:GetInt()
	local getFunc = firstPersonModes[mode]
	local nonSightPos = getFunc and getFunc(ply, origin, angles) or origin

	pos = LerpVector(qwb.ironsightLerpProgress, nonSightPos, pos)

	local weap = ply:GetActiveWeapon()

	local view = {
		origin = pos,
		angles = ang,
		fov = fov,
		znear = weap.IronsightZNear or 2.35,
		drawviewer = true,
	}

	return view
end)

-- Thanks to octothorp team for this solution, which fixes camera shake
hook.Add('RenderScene', '_qwb', function(pos, angle, fov)
	local camData = hook.Run('CalcView', LocalPlayer(), pos, angle, fov)
	if not camData then return end

	render.Clear(0, 0, 0, 255, true, true, true)
	render.RenderView({
		angles = camData.angles,
		origin = camData.origin,
		drawhud = true,
		drawmonitors = true,
		dopostprocess = true,
	})

	return true
end)

function qwb.fullyClearStencil()
	render.SetStencilWriteMask( 0xFF )
	render.SetStencilTestMask( 0xFF )
	render.SetStencilReferenceValue( 0 )
	render.SetStencilCompareFunction( STENCIL_ALWAYS )
	render.SetStencilPassOperation( STENCIL_KEEP )
	render.SetStencilFailOperation( STENCIL_KEEP )
	render.SetStencilZFailOperation( STENCIL_KEEP )
	render.ClearStencil()
end
```
```
-- sv_init.lua
util.AddNetworkString('qwb.setIronsight')
util.AddNetworkString('qwb.setAttachment')
util.AddNetworkString('qwb.removeAttachment')
util.AddNetworkString('qwb.muzzleFlashLight')

local realisticDamage = CreateConVar('qwb_realisticdamage', 1, FCVAR_NOTIFY, '', 0, 1)

local hitgroups = {
    [HITGROUP_HEAD] = 10000,
    [HITGROUP_STOMACH] = 1.5,
    [HITGROUP_LEFTARM] = 0.2,
    [HITGROUP_RIGHTARM] = 0.2,
    [HITGROUP_LEFTLEG] = 0.3,
    [HITGROUP_RIGHTLEG] = 0.3,
}

hook.Add('ScalePlayerDamage', 'qwb.damage', function( ply, hitgroup, dmginfo )
    if not realisticDamage:GetBool() then return end

    local attacker = dmginfo:GetAttacker()
    if not IsValid(attacker) or not IsValid(attacker:GetActiveWeapon()) then return end

    local weap = attacker:GetActiveWeapon()
    if not weap.IsQWB then return end

    local scale = hitgroups[hitgroup]
    if scale then dmginfo:ScaleDamage(scale) end
end)
```