CapsAdmin

Untitled

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