Garry's Mod Leaks

nxserv nametags new

Submitted by mrredar, , Thread ID: 204755

Thread Closed
26-04-2021, 03:42 PM
This post was last modified: 26-04-2021, 03:43 PM by mrredar
#1
local SCALE = 0.05

surface.CreateFont("nx_hud_nametag_main", {
size = 4.5 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
font = "Roboto"
})

surface.CreateFont("nx_hud_nametag_main_shadow", {
size = 4.5 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
blursize = 0.4 / SCALE,
font = "Roboto"
})

surface.CreateFont("nx_hud_nametag_icon", {
size = 4.5 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
font = NX_ICONFONT
})

surface.CreateFont("nx_hud_nametag_icon_shadow", {
size = 4.5 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
blursize = 0.4 / SCALE,
font = NX_ICONFONT
})

surface.CreateFont("nx_hud_nametag_sub", {
size = 3 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
font = "Roboto"
})

surface.CreateFont("nx_hud_nametag_sub_shadow", {
size = 3 / SCALE,
weight = 350,
antialias = true,
extended = true,
shadow = false,
outline = false,
blursize = 0.4 / SCALE,
font = "Roboto"
})



local roofcache = {}
local function getroof(car)
if car:GetParent():IsValid() and car:GetParent():IsVehicle() then
car = car:GetParent()
end

local mdl = car:GetModel()
if not roofcache[mdl] then
roofcache[mdl] = car:WorldToLocal(util.TraceLine{start = car:LocalToWorld(Vector(0, 0, car:OBBMaxs().z)), endpos = car:LocalToWorld(Vector(0, 0, car:OBBMins().z)), filter = function(ent) return ent == car end}.HitPos)
end
return car:LocalToWorld(roofcache[mdl]).z
end


local oy = 0
local drawables = {}
local fn = 0
local ffov = 0
local fadedist = 512

local putText = function(str, font, color)
surface.SetFont(font)

local w, h = surface.GetTextSize(str)
oy = oy - h

surface.SetFont(font .. "_shadow")

surface.SetTextPos(-w*0.5, oy)
surface.SetTextColor(color_black)
surface.DrawText(str)

surface.SetFont(font)

surface.SetTextPos(-w*0.5, oy)
surface.SetTextColor(color)
surface.DrawText(str)
end

local debug_plates = false
local debug_counter = false

hook.Add("RenderScene", "NameTags", function(pos, ang, fov)
fn = FrameNumber()
ffov = fov
end)

hook.Add("PostDrawTranslucentRenderables", "NameTags", function(depth, sky)
if depth or sky then return end

local ang = Angle(0, EyeAngles().y - 90, 90)
local eyepos = EyePos()

local counter = 0
local cfn = fn-1
for pl, fn in pairs(drawables) do
if not pl:IsValid() then
drawables[pl] = nil
continue
end

if pl.Alive and not pl:Alive() then continue end
if cfn ~= fn and (cfn+1)~=fn then continue end -- whether real world or rt scope?

local eye

local boneId = pl:LookupBone("ValveBiped.Bip01_Head1")
if boneId then
eye = (pl:GetBonePosition(boneId))
else
eye = pl:GetPos()
end

if pl.InVehicle and pl:InVehicle() then
eye.z = math.max(eye.z + 9, getroof(pl:GetVehicle()) + 5)
else
eye.z = eye.z + 9
end

if cfn == fn and eyepos:Distance(eye) > fadedist / math.atan(math.rad(ffov)) then continue end -- compensate for fov
-- if you're looking through scope it might draw a fuckton of player plates, which sucks
-- todo: we need to check for aimscope visible box

counter = counter + 1

oy = 0
cam.Start3D2D(eye, ang, SCALE)
--surface.SetDrawColor(color_white)
--surface.DrawRect(-256, 0, 512, 4)

--[==[
local staticLight = render.ComputeLighting(eye, vector_up)
local dynamicLight = render.ComputeDynamicLighting(eye, vector_up)

local bothLight = Vector(math.max(staticLight.x, dynamicLight.x), math.max(staticLight.y, dynamicLight.y), math.max(staticLight.z, dynamicLight.z))
bothLight = math.max(bothLight.x, bothLight.y, bothLight.z)

local dot = LocalPlayer():GetAimVector():Dot((eye - LocalPlayer():EyePos()):GetNormalized())

if --[[LocalPlayer():EyePos():Distance(eye) < 64 or]] (LocalPlayer():FlashlightIsOn() and dot > 0.85) then
bothLight = (dot-0.85)/(1-0.85)
end

surface.SetAlphaMultiplier(bothLight)
]==]

if pl:IsPlayer() then
putText(pl:Name(), "nx_hud_nametag_main", color_white)
putText(pl:getDarkRPVar("job") or team.GetName(pl:Team()), "nx_hud_nametag_sub", team.GetColor(pl:Team()))

if debug_plates or pl:getDarkRPVar("HasGunlicense") then
putText(DarkRP.getPhrase("with_license"), "nx_hud_nametag_sub", color_white)
end

if debug_plates or LocalPlayer():getJobTable().medic then
putText(DarkRP.getPhrase("health", pl:Health()), "nx_hud_nametag_sub", color_white)
end

if debug_plates or pl:getDarkRPVar("wantedReason") then
local sin = math.sin(RealTime() * 8)
local flash = HSVToColor(sin > 0 and 0 or 240, math.abs(sin), 1)

putText(DarkRP.getPhrase("wanted") .. tostring(pl:getDarkRPVar("wantedReason")), "nx_hud_nametag_sub", flash)
end

if (pl:FindStat("lockdown") and LocalPlayer():isCP()) then
local lockdown = pl:FindStat("lockdown"):Get()
lockdown = lockdown > 0 and DarkRP.getPhrase("lockdown_info_timeleft", math.ceil(lockdown)) or DarkRP.getPhrase("lockdown_info_timeout")

putText(lockdown, "nx_hud_nametag_sub", color_white)
end

local icons = {}
if pl:IsTyping() or debug_plates then
table.insert(icons, "j")
end
if pl:IsSpeaking() or debug_plates then
table.insert(icons, "g")
end
if pl:GetCuffsState() or debug_plates then
table.insert(icons, "A")
end
if #icons > 0 then
local sine = HSVToColor(200, math.abs(math.sin(RealTime()*2)), 1)
putText(table.concat(icons), "nx_hud_nametag_icon", sine)
end
elseif pl:GetClass() == "npc_mike" then
putText(pl:GetRPName(), "nx_hud_nametag_main", color_white)
putText(team.GetName(TEAM_CITIZEN), "nx_hud_nametag_sub", team.GetColor(TEAM_CITIZEN))

local icons = {}
if pl.snd then
table.insert(icons, "g")
end
if #icons > 0 then
local sine = HSVToColor(200, math.abs(math.sin(RealTime()*2)), 1)
putText(table.concat(icons), "nx_hud_nametag_icon", sine)
end
elseif pl:GetClass() == "nx_citizen" then
putText("John Madden", "nx_hud_nametag_main", color_white)
putText(team.GetName(TEAM_CITIZEN), "nx_hud_nametag_sub", team.GetColor(TEAM_CITIZEN))
end
--surface.SetAlphaMultiplier(1)
cam.End3D2D()
end

if debug_counter then print(counter) end
end)

hook.Add("UpdateAnimation", "NameTags", function(pl)
if pl == LocalPlayer() and not pl:ShouldDrawLocalPlayer() then return end

drawables[pl] = fn
end)

function nametagsDrawablesAdd(ent)
drawables[ent] = fn
end

Users browsing this thread: 1 Guest(s)