Advertisement
Capster

littlefix

Apr 19th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.50 KB | None | 0 0
  1.  
  2. local META = FindMetaTable("Player")
  3.  
  4. if CLIENT then
  5.     local font_name = "NameTags"
  6.     local font_scale = 0.1
  7.    
  8.     surface.CreateFont(
  9.         font_name,
  10.         {
  11.             font        = "Tahoma",
  12.             size        = 500,
  13.             weight      = 800,
  14.             antialias   = true,
  15.             additive    = true,
  16.         }
  17.     )
  18.    
  19.     local font_name_blur = font_name.."_blur"
  20.  
  21.     local afk_phrases = {
  22.         "Drinking some tea...",
  23.         "Probably sleeping...",
  24.         "Away...",
  25.         "Ya-a-a-a-wn...",
  26.         "Zzz...",
  27.         "Dreaming of gmod...",
  28.     }
  29.    
  30.     surface.CreateFont(
  31.         font_name_blur,
  32.         {
  33.             font        = "Tahoma",
  34.             size        = 500,
  35.             weight      = 800,
  36.             antialias   = true,
  37.             additive    = false,
  38.             blursize    = 10,
  39.         }
  40.     )
  41.  
  42.     net.Receive("CustomTitle", function()
  43.         local data = net.ReadTable()
  44.        
  45.         local ply = data.ply or NULL
  46.         local title = data.title
  47.        
  48.         if ply:IsValid() then
  49.             ply.CustomTitle = title
  50.  
  51.             if ply == LocalPlayer() then
  52.                 file.Write("custom_title.txt", title)
  53.             end
  54.         end
  55.     end)
  56.  
  57.     hook.Add("PopulateToolMenu", "NameTags", function()
  58.         spawnmenu.AddToolMenuOption("Options", "Player", "Custom Title", "Custom Title", "", "", function(panel)
  59.             local entry = panel:TextEntry("Nametag")
  60.             entry:SetTall(150)
  61.             entry:SetMultiline(true)
  62.             entry:SetEditable(true)
  63.             entry:SetAllowNonAsciiCharacters(true)
  64.  
  65.             local button = panel:Button("Set Title")
  66.             button:SetText("Set Title")
  67.             button.DoClick = function()
  68.                 net.Start("CustomTitle")
  69.                     net.WriteString(entry:GetValue())
  70.                 net.SendToServer()
  71.             end
  72.         end)
  73.     end)
  74.  
  75.     local inited=false
  76.     local function Init()
  77.         if inited then return end
  78.         inited=true
  79.        
  80.         local title = file.Read("custom_title.txt","DATA")
  81.        
  82.         net.Start("CustomTitle")
  83.             net.WriteString(title or "")
  84.         net.SendToServer()
  85.        
  86.     end
  87.    
  88.     hook.Add("InitPostEntity", "NameTags", Init)
  89.     if LocalPlayer():IsValid() then Init() end
  90.  
  91.     local angles = Angle(0,0,90)   
  92.     local cl_shownametags = CreateClientConVar("cl_shownametags", "1", true)   
  93.    
  94.     local offset = 20
  95.     local eyepos = Vector()
  96.     local eyeang = Vector()
  97.    
  98.     hook.Add("RenderScene", "NameTags", function(pos, ang) eyepos = pos eyeang = ang end)
  99.  
  100.     local function get_head_pos(ent)
  101.         local pos, ang
  102.         local bone = ent:LookupBone("ValveBiped.Bip01_Head1")
  103.        
  104.         if bone then
  105.             pos, ang = ent:GetBonePosition(bone)
  106.         else
  107.             pos, ang = ent:EyePos(), ent:EyeAngles()
  108.         end
  109.  
  110.         pos = pos + ent:GetUp() * offset
  111.                
  112.         return pos, ang
  113.     end
  114.    
  115.     local function draw_text(text, color, x, y)    
  116.         surface.SetFont(font_name_blur)
  117.         surface.SetTextColor(color_black)
  118.        
  119.         for i=1, 5 do
  120.             surface.SetTextPos(x,y)
  121.             surface.DrawText(text)
  122.         end
  123.    
  124.         surface.SetFont(font_name)
  125.         surface.SetTextColor(color)
  126.         surface.SetTextPos(x,y)
  127.         surface.DrawText(text)
  128.     end
  129.    
  130.     local spacing = 1.5
  131.     local white = Color(255, 255, 255, 255)
  132.     local function draw_nametag(ply, alpha)    
  133.         surface.SetFont(font_name)
  134.         local time = RealTime()
  135.        
  136.         angles.p = eyeang.p
  137.         angles.y = eyeang.y
  138.         angles.r = eyeang.r
  139.         angles:RotateAroundAxis(angles:Up(), -90)
  140.         angles:RotateAroundAxis(angles:Forward(), 90)
  141.            
  142.         local ent = ply.GetRagdollEntity and ply:GetRagdollEntity() or ply
  143.         local head_pos, head_ang = get_head_pos(ent)
  144.                
  145.         local scale = ply:GetModelScale()
  146.         local h_offset = 0
  147.                
  148.         local text = ply:Name()
  149.         text = text:gsub("%^%d", "") --- !?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
  150.         local w, h = surface.GetTextSize(text) 
  151.         local size = 0.3 * scale * font_scale
  152.         local c = team.GetColor(ply:Team())
  153.         cam.Start3D2D(head_pos, angles, size)
  154.             draw_text(text, c, -(w/2), 0)
  155.         cam.End3D2D()
  156.         h_offset = h_offset + (h * spacing)
  157.        
  158.         local classtab = ply:Team() == TEAM_UNDEAD and ply:GetZombieClassTable()
  159.         local title = (ply:Team() == TEAM_HUMAN and ply:GetActiveWeapon())
  160.         or (classtab.TranslationName and translate.Get(classtab.TranslationName) or classtab.Name)
  161.        
  162.         if ply:Team() == TEAM_UNDEAD and title or title:IsValid() then
  163.             local newtitle = ply:Team() == TEAM_HUMAN and title:GetPrintName() or title
  164.             local w, h = surface.GetTextSize(newtitle)
  165.             cam.Start3D2D(head_pos, angles, 0.2 * scale * font_scale)  
  166.                 draw_text(newtitle, white, -(w/2), h_offset)
  167.             cam.End3D2D()
  168.             h_offset = h_offset + (h * spacing)
  169.         end
  170.                
  171.         if META.IsAFK and ply:IsAFK() then         
  172.             local s = afk_phrases[math.floor((CurTime()/4 + ply:EntIndex())%#afk_phrases) + 1]
  173.            
  174.             local w, h = surface.GetTextSize(s)
  175.            
  176.             cam.Start3D2D(head_pos, angles, 0.3 * scale * font_scale)
  177.                 draw_text(s, Color(102, 102, 204), -(w/2), -spacing * h / spacing)
  178.             cam.End3D2D()
  179.         end
  180.     end
  181.    
  182.     local drawables=setmetatable({},{__mode='k'})
  183.     hook.Add("PostDrawTranslucentRenderables", "NameTags", function()
  184.         if not cl_shownametags:GetBool() then return end
  185.         local me = LocalPlayer()
  186.         for key, ply in pairs(player.GetAll()) do
  187.             if not drawables[ply] then continue end
  188.             drawables[ ply ] = false
  189.             ply.nametag_pixvis = ply.nametag_pixvis or util.GetPixelVisibleHandle()
  190.             if util.PixelVisible(ply:EyePos(), 32, ply.nametag_pixvis) > 0 and ply:Team() == me:Team() and not ply:GetNWBool("Restrictions", false) and not ply:IsCrow() then
  191.                 draw_nametag(ply)
  192.             end
  193.         end    
  194.        
  195.     end)
  196.    
  197.     --THIS IS HERE FOR PLAYER TELEPORTING SINCE THE PREVIOUS POSITION IS WHERE THEY LEFT IF THEY LEFT YOUR PVS
  198.     hook.Add("PostPlayerDraw", "NameTags", function(pl)
  199.         drawables[pl] = true
  200.     end)
  201.    
  202. else -- server
  203.  
  204.     util.AddNetworkString("CustomTitle")
  205.    
  206.     local function send(ply,target)
  207.         net.Start("CustomTitle")
  208.             net.WriteTable({title = ply.CustomTitle, ply = ply})
  209.         if target then
  210.             net.Send(target)
  211.         else
  212.             net.Broadcast()
  213.         end
  214.     end
  215.  
  216.     function META:SetCustomTitle(title)
  217.         self.CustomTitle = title or ""
  218.         send(self)
  219.     end
  220.  
  221.     local init={}
  222.     net.Receive("CustomTitle", function(len, ply)
  223.         local str = net.ReadString()
  224.        
  225.         if not init[ply] then
  226.             init[ply] = true
  227.             for k,v in pairs(player.GetAll()) do
  228.                 if v.CustomTitle and v ~= ply then
  229.                     send(v,ply)
  230.                 end
  231.             end
  232.             if #str==0 then
  233.                 return
  234.             end
  235.         end
  236.        
  237.         ply:SetCustomTitle(str)
  238.        
  239.     end)
  240.    
  241.     hook.Add("AowlInitialized", "nametags", function()     
  242.        
  243.         aowl.AddCommand("title", function(ply, line, target, targetline)
  244.             if not targetline or not ply:CheckUserGroupLevel("developers") then
  245.                 ply:SetCustomTitle(line or '')
  246.             else
  247.                 local ent = easylua.FindEntity(target)
  248.                 if not IsValid(ent) or not ent:IsPlayer() then return false, aowl.TargetNotFound(target) end
  249.                 ent:SetCustomTitle(targetline)
  250.             end
  251.         end, "players")
  252.        
  253.         hook.Remove("AowlInitialized", "nametags")
  254.        
  255.     end)
  256.    
  257. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement