kizaru335

nxserv nametags

Aug 10th, 2017
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. local SCALE = 0.05
  2.  
  3. surface.CreateFont("nx_hud_nametag_main", {
  4. size = 4.5 / SCALE,
  5. weight = 350,
  6. antialias = true,
  7. extended = true,
  8. shadow = false,
  9. outline = false,
  10. font = "Roboto"
  11. })
  12.  
  13. surface.CreateFont("nx_hud_nametag_main_shadow", {
  14. size = 4.5 / SCALE,
  15. weight = 350,
  16. antialias = true,
  17. extended = true,
  18. shadow = false,
  19. outline = false,
  20. blursize = 0.4 / SCALE,
  21. font = "Roboto"
  22. })
  23.  
  24. surface.CreateFont("nx_hud_nametag_icon", {
  25. size = 4.5 / SCALE,
  26. weight = 350,
  27. antialias = true,
  28. extended = true,
  29. shadow = false,
  30. outline = false,
  31. font = NX_ICONFONT
  32. })
  33.  
  34. surface.CreateFont("nx_hud_nametag_icon_shadow", {
  35. size = 4.5 / SCALE,
  36. weight = 350,
  37. antialias = true,
  38. extended = true,
  39. shadow = false,
  40. outline = false,
  41. blursize = 0.4 / SCALE,
  42. font = NX_ICONFONT
  43. })
  44.  
  45. surface.CreateFont("nx_hud_nametag_sub", {
  46. size = 3 / SCALE,
  47. weight = 350,
  48. antialias = true,
  49. extended = true,
  50. shadow = false,
  51. outline = false,
  52. font = "Roboto"
  53. })
  54.  
  55. surface.CreateFont("nx_hud_nametag_sub_shadow", {
  56. size = 3 / SCALE,
  57. weight = 350,
  58. antialias = true,
  59. extended = true,
  60. shadow = false,
  61. outline = false,
  62. blursize = 0.4 / SCALE,
  63. font = "Roboto"
  64. })
  65.  
  66.  
  67.  
  68. local roofcache = {}
  69. local function getroof(car)
  70. if car:GetParent():IsValid() and car:GetParent():IsVehicle() then
  71. car = car:GetParent()
  72. end
  73.  
  74. local mdl = car:GetModel()
  75. if not roofcache[mdl] then
  76. 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)
  77. end
  78. return car:LocalToWorld(roofcache[mdl]).z
  79. end
  80.  
  81.  
  82. local oy = 0
  83. local drawables = {}
  84. local fn = 0
  85. local ffov = 0
  86. local fadedist = 512
  87.  
  88. local putText = function(str, font, color)
  89. surface.SetFont(font)
  90.  
  91. local w, h = surface.GetTextSize(str)
  92. oy = oy - h
  93.  
  94. surface.SetFont(font .. "_shadow")
  95.  
  96. surface.SetTextPos(-w*0.5, oy)
  97. surface.SetTextColor(color_black)
  98. surface.DrawText(str)
  99.  
  100. surface.SetFont(font)
  101.  
  102. surface.SetTextPos(-w*0.5, oy)
  103. surface.SetTextColor(color)
  104. surface.DrawText(str)
  105. end
  106.  
  107. local debug_plates = false
  108. local debug_counter = false
  109.  
  110. hook.Add("RenderScene", "NameTags", function(pos, ang, fov)
  111. fn = FrameNumber()
  112. ffov = fov
  113. end)
  114.  
  115. hook.Add("PostDrawTranslucentRenderables", "NameTags", function(depth, sky)
  116. if depth or sky then return end
  117.  
  118. local ang = Angle(0, EyeAngles().y - 90, 90)
  119. local eyepos = EyePos()
  120.  
  121. local counter = 0
  122. local cfn = fn-1
  123. for pl, fn in pairs(drawables) do
  124. if not pl:IsValid() then
  125. drawables[pl] = nil
  126. continue
  127. end
  128.  
  129. if pl.Alive and not pl:Alive() then continue end
  130. if cfn ~= fn and (cfn+1)~=fn then continue end -- whether real world or rt scope?
  131.  
  132. local eye
  133.  
  134. local boneId = pl:LookupBone("ValveBiped.Bip01_Head1")
  135. if boneId then
  136. eye = (pl:GetBonePosition(boneId))
  137. else
  138. eye = pl:GetPos()
  139. end
  140.  
  141. if pl.InVehicle and pl:InVehicle() then
  142. eye.z = math.max(eye.z + 9, getroof(pl:GetVehicle()) + 5)
  143. else
  144. eye.z = eye.z + 9
  145. end
  146.  
  147. if cfn == fn and eyepos:Distance(eye) > fadedist / math.atan(math.rad(ffov)) then continue end -- compensate for fov
  148. -- if you're looking through scope it might draw a fuckton of player plates, which sucks
  149. -- todo: we need to check for aimscope visible box
  150.  
  151. counter = counter + 1
  152.  
  153. oy = 0
  154. cam.Start3D2D(eye, ang, SCALE)
  155. --surface.SetDrawColor(color_white)
  156. --surface.DrawRect(-256, 0, 512, 4)
  157.  
  158. --[==[
  159. local staticLight = render.ComputeLighting(eye, vector_up)
  160. local dynamicLight = render.ComputeDynamicLighting(eye, vector_up)
  161.  
  162. local bothLight = Vector(math.max(staticLight.x, dynamicLight.x), math.max(staticLight.y, dynamicLight.y), math.max(staticLight.z, dynamicLight.z))
  163. bothLight = math.max(bothLight.x, bothLight.y, bothLight.z)
  164.  
  165. local dot = LocalPlayer():GetAimVector():Dot((eye - LocalPlayer():EyePos()):GetNormalized())
  166.  
  167. if --[[LocalPlayer():EyePos():Distance(eye) < 64 or]] (LocalPlayer():FlashlightIsOn() and dot > 0.85) then
  168. bothLight = (dot-0.85)/(1-0.85)
  169. end
  170.  
  171. surface.SetAlphaMultiplier(bothLight)
  172. ]==]
  173.  
  174. if pl:IsPlayer() then
  175. putText(pl:Name(), "nx_hud_nametag_main", color_white)
  176. putText(pl:getDarkRPVar("job") or team.GetName(pl:Team()), "nx_hud_nametag_sub", team.GetColor(pl:Team()))
  177.  
  178. if debug_plates or pl:getDarkRPVar("HasGunlicense") then
  179. putText(DarkRP.getPhrase("with_license"), "nx_hud_nametag_sub", color_white)
  180. end
  181.  
  182. if debug_plates or LocalPlayer():getJobTable().medic then
  183. putText(DarkRP.getPhrase("health", pl:Health()), "nx_hud_nametag_sub", color_white)
  184. end
  185.  
  186. if debug_plates or pl:getDarkRPVar("wantedReason") then
  187. local sin = math.sin(RealTime() * 8)
  188. local flash = HSVToColor(sin > 0 and 0 or 240, math.abs(sin), 1)
  189.  
  190. putText(DarkRP.getPhrase("wanted") .. tostring(pl:getDarkRPVar("wantedReason")), "nx_hud_nametag_sub", flash)
  191. end
  192.  
  193. if (pl:FindStat("lockdown") and LocalPlayer():isCP()) then
  194. local lockdown = pl:FindStat("lockdown"):Get()
  195. lockdown = lockdown > 0 and DarkRP.getPhrase("lockdown_info_timeleft", math.ceil(lockdown)) or DarkRP.getPhrase("lockdown_info_timeout")
  196.  
  197. putText(lockdown, "nx_hud_nametag_sub", color_white)
  198. end
  199.  
  200. local icons = {}
  201. if pl:IsTyping() or debug_plates then
  202. table.insert(icons, "j")
  203. end
  204. if pl:IsSpeaking() or debug_plates then
  205. table.insert(icons, "g")
  206. end
  207. if pl:GetCuffsState() or debug_plates then
  208. table.insert(icons, "A")
  209. end
  210. if #icons > 0 then
  211. local sine = HSVToColor(200, math.abs(math.sin(RealTime()*2)), 1)
  212. putText(table.concat(icons), "nx_hud_nametag_icon", sine)
  213. end
  214. elseif pl:GetClass() == "npc_mike" then
  215. putText(pl:GetRPName(), "nx_hud_nametag_main", color_white)
  216. putText(team.GetName(TEAM_CITIZEN), "nx_hud_nametag_sub", team.GetColor(TEAM_CITIZEN))
  217.  
  218. local icons = {}
  219. if pl.snd then
  220. table.insert(icons, "g")
  221. end
  222. if #icons > 0 then
  223. local sine = HSVToColor(200, math.abs(math.sin(RealTime()*2)), 1)
  224. putText(table.concat(icons), "nx_hud_nametag_icon", sine)
  225. end
  226. elseif pl:GetClass() == "nx_citizen" then
  227. putText("John Madden", "nx_hud_nametag_main", color_white)
  228. putText(team.GetName(TEAM_CITIZEN), "nx_hud_nametag_sub", team.GetColor(TEAM_CITIZEN))
  229. end
  230. --surface.SetAlphaMultiplier(1)
  231. cam.End3D2D()
  232. end
  233.  
  234. if debug_counter then print(counter) end
  235. end)
  236.  
  237. hook.Add("UpdateAnimation", "NameTags", function(pl)
  238. if pl == LocalPlayer() and not pl:ShouldDrawLocalPlayer() then return end
  239.  
  240. drawables[pl] = fn
  241. end)
  242.  
  243. function nametagsDrawablesAdd(ent)
  244. drawables[ent] = fn
  245. end
Advertisement
Add Comment
Please, Sign In to add comment