------------------------------------------------------------------------OTHER PART
SuR.Data = {}
SuR.Data["Wave"] = 0
SuR.Data["WaveState"] = false
SuR.Data["Enemies"] = 0
SuR.Data["DrawHUD"] = true
SuR.Data["DeployTime"] = 0
SuR.Data["Deploying"] = false
SuR.Data["Mutator"] = 0
SuR.Data["Fuel"] = 0
SuR.Data["MaxFuel"] = 0
SuR.Data["DisableMusic"] = false

local lang = SuR.Language
local hide = {
	["CHudHealth"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true,
	["CHudBattery"] = true,
	["CHudCrosshair"] = true,
	["CHudDamageIndicator"] = true,
	["CHudWeaponSelection"] = true,
}

hook.Add("HUDShouldDraw", "HideHUD", function( name )
	if hide[name] then
		return false
	end
end)

hook.Add("DrawDeathNotice", "DisableKillfeed", function()
	return 0,0
end)

net.Receive("SuR.SendDataToClient", function()
	local str = net.ReadString()
	local value = net.ReadTable()[1]
	SuR.Data[str] = value
end)

net.Receive("SuR.MessageOnClient", function()
	local fl = net.ReadFloat()
	local value = net.ReadTable()[1]
	message = ""
	message2 = ""
	if fl == 1 then
		message = lang["message_main1"]
		message2 = lang["message_main2"]
		surface.PlaySound("surrounded/tick.wav")
	elseif fl == 2 then
		message = string.format(lang["message_wavestart1"], SuR.Data["Wave"])
		message2 = lang["message_wavestart2"]
	elseif fl == 3 then
		message = string.format(lang["message_waveend1"], SuR.Data["Wave"])
		message2 = lang["message_waveend2"]
	elseif fl == 4 then
		message = value:Nick()..lang["message_thelp1"]
		message2 = lang["message_thelp2"]
		surface.PlaySound("surrounded/sfx/player_downed.mp3")
	elseif fl == 5 then
		message = lang["message_tdied1"]
		message2 = value:Nick()..lang["message_tdied2"]
		surface.PlaySound("trials/player_death_02.wav")
	elseif fl == 6 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_support"]
	elseif fl == 7 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_mortar"]
	elseif fl == 8 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_away"]
	elseif fl == 9 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_supply"]
	elseif fl == 10 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_heli"]
	elseif fl == 11 then
		message = lang["message_warn"]

		local data = 2
		if SuR.Data["Wave"] >= 14 then
			data = 5
		elseif SuR.Data["Wave"] >= 9 then
			data = 4
		elseif SuR.Data["Wave"] >= 5 then
			data = 3
		end
		message2 = string.format(lang["message_zombie_phase"], data)
	elseif fl == 12 then
		message = lang["message_warn"]
		message2 = lang["mutator_appear"]
	elseif fl == 13 then
		message = lang["message_radio_accept"]
		message2 = lang["message_radio_exfil"]
	elseif fl == 14 then
		message = lang["message_warn"]
		message2 = lang["zombie_choose"]
	elseif fl == 14 then
		message = lang["message_warn"]
		message2 = lang["zombie_choose"]
	elseif fl == 15 then
		message = lang["message_info"]
		message2 = value..lang["message_radio_found"]
	elseif fl == 16 then
		message = lang["message_info"]
		message2 = lang["message_healed"]..value
	elseif fl == 17 then
		message = lang["message_info"]
		message2 = lang["message_healing"]..value
	elseif fl == 18 then
		message = lang["message_info"]
		message2 = value..lang["message_open_box"]
	elseif fl == 19 then
		message = lang["message_info"]
		message2 = value..lang["message_fuel"]
	elseif fl == 20 then
		message = lang["message_info"]
		message2 = lang["message_obj_done"]
	end
	GiveMessageOnScreen(message, message2)
end)

------------------------------------------------------------------------VOICE PART
local icon_voiceMat = Material('surrounded/voice.png')
local havevoices = 0

local function CreateVoicePanel(ply, bool)
	if bool then
		havevoices = havevoices + 1
		local max = 0+(havevoices*He(36))
		local nick = ""
		if IsValid(ply) then
			nick = ply:Nick()
		end
		hook.Add("HUDPaint", "ImageOnVoice"..ply:EntIndex(), function()
			surface.SetMaterial(icon_voiceMat)
			surface.SetDrawColor(255,255,255)
			surface.DrawTexturedRect(We(10), He(320)-He(24)+max, We(48), He(48))
			draw.SimpleText(nick, "SuR_SmallFont1", We(64), He(320)+max, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
		end)
	else
		havevoices = havevoices - 1
		hook.Remove("HUDPaint", "ImageOnVoice"..ply:EntIndex())
	end
end

hook.Add("PlayerStartVoice", "ImageOnVoice", function(ply)
	CreateVoicePanel(ply, true)
	return false
end)

hook.Add("PlayerEndVoice", "ImageOnVoice", function(ply)
	CreateVoicePanel(ply, false)
end)

------------------------------------------------------------------------HUD PART

local function create_fonts()
	surface.CreateFont("SuR_PixelFont",{
		font = "sur_font1",
		extended = true,
		size = He(10),
		antialias = true,
	})

	surface.CreateFont("SuR_SmallFont1",{
		font = "sur_font1",
		extended = true,
		size = He(16),
		antialias = true,
	})
	
	surface.CreateFont("SuR_SmallFont2",{
		font = "sur_font1",
		extended = true,
		size = He(24),
		antialias = true,
	})
	
	surface.CreateFont("SuR_MediumFont1",{
		font = "sur_font1",
		extended = true,
		size = He(32),
		antialias = true,
	})
	
	surface.CreateFont("SuR_MediumFont2",{
		font = "sur_font1",
		extended = true,
		size = He(48),
		antialias = true,
	})

	surface.CreateFont("SuR_LargeFont1",{
		font = "sur_font1",
		extended = true,
		size = He(64),
		antialias = true,
	})
end
create_fonts()
hook.Add("OnScreenSizeChanged", "ChangeFonts", create_fonts)

local aMat = Material('surrounded/ammo_bg.png')
local vMat = Material('surrounded/wave_bg.png')
local gMat = Material('surrounded/gradient.png')
local cMat = Material('surrounded/crosshair.png')
local killMat = Material('surrounded/kill.png')
local icon_kickMat = Material('surrounded/kick.png')
local icon_vaultMat = Material('surrounded/vault.png')
local icon_ammoMat = Material('surrounded/ammo.png')
local icon_healMat = Material('surrounded/heal.png')
local icon_grenadeMat = Material('surrounded/grenade.png')
local icon_sprayMat = Material('surrounded/spray.png')
local icon_radioMat = Material('surrounded/radio_ab.png')
local icon_srkMat = Material('surrounded/srk.png')
local icon_spaceMat = Material('surrounded/space.png')
local icon_mutatorMat = Material('surrounded/mutator.png')
local vinMat = Material('surrounded/vin.png')

function GiveMessageOnScreen(m1, m2)
	local long = 600
	local longstate = true
	timer.Simple(8, function()
		longstate = false
	end)
	hook.Add("HUDPaint", "MainHUDMessage1", function()
		local ply = LocalPlayer()

		surface.SetMaterial(vMat)
		surface.SetDrawColor(255,255,255,250)
		surface.DrawTexturedRectRotated(ScrW()-We(300)+long, He(130), We(600), He(120), 180)
		draw.SimpleText(m1, "SuR_SmallFont2", ScrW()-We(260)+long, He(110), Color(200,200,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
		draw.SimpleText(m2, "SuR_SmallFont1", ScrW()-We(260)+long, He(135), Color(200,20,20), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)

		if not longstate then
			long = math.min(long+FrameTime()/0.001, 600)
			if long == 600 then
				hook.Remove("HUDPaint", "MainHUDMessage1")
			end
		else
			long = math.max(long-FrameTime()/0.001, 0)
		end
	end)
end

local function ShowGameOverScreen()
    local alpha = 0
    local morealpha = true
    local wave = net.ReadFloat()
	local success = net.ReadBool()
    local ply = LocalPlayer()
	local maintext = ""
	SuR.Data["DrawHUD"] = false
	if success then
		SuR:PlayMusicOther(table.Random(SuR.Config.MusicWave["ExfilOver"]))
		maintext = SuR.Language["game_over_success"]
	else
		SuR:PlayMusicOther(table.Random(SuR.Config.MusicWave["GameOver"]))
		maintext = SuR.Language["game_over_main"]
	end
    ply:ScreenFade(SCREENFADE.OUT, color_black, 1, 1)
    timer.Simple(2, function()
        ply:ScreenFade(SCREENFADE.IN, color_black, 1, 0)
        hook.Add("HUDPaint", "Surrounded_TheEnd", function()
            draw.SimpleText(maintext, "SuR_LargeFont1", ScrW()/2, ScrH()/2-He(300), Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			if not SuR.Config.Objective_Mode then
            	draw.SimpleText(string.format(SuR.Language["game_over_wave"], wave), "SuR_MediumFont1", ScrW()/2, ScrH()/2-He(180), Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			end
            if morealpha then
                alpha = math.Clamp(alpha+FrameTime()/0.01, 0, 255)
            else
                alpha = math.Clamp(alpha-FrameTime()/0.01, 0, 255)
            end
        end)
        hook.Add("CalcView", "Surrounded_TheEnd",function(ply, pos, angles, fov)
            local view = {
                origin = SuR.Config.Camera_Position[1],
                angles = SuR.Config.Camera_Position[2],
                fov = fov,
                drawviewer = false
            }
        
            return view
        end)

        timer.Simple(SuR.Config.Game_Over_Screen_Delay-6, function()
            ply:ScreenFade(SCREENFADE.OUT, color_black, 4, 1)
            morealpha = false
            timer.Simple(4, function()
                ply:ScreenFade(SCREENFADE.IN, color_black, 1, 0)
                hook.Remove("CalcView", "Surrounded_TheEnd")
                hook.Remove("HUDPaint", "Surrounded_TheEnd")
				SuR.Data["DrawHUD"] = true
            end)
        end)
    end)
end
net.Receive("SuR.GameOverScreen", ShowGameOverScreen)

function SuR:StartPhrase()
    local alpha = 0
	local add1, add2, add3 = 0, 0, 0
	local adddelay = 0
    local morealpha = true
	local text = lang["start_message1"]
	if SuR.Config.Objective_Mode then
		text = lang["start_message_fuel"]
	end
	timer.Simple(2, function()
		hook.Add("HUDPaint", "Surrounded_Phrase", function()
			draw.SimpleText(text, "SuR_SmallFont1", ScrW()/2+We(add1), ScrH()/2+He(200)+He(add2), Color(255,255,255,alpha+add3), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			if adddelay < CurTime() then
				adddelay = CurTime()+0.05
				add1, add2, add3 = math.Rand(-2,2), math.Rand(-2,2), math.Rand(-25,25)
			end
			if morealpha then
				alpha = math.Clamp(alpha+FrameTime()/0.02, -25, 200)
			else
				alpha = math.Clamp(alpha-FrameTime()/0.02, -25, 200)
				if alpha <= -25 then
					hook.Remove("HUDPaint", "Surrounded_Phrase")
				end
			end
		end)
		timer.Simple(15, function()
			morealpha = false
		end)
	end)
end

local screen_kills = 0
local rndnum = 0
local alpha = 255
local function GiveKillsOnScreen()
	local bool = net.ReadBool()
	screen_kills = screen_kills + 1
	alpha = 255

	local alphaminus = false
	local text = ""
	if bool then
		text = lang["killstreak_exec"]
		rndnum = 10
	elseif screen_kills == 2 then
		text = lang["killstreak_1"]
		rndnum = 8
	elseif screen_kills == 3 then
		text = lang["killstreak_2"]
		rndnum = 12
	elseif screen_kills == 4 then
		text = lang["killstreak_3"]
		rndnum = 16
	elseif screen_kills == 5 then
		text = lang["killstreak_4"]
		rndnum = 20
	end
	hook.Add("HUDPaint", "MainHUDKills", function()
		local w, h = ScrW(), ScrH()
		local mat = Matrix()

		rndnum = math.max(rndnum-FrameTime()/0.1, 0)
		if alphaminus then
			alpha = math.max(alpha-FrameTime()/0.001, 0)
		end
	 
		mat:Translate(Vector(w/2+math.random(-rndnum,rndnum), 250+math.random(-rndnum,rndnum)))
		mat:Rotate(Angle(0,math.random(-rndnum,rndnum),0))
		mat:Scale(Vector(1,1,1))
		mat:Translate(-Vector(w/2, h/2))
	 
		cam.PushModelMatrix(mat)
			draw.SimpleTextOutlined(text, "SuR_SmallFont2", w/2, h/2, Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, Color(0, 0, 0, alpha))
		cam.PopModelMatrix()
	end)
	timer.Simple(3.25, function()
		alphaminus = true
	end)
	timer.Create("TimerScreenKills", 4, 1, function()
		screen_kills = 0
		hook.Remove("HUDPaint", "MainHUDKills")
	end)
end
net.Receive("SuR.KillStatus", GiveKillsOnScreen)

local alpha = 255
local countdown_time = 0
local function Countdown(num)
	countdown_time = countdown_time + 1
	local mytime = countdown_time
	for i=0,num-1 do
		timer.Simple(i, function()
			if mytime != countdown_time then return end
			alpha = 255
			surface.PlaySound("surrounded/tick.wav")
			hook.Add("HUDPaint", "MainHUDTimer", function()
				alpha = math.max(alpha-FrameTime()/0.004, 0)
				if alpha == 0 then
					hook.Remove("HUDPaint", "MainHUDTimer")
				end
				draw.SimpleTextOutlined(num-i, "SuR_LargeFont1", ScrW()/2, He(250), Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, Color(0, 0, 0, alpha))
			end)
		end)
	end
end
net.Receive("SuR.Countdown", function()
	local f = net.ReadFloat()
	Countdown(f)
end)

cvars.AddChangeCallback("sur_disable_hud", function(convar_name, value_old, value_new)
	if tonumber(value_new) == 0 then
		SuR.Data["DrawHUD"] = true
	end
end)

local wave_long = 300
local wave_longstate = false
local player_health_alpha = 0
local player_health_alphab = false
local player_infected_alpha = 0
local player_infected_alphab = false
local mut_we = 650
hook.Add("HUDPaint", "MainHUD", function()
	local ply = LocalPlayer()

	if SuR.Data["GameplayBlockNode"] == true then
		surface.SetFont("SuR_SmallFont2")
		local x = surface.GetTextSize(lang["deploy_error_node"])

		surface.SetDrawColor(0,0,0,200)
		surface.DrawRect(ScrW()/2-(x/2+5), He(385), (x+10), He(30))
		draw.SimpleText(lang["deploy_error_node"], "SuR_SmallFont2", ScrW()/2, He(400), Color(200,20,20,255*math.abs(math.cos(CurTime()))), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	end
	if SuR.Data["GameplayBlockConfig"] == true then
		surface.SetFont("SuR_SmallFont2")
		local x = surface.GetTextSize(lang["deploy_error_config"])

		surface.SetDrawColor(0,0,0,200)
		surface.DrawRect(ScrW()/2-(x/2+5), He(415), (x+10), He(30))
		draw.SimpleText(lang["deploy_error_config"], "SuR_SmallFont2", ScrW()/2, He(430), Color(200,20,20,255*math.abs(math.cos(CurTime()))), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	end

	if not SuR.Config.Deploy_Cutscene.cam and SuR.Data["Deploying"] and SuR.Data["DeployTime"]-CurTime() > 0 then
		local dtime = math.floor(SuR.Data["DeployTime"]-CurTime())
		draw.SimpleText(string.format(lang["deploy_time"], dtime), "SuR_MediumFont1", ScrW()/2, ScrH()-He(130), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText(lang["deploy_hint"], "SuR_SmallFont1", ScrW()/2, ScrH()-He(100), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	end

	if GetConVar("sur_disable_hud"):GetBool() then
		SuR.Data["DrawHUD"] = false
	end

	local drawhud = ply:Alive() and !ply:IsDowned() and SuR.Data["DrawHUD"]
	if drawhud then
		local see = ply:GetEyeTrace()

		local bug = ply:GetNWFloat('BuggedPos')
		if bug > 0.3 then
			draw.SimpleText(lang["unreachable"], "SuR_SmallFont1", ScrW()/2, 200, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		end

		local tr = see.Entity
		if !ply:IsLockedAbilities() and IsValid(tr) and string.match(tr:GetClass(), "vj") and tr:GetPos():DistToSqr(ply:GetPos()) < 10000 and tr:GetNWBool('flinching', false) and tr:Health() <= 200 then
			local pos = (tr:EyePos()):ToScreen()
			if tr:LookupAttachment("eyes") > 0 then
				pos = (tr:GetAttachment(tr:LookupAttachment("eyes")).Pos):ToScreen()
			end

			surface.SetMaterial(killMat)
			surface.SetDrawColor(255,255,255,240)
			surface.DrawTexturedRect(pos.x-48,pos.y-160,96,96)
		end

		if !ply:IsLockedAbilities() and ply:IsSurvivor() then	
			local tr2 = util.TraceLine({
				start = ply:EyePos(),
				endpos = ply:EyePos() + ply:GetAimVector() * 72,
				filter = ply,
			})
			if IsValid(tr2.Entity) and tr2.Entity:IsPlayer() and not tr2.Entity:IsDowned() and tr2.Entity:GetNWBool("IsInfected") and ply:GetNWFloat('Sprays') > 0 then
				draw.SimpleText(lang["heal_spray"], "SuR_SmallFont2", ScrW()/2, ScrH()-He(300), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			elseif IsValid(tr2.Entity) and tr2.Entity:IsPlayer() and not tr2.Entity:IsDowned() and tr2.Entity:Health() < 100 and ply:GetNWFloat("Bandages") > 0 then
				draw.SimpleText(lang["heal_bandages"], "SuR_SmallFont2", ScrW()/2, ScrH()-He(300), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			end
		end
				
		local h = ply:GetInfection()
		if h > 0 then
			surface.SetMaterial(vinMat)
			surface.SetDrawColor(70,0,125,player_infected_alpha)
			surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
			
			surface.SetDrawColor(0,0,0,(h+1-1)*250)
			surface.DrawRect(0, 0, ScrW(), ScrH())

			if player_infected_alpha <= 0 then
				player_infected_alphab = true
			elseif player_infected_alpha >= (h+1-1)*125 then
				player_infected_alphab = false
			end

			if player_infected_alphab then
				player_infected_alpha = player_infected_alpha+FrameTime()/0.05
			else
				player_infected_alpha = player_infected_alpha-FrameTime()/0.05
			end
		end

		local h = ply:Health()
		if h < 80 then
			surface.SetMaterial(vinMat)
			surface.SetDrawColor(75,0,0,player_health_alpha)
			surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
			
			if player_health_alpha <= 0 then
				player_health_alphab = true
			elseif player_health_alpha >= (80-h)*1.5 then
				player_health_alphab = false
			end

			if player_health_alphab then
				player_health_alpha = player_health_alpha+(FrameTime()/(ply:Health()/ply:GetMaxHealth()))/0.1
			else
				player_health_alpha = player_health_alpha-(FrameTime()/(ply:Health()/ply:GetMaxHealth()))/0.1
			end
		end

		------------------------------

		local ent1 = see.Entity
		if IsValid(ent1) and see.HitPos:Distance(ply:EyePos()) < 96 then
			local loot = ent1:GetNWString("LootName", "")
			local name = SuR.Language[loot]
			if not name then
				name = loot
			end
			if name != '' then
				draw.SimpleText(lang["main_pickup"]..name, "SuR_SmallFont2", ScrW()/2, ScrH()-He(150), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			end
		end

		------------------------------

		surface.SetMaterial(gMat)
		surface.SetDrawColor(255,255,255,150)
		surface.DrawTexturedRect(We(15), ScrH()-He(130), We(240), He(60))
		draw.SimpleText("+ "..ply:Health(), "SuR_MediumFont2", We(25), ScrH()-He(75), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)

		------------------------------

		surface.SetMaterial(gMat)
		surface.SetDrawColor(255,255,255,150)
		surface.DrawTexturedRect(We(15), He(35), We(300), He(80))

		local icon = SuR.Config.ClassIcons[ply:GetPlayerClass()]
		surface.SetMaterial(icon)
		surface.SetDrawColor(255,255,255)
		surface.DrawTexturedRect(We(20), He(39), We(72), He(72))

		draw.SimpleText(lang["class_"..ply:GetPlayerClass()], "SuR_SmallFont2", We(100), We(70), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
		draw.SimpleText(lang["class_lvl_"..ply:GetLevel()], "SuR_SmallFont1", We(100), He(85), Color(200,200,200), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
		
		surface.SetDrawColor(120,120,120,50)
		surface.DrawRect(We(100), He(95), We(120), He(3))

		local mult = ((ply:GetXPToLevel()/ply:GetXPToLevel(true))*-1+1)
		if ply:GetLevel() == 21 then
			mult = 1
		end
		surface.SetDrawColor(240,240,120,150)
		surface.DrawRect(We(100), He(95), We(120)*mult, He(3))

		------------------------------

		local mut = SuR.Data["Mutator"]
		if mut > 0 then
			mut_we = math.max(mut_we-FrameTime()/0.005, 0)
		else
			mut_we = math.min(mut_we+FrameTime()/0.005, 650)
		end

		surface.SetMaterial(aMat)
		surface.SetDrawColor(Color(0,0,0,200))
		surface.DrawTexturedRect(We(15-mut_we), ScrH()-He(275), We(560), He(130))

		surface.SetMaterial(icon_mutatorMat)
		surface.SetDrawColor(255,255,255)
		surface.DrawTexturedRect(We(60-mut_we), ScrH()-He(260), We(60), He(60))

		draw.SimpleText(lang["mutator_main"], "SuR_SmallFont1", We(145-mut_we), ScrH()-He(250), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
		if mut > 0 then
			draw.SimpleText(lang["mutator_"..mut], "SuR_SmallFont2", We(145-mut_we), ScrH()-He(230), Color(200,200,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			draw.SimpleText(lang["mutator_"..mut.."_desc"], "SuR_SmallFont1", We(80-mut_we), ScrH()-He(190), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
		end
		
		------------------------------

		local tr = (see.HitPos):ToScreen()
		local wep = ply:GetActiveWeapon()
		local drawcrosshair = IsValid(wep) and !ply:IsDowned() and !ply:GetNWBool('SVAnimStopCutscene') and ply:ShouldDrawLocalPlayer()

		if drawcrosshair then
			surface.SetMaterial(cMat)
			surface.SetDrawColor(255,255,255)
			surface.DrawTexturedRect(tr.x-16, tr.y-16, We(32), He(32))
		end

		------------------------------

		local drawweapon = IsValid(wep) and wep:GetPrintName()
		if drawweapon and ply:IsSurvivor() then
			local tier = 0
			local clip = wep:Clip1()
			local maxclip = wep:GetMaxClip1()
			local ammo = ply:GetAmmoCount(wep:GetPrimaryAmmoType())
			local color = color_white
			local color2 = color_white
			if clip == -1 then
				clip = 0
			end
			if clip == 0 then
				color = Color(200,20,20)
			end
			if ammo == 0 then
				color2 = Color(200,20,20)
			elseif ammo <= maxclip then
				color2 = Color(200,150,20)
			end
			if maxclip > 0 then
				surface.SetMaterial(aMat)
				surface.SetDrawColor(Color(255,255,255,240))
				surface.DrawTexturedRect(ScrW()-We(550), ScrH()-He(250), We(400), He(220))

				draw.SimpleText(clip, "SuR_MediumFont2", ScrW()-We(430), ScrH()-He(130), color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP)
				draw.SimpleText("/", "SuR_MediumFont2", ScrW()-We(420), ScrH()-He(120), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText(maxclip, "SuR_MediumFont2", ScrW()-We(410), ScrH()-He(110), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

				surface.SetMaterial(icon_ammoMat)
				surface.SetDrawColor(Color(255,255,255,240))
				surface.DrawTexturedRect(ScrW()-We(275), ScrH()-He(160), We(48), He(48))
				draw.SimpleText(ammo, "SuR_SmallFont2", ScrW()-We(250), ScrH()-He(100), color2, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(aMat)
				surface.SetDrawColor(Color(255,255,255,240))
				surface.DrawTexturedRect(ScrW()-We(550), ScrH()-He(240), We(400), He(110))
			end
			draw.SimpleText(wep:GetPrintName(), "SuR_SmallFont2", ScrW()-We(500), ScrH()-He(205), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

			local t = SuR.Config.TierWeapons
			local cl = wep:GetClass()
			if table.HasValue(t["Tier1"], cl) then
				tier = 1
			elseif table.HasValue(t["Tier2"], cl) or table.HasValue(t["Melee"], cl) then
				tier = 2
			elseif table.HasValue(t["Tier3"], cl) or table.HasValue(t["Other"], cl) then
				tier = 3
			elseif table.HasValue(t["Tier4"], cl) then
				tier = 4
			elseif table.HasValue(t["Tier5"], cl) then
				tier = 5
			end
			if wep:GetNWFloat('Tier') > 0 then
				tier = wep:GetNWFloat('Tier')
			end
			if tier > 0 then
				draw.SimpleText(lang["loot_tier"..tier], "SuR_SmallFont1", ScrW()-We(500), ScrH()-He(180), SuR.Config.Tier_Colors[tier], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			end
		end

		------------------------------

		if ply:IsSurvivor() then
			surface.SetMaterial(gMat)
			surface.SetDrawColor(255,255,255,150)
			surface.DrawTexturedRect(We(15), He(230), We(150), He(50))
			draw.SimpleText("$ "..ply:GetNWInt('Money'), "SuR_SmallFont2", We(25), He(240), SuR.Config.Tier_Colors[tier], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

			if string.match(ply:GetSVAnim(), "grappleloop") or ply:IsStunned(true) then
				surface.SetMaterial(icon_spaceMat)
				if input.IsKeyDown(KEY_SPACE) then
					surface.SetDrawColor(100,255,100)
				else
					surface.SetDrawColor(255,255,255)
				end
				if ply:IsStunned(true) then
					surface.DrawTexturedRectRotated(ScrW()/2, ScrH()-He(150), We(350), He(350), 8*math.sin(CurTime()*4))
				else
					surface.DrawTexturedRectRotated(ScrW()/2+math.Rand(-5,5), ScrH()-He(150)+math.Rand(-5,5), We(350), He(350), 10*math.sin(CurTime()*4))
				end
			end

			if ply:GetNWFloat('SelfRevive') > 0 then
				surface.SetMaterial(icon_srkMat)
				surface.SetDrawColor(255,255,255,150)
				surface.DrawTexturedRect(We(10), ScrH()-He(75), We(80), He(75))
				draw.SimpleText(ply:GetNWFloat('SelfRevive'), "SuR_SmallFont2", We(85), ScrH()-He(10), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
			else
				surface.SetMaterial(icon_srkMat)
				surface.SetDrawColor(0,0,0,100)
				surface.DrawTexturedRect(We(10), ScrH()-He(75), We(80), He(75))
				draw.SimpleText(ply:GetNWFloat('SelfRevive'), "SuR_SmallFont2", We(85), ScrH()-He(10), Color(0,0,0,100), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
			end
			
			if ply:GetNWFloat('CanCallSupport') > 0 and !ply:IsLockedAbilities() then
				surface.SetMaterial(icon_radioMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(800), We(100), He(100))

				draw.SimpleText("M", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(700), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat('CanCallSupport'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(685), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(icon_radioMat)
				surface.SetDrawColor(100,0,0,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(800), We(100), He(100))

				draw.SimpleText("M", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(700), Color(100,0,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat('CanCallSupport'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(685), Color(100,0,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			end

			if ply:GetInfection() > 0 and ply:GetNWFloat('Sprays') > 0 and !ply:IsLockedAbilities() then
				surface.SetMaterial(icon_sprayMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(650), We(100), He(100))

				draw.SimpleText("H", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(550), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat('Sprays'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(535), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(icon_sprayMat)
				surface.SetDrawColor(100,0,0,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(650), We(100), He(100))

				draw.SimpleText("H", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(550), Color(100,0,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat('Sprays'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(535), Color(100,0,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			end

			if ply:GetNWBool('CanHeal') and !ply:IsLockedAbilities() and ply:GetNWFloat("Bandages") > 0 then
				surface.SetMaterial(icon_healMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(500), We(100), He(100))

				draw.SimpleText("B", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(400), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat("Bandages"), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(385), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(icon_healMat)
				surface.SetDrawColor(100,0,0,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(500), We(100), He(100))

				draw.SimpleText("B", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(400), Color(100,0,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWFloat("Bandages"), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(385), Color(100,0,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			end

			if ply:GetNWInt('Grenades') > 0 and !ply:IsLockedAbilities() then
				surface.SetMaterial(icon_grenadeMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(350), We(100), He(100))

				draw.SimpleText("L", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(250), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWInt('Grenades'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(235), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(icon_grenadeMat)
				surface.SetDrawColor(100,0,0,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(350), We(100), He(100))

				draw.SimpleText("L", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(250), Color(100,0,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
				draw.SimpleText("x"..ply:GetNWInt('Grenades'), "SuR_SmallFont1", ScrW()-We(60), ScrH()-He(235), Color(100,0,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
			end

			if ply:GetNWBool('CanVault') and !ply:IsLockedAbilities() then
				surface.SetMaterial(icon_vaultMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(250), ScrH()-He(350), We(100), He(100))

				draw.SimpleText("V", "SuR_MediumFont1", ScrW()-We(200), ScrH()-He(250), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			end

			if !ply:IsLockedAbilities() then
				surface.SetMaterial(icon_kickMat)
				surface.SetDrawColor(255,255,255,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(200), We(100), He(100))

				draw.SimpleText("G", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(100), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			else
				surface.SetMaterial(icon_kickMat)
				surface.SetDrawColor(100,0,0,240)
				surface.DrawTexturedRect(ScrW()-We(125), ScrH()-He(200), We(100), He(100))

				draw.SimpleText("G", "SuR_MediumFont1", ScrW()-We(75), ScrH()-He(100), Color(100,0,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			end

			local tr = util.TraceLine({
				start = ply:EyePos(),
				endpos = ply:EyePos() + ply:GetAimVector() * 50,
				filter = ply,
				mask = MASK_SHOT_HULL
			})

			local ent = tr.Entity
			if IsValid(ent) and ent:IsPlayer() and ent:IsDowned() and !ply:IsDowned() and ply:Alive() and ply:GetVelocity():Length() < 10 then
				draw.SimpleText(lang["revive_help"], "SuR_MediumFont1", ScrW()/2, ScrH()-He(150), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			end
		else
			surface.SetMaterial(vinMat)
			surface.SetDrawColor(70,0,125,100)
			surface.DrawTexturedRect(0, 0, ScrW(), ScrH())

			draw.SimpleText(lang["zombie_attack1"], "SuR_MediumFont1", ScrW()-We(100), ScrH()-He(140), color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP)
			draw.SimpleText(lang["zombie_attack2"], "SuR_MediumFont1", ScrW()-We(100), ScrH()-He(110), color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP)
		end
	elseif not drawhud and ply:IsZombie() then
		if !ply:Alive() and SuR.Data["WaveState"] then
			draw.SimpleText(lang["zombie_spawn"], "SuR_MediumFont1", ScrW()/2, ScrH()-He(200), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			draw.SimpleText(lang["zombie_menu"], "SuR_SmallFont2", ScrW()/2, ScrH()-He(230), Color(225,200,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
		elseif !ply:Alive() and not SuR.Data["WaveState"] then
			draw.SimpleText(lang["zombie_wait"], "SuR_MediumFont1", ScrW()/2, ScrH()-He(200), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
			draw.SimpleText(lang["zombie_menu"], "SuR_SmallFont2", ScrW()/2, ScrH()-He(230), Color(225,200,0), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
		end
	end
	
	draw.SimpleText("SURROUNDED - v"..SuR.Version.." ["..SuR.Build.."]", "SuR_SmallFont1", 5, 5, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
	draw.SimpleText(lang["hud_discord_join"], "SuR_PixelFont", 5, He(22), Color(225, 200, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

	surface.SetMaterial(vMat)
	surface.SetDrawColor(255,255,255,250)
	surface.DrawTexturedRect(0-wave_long, He(130), We(230), He(70))
	if SuR.Data["ExfilWave"] then
		draw.SimpleText(lang["evac"], "SuR_MediumFont1", We(15)-wave_long, He(145), Color(200,200*math.cos(CurTime()*3),200*math.cos(CurTime()*3)), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
	elseif SuR.Config.Objective_Mode then
		local fuel, maxfuel = SuR.Data["Fuel"], SuR.Data["MaxFuel"]
		draw.SimpleText(lang["fuel"], "SuR_SmallFont1", We(110)-wave_long, He(145), Color(200,200,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
		draw.SimpleText(fuel.."/"..maxfuel, "SuR_MediumFont1", We(110)-wave_long, He(160), Color(200,200,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
	else
		draw.SimpleText(lang["main_wave"]..SuR.Data["Wave"], "SuR_MediumFont1", We(15)-wave_long, He(140), Color(200,200,200), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
		if wave_longstate then
			draw.SimpleText(lang["main_count"]..SuR.Data["Enemies"], "SuR_SmallFont1", We(15)-wave_long, He(175), Color(100,20,20), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
		end
	end

	wave_longstate = SuR.Data["WaveState"]
	if not wave_longstate then
		wave_long = math.min(wave_long+FrameTime()/0.005, 300)
	else
		wave_long = math.max(wave_long-FrameTime()/0.005, 0)
	end

	local tab = player.GetAll()
	for i=1,#tab do
		local ent = tab[i]
		if ent:Team() != ply:Team() then continue end
		if ent != ply and ent:Alive() and ent:IsLineOfSightClear(ply) then
			local pos = (ent:GetBonePosition(ent:LookupBone("ValveBiped.Bip01_Head1"))+Vector(0,0,20)):ToScreen()
			if string.match(ent:GetSVAnim(), "executions") or string.match(ent:GetSVAnim(), "killmove") or string.match(ent:GetSVAnim(), "grappleloop") then
				draw.SimpleText(ent:Nick(), "SuR_SmallFont1", pos.x, pos.y-He(16), Color(200,120,20), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
				draw.SimpleText("[HELP]", "SuR_SmallFont1", pos.x, pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			elseif ent:IsDowned() then
				draw.SimpleText(ent:Nick(), "SuR_SmallFont1", pos.x, pos.y-He(16), Color(200,20,20), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
				draw.SimpleText("[+]", "SuR_SmallFont1", pos.x, pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			else
				local alpha = 255/(ent:EyePos():Distance(EyePos())/500)
				if alpha > 200 then
					draw.SimpleText(ent:Nick(), "SuR_SmallFont1", pos.x, pos.y, Color(255,255,255,alpha), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
					local icon = SuR.Config.ClassIcons[ent:GetPlayerClass()]
					surface.SetMaterial(icon)
					surface.SetDrawColor(255,255,255,alpha)
					surface.DrawTexturedRect(pos.x-We(40), pos.y-He(16), We(32), He(32))
				else
					draw.SimpleText(ent:Nick(), "SuR_PixelFont", pos.x, pos.y, Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
				end
			end
		end
	end

	if ply:IsDowned() then
		draw.SimpleText(lang["revive_main"], "SuR_MediumFont1", ScrW()/2, ScrH()-He(150), Color(200,20,20), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText(lang["revive_wait"], "SuR_SmallFont2", ScrW()/2, ScrH()-He(110), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

		if ply:GetNWFloat('SelfRevive') > 0 and ply:GetSVAnim() != "sur_selfrevive" then
			draw.SimpleText(lang["revive_self"], "SuR_SmallFont1", ScrW()/2, ScrH()-He(300), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			surface.SetMaterial(icon_srkMat)
			surface.SetDrawColor(255,255,255,150)
			surface.DrawTexturedRect(ScrW()/2-We(35), ScrH()-He(300), We(80), He(75))
			draw.SimpleText(ply:GetNWFloat('SelfRevive'), "SuR_SmallFont2", ScrW()/2+We(35), ScrH()-He(235), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
		end
	end
end)

local addmat_r = Material("surrounded/add_r")
local addmat_g = Material("surrounded/add_g")
local addmat_b = Material("surrounded/add_b")
local vgbm = Material("vgui/black")

function DrawCA(rx, gx, bx, ry, gy, by)
    render.UpdateScreenEffectTexture()

    addmat_r:SetTexture("$basetexture", render.GetScreenEffectTexture())
    addmat_g:SetTexture("$basetexture", render.GetScreenEffectTexture())
    addmat_b:SetTexture("$basetexture", render.GetScreenEffectTexture())

    render.SetMaterial(vgbm)
    render.DrawScreenQuad()

    render.SetMaterial(addmat_r)
    render.DrawScreenQuadEx(-rx / 2, -ry / 2, ScrW() + rx, ScrH() + ry)

    render.SetMaterial(addmat_g)
    render.DrawScreenQuadEx(-gx / 2, -gy / 2, ScrW() + gx, ScrH() + gy)

    render.SetMaterial(addmat_b)
    render.DrawScreenQuadEx(-bx / 2, -by / 2, ScrW() + bx, ScrH() + by)
end

hook.Add("RenderScreenspaceEffects", "MainColorHP", function()
	local ply = LocalPlayer()
	local death = isfunction(hook.GetTable()["CalcView"]["SuR_DeathView"])
	if ply:Alive() or death then
		local tab = {
			["$pp_colour_contrast"] = (ply:Health()/ply:GetMaxHealth())/4+0.75,
			["$pp_colour_colour"] = (ply:Health()/ply:GetMaxHealth()),
		}
		if ply:IsDowned() or death then
			tab = {
				["$pp_colour_contrast"] = 0.75,
				["$pp_colour_colour"] = 0.1,
			}
		end

		DrawColorModify(tab)

		local num = ply:IsDowned() and 25 or ( (1-(ply:Health()/ply:GetMaxHealth()))*10 )
		if ply:Health() < 50 or ply:IsDowned() or death then
			num = num*math.abs(math.sin(CurTime()))+0.1
			if num > 0 then
				DrawCA(4 * num, 2 * num, 0, 2 * num, 1 * num, 0)
			end
		end
	end
end)

------------------------------------------------------------------------WORK PART

hook.Add("InitPostEntity", "MainDeleter", function()
	function GAMEMODE:HUDDrawTargetID() end
	function GAMEMODE:HUDDrawPickupHistory() end
end)

local bindfalse = {
	["-voicerecord"] = true,
	["+voicerecord"] = true,
	["messagemode"] = true,
}

local movebind = {
	["-forward"] = true,
	["+forward"] = true,
	["-moveleft"] = true,
	["+moveleft"] = true,
	["-moveright"] = true,
	["+moveright"] = true,
	["-back"] = true,
	["+back"] = true,
}

hook.Add("PlayerBindPress", "Main_PlayerBindPress", function(ply, bind, pressed)
	local ply = LocalPlayer()
	local cutscene = ply:GetNWBool('SVAnimStopCutscene')
	if (ply:KeyDown(IN_DUCK) or !ply:OnGround()) and bind == "+jump" then return true end
	if (ply:KeyDown(IN_JUMP) or !ply:OnGround()) and bind == "+duck" then return true end
    if cutscene and not bindfalse[bind] then
		return true
    end
	if ply:IsDowned() and not bindfalse[bind] and not movebind[bind] then
		return true
	end
end)
