local meta = FindMetaTable("Player")

net.Receive("SuR.ClientRunString", function()
    local str = net.ReadString()
    RunString(str)
end)

net.Receive("SuR.PlaySoundOnClient", function()
	local str = net.ReadString()
    if string.match(str, "https://") then
        sound.PlayURL(str, "", function(st)
            if IsValid(st) then
                st:Play()
            end
        end)
    else
        surface.PlaySound(str)
    end
end)

function SuR:GetRandomSound(path)
    local fil, dir = file.Find("sound/"..path.."*", "GAME")
    if #fil > 0 then
        local snd = path..fil[math.random(1,#fil)]
        return snd
    else
        return ""
    end
end

function meta:PlayVoiceLine(type, chance)
	if chance and chance < math.random(1,100) then return end

	local snd = ""
	local nodelay = false
	local death = !self:Alive()
    local voice = self:GetNWString("VoicePack")
    local tab = SuR.Config.VoicePacks[voice]
    if istable(tab) then
        if type == "pain" then
            snd = SuR:GetRandomSound(tab["pain"])
            nodelay = true
        elseif type == "death" then
            snd = SuR:GetRandomSound(tab["death"])
            nodelay = true
            death = false
        elseif type == "reload" then
            snd = SuR:GetRandomSound(tab["reload"])
        elseif type == "enemyback" then
            snd = SuR:GetRandomSound(tab["enemyback"])
            nodelay = true
        elseif type == "enemydown" then
            snd = SuR:GetRandomSound(tab["enemydown"])
        elseif type == "pickup" then
            snd = SuR:GetRandomSound(tab["pickup"])
        elseif type == "noammo" then
            snd = SuR:GetRandomSound(tab["noammo"])
        elseif type == "downed" then
            snd = SuR:GetRandomSound(tab["downed"])
            nodelay = true
        elseif type == "friendlyfire" then
            snd = SuR:GetRandomSound(tab["friendlyfire"])
        elseif type == "frienddied" then
            snd = SuR:GetRandomSound(tab["frienddied"])
        elseif type == "lowhp" then
            snd = SuR:GetRandomSound(tab["lowhp"])
        elseif type == "infected" then
            snd = SuR:GetRandomSound(tab["infected"])
            nodelay = true
        elseif type == "enemyspotted" then
            snd = SuR:GetRandomSound(tab["enemyspotted"])
            nodelay = true
        elseif type == "thanks" then
            snd = SuR:GetRandomSound(tab["thanks"])
        elseif type == "cover" then
            snd = SuR:GetRandomSound(tab["cover"])
        end
    end     

    if type == "zombie_death" then
        local str = "vj_lnrhl2/walker_male/die0"..math.random(1,5)..".wav"
        snd = str
        nodelay = true
        death = false
    elseif type == "zombie_idle" then
        local str = "vj_lnrhl2/infected/zomb_runner_male1-idle-0"..math.random(1,9)..".wav"
        snd = str
    elseif type == "zombie_attack" then
        local rnd = math.random(1,22)
        local str = "vj_lnrhl2/walker_male/attack_sham_m_"
        if rnd > 9 then
            str = str..rnd..".wav"
        else
            str = str.."0"..rnd..".wav"
        end
        snd = str
        snd = str
    elseif type == "zombie_pain" then
        local str = "vj_lnrhl2/walker_male/pain0"..math.random(1,5)..".wav"
        snd = str
        nodelay = true
    end

	if death then return end

    if not self.PreviousVoiceLine then
        self.PreviousVoiceLine = 0
    end
    if not self.PreviousVoiceLineString then
        self.PreviousVoiceLineString = ""
    end

	if snd != "" and (self.PreviousVoiceLine < CurTime() or nodelay) then
        snd = ")"..snd
		self.PreviousVoiceLine = CurTime()+4
		self:StopSound(self.PreviousVoiceLineString)
		self.PreviousVoiceLineString = snd
		self:EmitSound(snd)
	end
end

net.Receive("SuR.VoiceLines", function(len, ply)
    local data = net.ReadTable()
    if IsEntity(data[1]) and data[1].PlayVoiceLine then
        data[1]:PlayVoiceLine(data[2], data[3])
    end
end)

local arrowMat = Material('surrounded/arrow.png')
net.Receive("SuR.PointMarker", function()
    local vec = net.ReadVector()
    local str = net.ReadString()
    local delay = CurTime()+120
    hook.Add("HUDPaint", "SuR_PointMarker", function()
        local pos = vec:ToScreen()

        surface.SetMaterial(arrowMat)
        surface.SetDrawColor(255,255,255)
        surface.DrawTexturedRect(pos.x-16,pos.y-16,32,32)

        draw.SimpleText(math.Round(LocalPlayer():GetPos():Distance(vec) * 2/100) .. " m", "SuR_SmallFont1", pos.x+20, pos.y, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        if str != "" then
            draw.SimpleText(str, "SuR_SmallFont1", pos.x, pos.y-20, Color(240,220,0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end

        if delay < CurTime() or !SuR.Data["DrawHUD"] then
            hook.Remove("HUDPaint", "SuR_PointMarker")
        end
    end)
end)

------------------------------------------------------------------------JUMP PART

local jumpDelay = 1
local lastJumpTime = 0

hook.Add("PlayerBindPress", "JumpDelay", function(ply, key)
    if ply:Alive() and key == "+jump" and lastJumpTime < CurTime() then
        lastJumpTime = CurTime()+jumpDelay
        return false
    elseif ply:Alive() and key == "+jump" and ply:OnGround() and lastJumpTime >= CurTime() then
        return true
    end
end)

------------------------------------------------------------------------CAM PART

local currentpos = Vector(0,0,0)
local currentang = Angle(0,0,0)
local changeview = true
local viewbob_speed = 10
local viewbob_amount = 0.01
local viewbob_offset = 0
local last_velocity = 0
local left_side = false
local FPOffsetAngles = Angle(0,0,0)
local fp_offset = {x = 0, y = 0, z = 0}
hook.Add("PlayerButtonDown", "MainCamButtons", function(ply, but)
    if but == KEY_CAPSLOCK and not ply:IsTyping() then
        left_side = !left_side
    end
end)
hook.Add("CalcView", "MainCam", function( ply, pos, angles, fov )
	if ply:Alive() then
        local body = ply
        if IsValid(ply:GetNWEntity("CameraEnt")) then
            body = ply:GetNWEntity("CameraEnt")
        end
        local curmask = MASK_SHOT_HULL
		local plyang = ply:EyeAngles()
		local headpos = body:GetBonePosition(body:LookupBone("ValveBiped.Bip01_Head1"))
		local needpos = headpos - angles:Forward()*18 + angles:Right()*16 - angles:Up()*2
        if ply:IsZombie() then
            needpos = headpos - angles:Forward()*32 + angles:Right()*20 - angles:Up()*2
            if left_side then
                needpos = headpos - angles:Forward()*32 - angles:Right()*20 - angles:Up()*2
            end
        elseif not ply:IsZombie() and left_side then
            needpos = headpos - angles:Forward()*18 - angles:Right()*16 - angles:Up()*2
        end
		local limitpos = headpos
		local cutscene = ply:GetNWBool('SVAnimStopCutscene')
		local person = GetConVar("sur_viewmod"):GetFloat()
        local person_cutscene = GetConVar("sur_viewmod_cutscene"):GetFloat()
        local person_da = GetConVar("sur_viewmod_deathanims"):GetFloat()
		local wep = ply:GetActiveWeapon()
        local person_da_check = false

		if ply:KeyDown(IN_ATTACK2) and changeview and IsValid(wep) and isstring(wep.Base) and string.match(wep.Base, "tfa") and wep:GetMaxClip1() > 0 and person > 0 then
			changeview = false
			ply:ScreenFade(SCREENFADE.IN, color_black, 0.3, 0)
		elseif not ply:KeyDown(IN_ATTACK2) and not changeview then
			changeview = true
			ply:ScreenFade(SCREENFADE.IN, color_black, 0.3, 0)
		end

        local tp_enable = person == 2 and not cutscene or (cutscene or ply:IsDowned()) and person_cutscene == 1
        local fp_enable = person == 1 and not cutscene or (cutscene or ply:IsDowned()) and person_cutscene == 0
        if person_da == 0 and (string.match(ply:GetSVAnim(), "killmove") or string.match(ply:GetSVAnim(), "executions")) then
            fp_enable = true
            tp_enable = false
            person_da_check = true
        elseif person_da == 1 and (string.match(ply:GetSVAnim(), "killmove") or string.match(ply:GetSVAnim(), "executions")) then
            tp_enable = true
            fp_enable = false
            person_da_check = true
        end

        if fp_enable and not tp_enable then
            ply:ManipulateBoneScale(ply:LookupBone("ValveBiped.Bip01_Head1"), Vector(0,0,0))
        else
            ply:ManipulateBoneScale(ply:LookupBone("ValveBiped.Bip01_Head1"), Vector(1,1,1))
        end

		if tp_enable then
			if cutscene or ply:IsDowned() or person_da_check then
                local pos2 = pos
                if string.match(ply:GetSVAnim(), "killmove") or string.match(ply:GetSVAnim(), "executions") or string.match(ply:GetSVAnim(), "killanim") then
                    pos2 = body:GetBonePosition(body:LookupBone("ValveBiped.Bip01_Head1"))
                    pos2.z = ply:EyePos().z-16
                    curmask = MASK_SOLID_BRUSHONLY
                end
				needpos = pos2 - angles:Forward()*64 + angles:Right()*32 + ply:GetNWVector('CutsceneAddPos')
                if left_side then
                    needpos = pos2 - angles:Forward()*64 - angles:Right()*32 + ply:GetNWVector('CutsceneAddPos')
                    plyang = plyang + Angle(10,-20,0)
                    if string.match(ply:GetSVAnim(), "closeencounter") then
                        needpos = pos2 - angles:Forward()*32 - angles:Right()*48 + ply:GetNWVector('CutsceneAddPos')
                        plyang = plyang + Angle(15,-30,0)
                        plyang.z = math.Clamp(ply:GetAttachment(ply:LookupAttachment('eyes')).Ang.z/2, -45, 45)
                        curmask = MASK_SOLID_BRUSHONLY
                    elseif string.match(ply:GetSVAnim(), "killanim") then
                        local att = ply:GetAttachment(ply:LookupAttachment('eyes'))
                        needpos = pos2 - angles:Forward()*32 - angles:Right()*48 + ply:GetNWVector('CutsceneAddPos')
                        plyang = plyang + Angle(0,-20,0)
                        plyang.x = -(needpos-att.Pos):GetNormalized():Angle().x+15
                        plyang.z = math.Clamp(att.Ang.z/4, -45, 45)
                        curmask = MASK_SOLID_BRUSHONLY
                    end
                else
                    plyang = plyang + Angle(10,20,0)
                    if string.match(ply:GetSVAnim(), "closeencounter") then
                        needpos = pos2 - angles:Forward()*32 + angles:Right()*48 + ply:GetNWVector('CutsceneAddPos')
                        plyang = plyang + Angle(15,30,0)
                        plyang.z = math.Clamp(ply:GetAttachment(ply:LookupAttachment('eyes')).Ang.z/2, -45, 45)
                        curmask = MASK_SOLID_BRUSHONLY
                    elseif string.match(ply:GetSVAnim(), "killanim") then
                        local att = ply:GetAttachment(ply:LookupAttachment('eyes'))
                        needpos = pos2 - angles:Forward()*32 + angles:Right()*48 + ply:GetNWVector('CutsceneAddPos')
                        plyang = plyang + Angle(0,20,0)
                        plyang.x = -(needpos-att.Pos):GetNormalized():Angle().x+15
                        plyang.z = math.Clamp(att.Ang.z/4, -45, 45)
                        curmask = MASK_SOLID_BRUSHONLY
                    end
                end
                if ply:IsDowned() and ply:GetSVAnim() == "" then
                    needpos = needpos + angles:Up()*36
                end
			end

			currentpos = LerpVector(FrameTime()*6, currentpos, needpos)
			currentang = LerpAngle(FrameTime()*12, currentang, plyang)

			local tr = util.TraceLine({
				start = limitpos,
				endpos = currentpos,
				mask = curmask,
				filter = ply,
			})

			local wep = ply:GetActiveWeapon()
 
			if changeview then
				local view = {
					origin = tr.HitPos,
					angles = currentang,
					fov = fov,
					drawviewer = true,
                    nearz = 1
				}

				return view
			else
				currentpos = limitpos
			end
		elseif fp_enable then
            local ang1 = angles
			currentpos = limitpos

			if changeview then
				local eye = body:GetAttachment(body:LookupAttachment('eyes'))
                if string.match(ply:GetSVAnim(), "sur_executions_") and body:LookupAttachment('custom_eyes') > 0 then
                    eye = body:GetAttachment(body:LookupAttachment('custom_eyes'))
                end
                if cutscene then
                    ang1 = eye.Ang
                end
				local view = {
					origin = eye.Pos,
					angles = ang1,
					fov = fov,
					drawviewer = true,
                    nearz = 1
				}

				return view
			end
        else
            currentpos = limitpos
            currentang = angles
            if ply:Alive() and not ply:ShouldDrawLocalPlayer() then
                local velocity = ply:GetVelocity():Length()
                if velocity > 0 and last_velocity == 0 then
                    viewbob_offset = 0
                end
                last_velocity = velocity
                viewbob_offset = viewbob_offset + (viewbob_speed * FrameTime())
                local bob_x = math.sin(viewbob_offset) * viewbob_amount * last_velocity
                local bob_y = math.cos(viewbob_offset) * viewbob_amount * last_velocity
                angles.roll = angles.roll + bob_y/2
                angles.x = angles.x + bob_x/4
                local view = {}
                view.origin = pos
                view.angles = angles+FPOffsetAngles
                view.fov = fov

                local power = ply:GetVelocity():Length()/25
                local num1 = math.Clamp(power, 0, 10)

                if ply:KeyDown(IN_MOVELEFT) then
                    fp_offset.z = -num1
                elseif ply:KeyDown(IN_MOVERIGHT) then
                    fp_offset.z = num1
                else
                    fp_offset.z = 0    
                end

                if ply:KeyDown(IN_FORWARD) and !ply:KeyDown(IN_ATTACK2) then
                    fp_offset.x = num1
                elseif ply:KeyDown(IN_BACK) and !ply:KeyDown(IN_ATTACK2) then
                    fp_offset.x = -num1
                else
                    fp_offset.x = 0    
                end

                FPOffsetAngles = LerpAngle(FrameTime()*4, FPOffsetAngles, Angle(fp_offset.x, fp_offset.y, fp_offset.z))

                return view
            end
		end
	end
end)

------------------------------------------------------------------------BOSS PART

local barMat = Material('surrounded/bar.png', 'smooth')

net.Receive("SuR.Boss", function()
    local name = SuR.Language[net.ReadString()]
    local ent = net.ReadEntity()
    local alpha = 0
    local morealpha = true
    hook.Add("HUDPaint", "SuR_Boss", function()
        surface.SetMaterial(barMat)
        surface.SetDrawColor(0,0,0,alpha)
        surface.DrawTexturedRect(ScrW()/2-We(240), He(30), We(480), He(50))

        if IsValid(ent) then
            local mult = (ent:Health()/ent:GetMaxHealth())
            surface.SetMaterial(barMat)
            surface.SetDrawColor(150,0,0,alpha)
            render.SetScissorRect( ScrW()/2-We(240), He(30), ScrW()/2+We(480*mult-240), He(80), true )
                surface.DrawTexturedRect(ScrW()/2-We(235), He(35), We(470), He(40))
            render.SetScissorRect( 0, 0, 0, 0, false )
        else
            morealpha = false
        end

        draw.SimpleText(name, "SuR_SmallFont2", ScrW()/2, He(25), Color(255,255,255,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

        if morealpha then
            alpha = math.Clamp(alpha+FrameTime()/0.01, 0, 255)
        else
            alpha = math.Clamp(alpha-FrameTime()/0.01, 0, 255)
            if alpha == 0 then
                hook.Remove("HUDPaint", "SuR_Boss")
            end
        end
    end)
end)

------------------------------------------------------------------------MUSIC PART

local rndmusic = ""
local musicname = ""
local currentchannel = nil
local otherchannel = nil

local function RandomizeTrack()
	local tab = SuR.Config.MusicWave
	local wave = SuR.Data["Wave"]
    if SuR.Data["ExfilWave"] and SuR.Data["WaveState"] then
        rndmusic = tab["Exfil"][math.random(1,#tab["Exfil"])]
        return
    end
    if SuR.Config.Objective_Mode then
        rndmusic = tab["Objective"][math.random(1,#tab["Objective"])]
        return
    end
	for k, v in pairs(tab) do
		local allow = false
		if (k == "Easy" and wave < 3) or (k == "Medium" and wave >= 3 and wave < 6) or (k == "Hard" and wave >= 6 and wave < 10) or (k == "Chaos" and wave >= 10 and wave < 15) or (k == "Extreme" and wave >= 15) then
			allow = true
		end
		if allow then
			rndmusic = v[math.random(1,#v)]
			break
		end
	end
end

hook.Add("Think", "MainMusic", function()
	local wave = SuR.Data["Wave"]
	local wavest = SuR.Data["WaveState"]
	if wavest and wave > 0 and not SuR.Data["DisableMusic"] then
		SuR:PlayMusic(rndmusic)
		if IsValid(currentchannel) then
			local maxtime = currentchannel:GetLength()
			local time = currentchannel:GetTime()
			currentchannel:SetVolume(GetConVar("sur_music_volume"):GetFloat())
			if time >= maxtime or currentchannel:GetState() == 0 or currentchannel:GetState() == 2 or (SuR.Data["ExfilWave"] and SuR.Data["WaveState"] and !table.HasValue(SuR.Config.MusicWave["Exfil"], rndmusic)) then
				RandomizeTrack()
				SuR:PlayMusic("")
			end
		end
	else
		if IsValid(currentchannel) then
			local volume = currentchannel:GetVolume()
			currentchannel:SetVolume(math.max(volume-FrameTime()/2, 0))
			if volume == 0 then
				SuR:PlayMusic("")
			end
		end
		RandomizeTrack()
	end
    if IsValid(otherchannel) then
        otherchannel:SetVolume(GetConVar("sur_music_volume"):GetFloat())
    end
end)

function SuR:PlayMusicOther(str)
    if IsValid(otherchannel) then
        otherchannel:Stop()
    end
	sound.PlayFile("sound/"..str, "noblock", function(station, s1, s2)
        if IsValid(station) then
            station:Play()
            station:SetVolume(GetConVar("sur_music_volume"):GetFloat())
            otherchannel = station
        end
    end)
end

function SuR:PlayMusic(music1, rnd)
	local music = "sound/"..music1
    if rnd then
        RandomizeTrack()
        music1 = rndmusic
    end
	if music1 != "" then
		if musicname == music1 then 
			return
		else
			if IsValid(currentchannel) then
				currentchannel:Stop()
				currentchannel = nil
			end
			timer.Simple(1, function()
				sound.PlayFile(music, "noblock", function(station, s1, s2)
					if IsValid(station) then
						station:Play()
						currentchannel = station
					end
				end)
			end)
		end

		musicname = music1
	else
		musicname = ""
		if IsValid(currentchannel) then
			currentchannel:Stop()
			currentchannel = nil
		end
	end
end

timer.Simple(0.5, function()
    local f = file.Read("surrounded/music_replacement.lua", "LUA")
    if !isstring(f) then return end

    local pattern = "start_config.-end_config"
    local musicWaveTable = string.match(f, pattern)
    
    if !musicWaveTable then return end
    musicWaveTable = string.Replace(musicWaveTable, "start_config", "SuR.Config.MusicWave = {")
    musicWaveTable = string.Replace(musicWaveTable, "end_config", "}")
    RunString(musicWaveTable)
end)

------------------------------------------------------------------------ANIM PART

local disable_tab = {
    ["sur_helpup_trials_follower_try"] = true,
    ["sur_helpup_trials_leader_try"] = true,
    ["sur_helpup_trials_follower_success"] = true,
    ["sur_helpup_trials_leader_success"] = true,
    ["sur_helpup_trials_follower_drophigh"] = true,
    ["sur_helpup_trials_leader_leave"] = true,
}
hook.Add("AdjustMouseSensitivity", "SuR_Sens", function()
	local ply = LocalPlayer()
	local downed = ply:IsDowned()
    local disable = disable_tab[ply:GetSVAnim()]
	if downed then
		return 0.1
	end
    if disable then
        return 0.001
    end
	if ply:IsZombie() and ply:Alive() then
		return 0.5
	end
end)

hook.Add("CalcMainActivity", "MainAnims", function(ply, vel)
    local str = ply:GetSVAnim()
    local num = ply:GetNWFloat('SVAnimDelay')
    local st = ply:GetNWFloat('SVAnimStartTime')
	local downed = ply:IsDowned()
    local dir = ply:GetNWString("MoveDirection")
    if str != "" then
        ply:SetCycle((CurTime()-st)/num)
        return -1, ply:LookupSequence(str)
    end
	if downed then
        if ply:GetCycle() == 1 then
            ply:SetCycle(0)
        end
		local speed = ply:GetVelocity():Length()
		if speed > 5 then
            if dir == "forward" then
			    return -1, ply:LookupSequence("sur_downed_trials_forward")
            elseif dir == "backward" then
			    return -1, ply:LookupSequence("sur_downed_trials_backward")
            elseif dir == "left" then
			    return -1, ply:LookupSequence("sur_downed_trials_left")
            elseif dir == "right" then
			    return -1, ply:LookupSequence("sur_downed_trials_right")
            else
                return -1, ply:LookupSequence("sur_downed_trials_idle")
            end
		else
			return -1, ply:LookupSequence("sur_downed_trials_idle")
		end
	end
	if ply:IsZombie() then
		local speed = vel:Length()
		local cr = ply:Crouching()
		if !ply:OnGround() then
			return ACT_JUMP, -1
		elseif speed > 200 and not cr then
			return ACT_SPRINT, -1
		elseif speed > 75 and not cr or cr and speed > 25 then
			if cr then
				return ACT_WALK_AGITATED, -1
			else
				return ACT_RUN, -1
			end
		elseif speed > 10 then
			if cr then
				return ACT_WALK_STIMULATED, -1
			else
				if ply:GetModel() == "models/vj_lnrspecials/brute.mdl" then
					return ACT_WALK_AIM, -1
				else
					return ACT_WALK, -1
				end
			end
		else
			if cr then
				return ACT_IDLE_STIMULATED, -1
			else
				return ACT_IDLE, -1
			end
		end
	end
end)

------------------------------------------------------------------------MARK PART

local num_marks = 0
local mat_markpoint = Material("surrounded/marks/point.png")
local mat_markitem = Material("surrounded/marks/item.png")
local mat_markenemy = Material("surrounded/marks/enemy.png")

function screen_distance(x1, y1, x2, y2)
    local dif = Vector(x1, y1):Distance(Vector(x2, y2))
    return dif
end

net.Receive("SuR.PointMark", function()
    local type = net.ReadString()
    local ply = net.ReadEntity()
    local data = net.ReadTable()[1]
    if not data then return end

    local mat = mat_markpoint
    if type == "item" then
        mat = mat_markitem
        surface.PlaySound("surrounded/sfx/mark_item.mp3")
    elseif type == "enemy" then
        mat = mat_markenemy
        surface.PlaySound("surrounded/sfx/mark_enemy.mp3")
    else
        surface.PlaySound("surrounded/sfx/mark_point.mp3")
    end

    num_marks = num_marks + 1

    local name = "SuR_PointMark"..num_marks
    local nick = ply:Nick()
    local alpha = 255
    local height = ScrH()/2

    hook.Add("HUDPaint", name.."n", function()
        draw.SimpleText(nick .. SuR.Language["message_mark"], "SuR_SmallFont1", We(50), height, Color(255,255,255,alpha), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        height = height - FrameTime()/0.01
        alpha = alpha - FrameTime()/0.005
        if alpha <= 0 then
            hook.Remove("HUDPaint", name.."n")
        end
    end)

    hook.Add("HUDPaint", name, function()
        if !LocalPlayer():Alive() then
            hook.Remove("HUDPaint", name)
            return
        end
        local pos = Vector()
        if isvector(data) then
            pos = data
        else
            if !IsValid(data) then
                hook.Remove("HUDPaint", name)
                return
            end
            pos = data:WorldSpaceCenter()
        end
        local spos = pos:ToScreen()
        local dist = screen_distance(ScrW()/2, ScrH()/2, spos.x, spos.y) < 50
        if dist then
            surface.SetDrawColor(255,255,255,230)
            surface.SetMaterial(mat)
            surface.DrawTexturedRect(spos.x-We(32), spos.y-He(32), We(64), He(64))
            draw.SimpleText(nick, "SuR_PixelFont", spos.x, spos.y+He(40), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
            draw.SimpleText(math.Round(LocalPlayer():GetPos():Distance(pos) * 2/100) .. " m", "SuR_SmallFont1", spos.x, spos.y+He(55), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        else
            surface.SetDrawColor(255,255,255,150)
            surface.SetMaterial(mat)
            surface.DrawTexturedRect(spos.x-We(12), spos.y-He(12), We(24), He(24))
            draw.SimpleText(math.Round(LocalPlayer():GetPos():Distance(pos) * 2/100) .. " m", "SuR_PixelFont", spos.x, spos.y+He(20), Color(255,255,255,150), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        end
    end)

    timer.Simple(30, function()
        hook.Remove("HUDPaint", name)
    end)
end)