Advertisement
Jak92

Untitled

Jul 4th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. surface.CreateFont( "3D2DName", { font = "Bebas Neue", size = 135, weight = 600 } )
  2.  
  3. local function DrawName( ply, opacityScale )
  4.  
  5.     if !IsValid(ply) or !ply:Alive() then return end
  6.    
  7.     local pos = ply:GetPos()
  8.     local ang = LocalPlayer():EyeAngles()
  9.    
  10.     ang:RotateAroundAxis( ang:Forward(), 90 )
  11.     ang:RotateAroundAxis( ang:Right(), 90 )
  12.    
  13.     if ply:InVehicle() then
  14.         pos = pos + Vector( 0, 0, 30 )
  15.     else
  16.         pos = pos + Vector( 0, 0, 60 )
  17.     end
  18.    
  19.     local dist = LocalPlayer():GetPos():Distance( ply:GetPos() )
  20.     if ( dist >= 800 ) then return end // no need to draw anything if the player is far away
  21.    
  22.     local opacity = math.Clamp( 310.526 - ( 0.394737 * dist ), 0, 150 ) // woot mathematica
  23.    
  24.     opacityScale = opacityScale and opacityScale or 1
  25.     opacity = opacity * opacityScale
  26.  
  27.     local name = "  " .. string.upper( ply:GetName() )
  28.  
  29.     cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.15 )
  30.  
  31.         -- render.OverrideDepthEnable(false, true)
  32.  
  33.         draw.TheaterText( name, "3D2DName", 50, 0, Color( 255, 255, 255, opacity ) )
  34.        
  35.         -- render.OverrideDepthEnable(false, false)
  36.  
  37.     cam.End3D2D()
  38.  
  39. end
  40.  
  41. local HUDTargets = {}
  42. local fadeTime = 2
  43. hook.Add( "PostDrawTranslucentRenderables", "DrawPlayerNames", function()
  44.  
  45.     -- Don't render names while we're sitting down
  46.     if GetConVar("cinema_drawnames") and !GetConVar("cinema_drawnames"):GetBool() then return end
  47.     if !LocalPlayer().InTheater then return end
  48.     if theater.Fullscreen then return end
  49.     if IsValid( LocalPlayer():GetVehicle() ) then return end
  50.  
  51.     -- Draw lower opacity and recently targetted players in theater
  52.     if LocalPlayer():InTheater() then
  53.  
  54.         for ply, time in pairs(HUDTargets) do
  55.  
  56.             if time < RealTime() then
  57.                 HUDTargets[ply] = nil
  58.                 continue
  59.             end
  60.  
  61.             -- Fade over time
  62.             DrawName( ply, 0.11 * ((time - RealTime()) / fadeTime) )
  63.  
  64.         end
  65.  
  66.         local tr = util.GetPlayerTrace( LocalPlayer() )
  67.         local trace = util.TraceLine( tr )
  68.         if (!trace.Hit) then return end
  69.         if (!trace.HitNonWorld) then return end
  70.        
  71.         -- Keep track of recently targetted players
  72.         if trace.Entity:IsPlayer() then
  73.             HUDTargets[trace.Entity] = RealTime() + fadeTime
  74.         elseif trace.Entity:IsVehicle() and
  75.             IsValid(trace.Entity:GetOwner()) and
  76.             trace.Entity:GetOwner():IsPlayer() then
  77.             HUDTargets[trace.Entity:GetOwner()] = RealTime() + fadeTime
  78.         end
  79.  
  80.     else -- draw all players names
  81.  
  82.         for _, ply in pairs( player.GetAll() ) do
  83.  
  84.             -- Don't draw name if either player is not in theater and the other is, etc.
  85.             if (LocalPlayer():InTheater() and !ply:InTheater()) or
  86.                 (!LocalPlayer():InTheater() and ply:InTheater()) then
  87.                 continue
  88.             end
  89.  
  90.             if ply != LocalPlayer() then
  91.                 DrawName( ply )
  92.             end
  93.         end
  94.  
  95.     end
  96.    
  97. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement