Guest User

Untitled

a guest
Jan 9th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.07 KB | None | 0 0
  1. -- Gamemode Selection:
  2. local isTTT = false
  3. local isSandbox = true -- Default to this if your gamemode is something different
  4. local isDarkRP = false
  5.  
  6. -- Message Stuff:
  7. local maxLength = 80 -- Maximum string length before it gets automatically ommitted
  8. local maxMessages = 8 -- Maximum messages displayed above the player's head before it starts deleting
  9.  
  10. -- Colors:
  11. local textColor = Color(255,255,255,255) -- Message color
  12. local plyColor = Color(25, 200, 25, 255) -- Player name color
  13. local textShadowColor = Color(0,0,0,255) -- Message shadow color
  14. local plyShadowColor = Color(0, 80, 0, 255) -- Player name shadow color
  15.  
  16. local plyCanSeeOwnMsg = false -- (not recommended) Allow the players to see their own messages above their head, glitchy AF
  17.  
  18. if SERVER then
  19.     AddCSLuaFile()
  20.     util.AddNetworkString( "PlayerSaidSomethin" )
  21.    
  22.     hook.Add( "PlayerSay", "PlayerHasSpoken", function( ply, text, team )
  23.         if not ply:Alive() then return end
  24.         local SayData = {}
  25.         SayData.ply = ply
  26.         SayData.txt = text
  27.         net.Start("PlayerSaidSomethin")
  28.             net.WriteTable(SayData)
  29.         net.Broadcast() -- Tell erryone
  30.     end)
  31. end
  32.  
  33. if CLIENT then 
  34.     surface.CreateFont( "Overhead_Msg", {
  35.     font = "Arial",
  36.     size = 30,
  37.     weight = 500,
  38.     antialias = true,
  39. } )
  40.     surface.CreateFont( "Overhead_Name", {
  41.     font = "Arial",
  42.     size = 32,
  43.     weight = 650,
  44.     antialias = true,
  45. } )
  46.    
  47.     local function PlayerColor(ply)
  48.         if isTTT then
  49.             local role = ply:GetRole()
  50.             if role == ROLE_TRAITOR and LocalPlayer:GetRole() == ROLE_TRAITOR then
  51.                 plyColor = Color(255,0,0,255)
  52.             elseif role == ROLE_INNOCENT then
  53.                 plyColor = Color(0,255,0,255)
  54.             elseif role == ROLE_DETECTIVE then
  55.                 plyColor = Color(0,0,255,255)
  56.             else
  57.                 plyColor = Color(0,255,0,255)
  58.             end
  59.             return
  60.         elseif isSandbox or isDarkRP then
  61.             plyColor = ply:GetPlayerColor( ) or Color(25, 200, 25, 255)
  62.             return
  63.         --elseif isCustomGamemode then
  64.             --plyColor = YourColorGettingmethod
  65.             --return
  66.         end
  67.     end
  68.  
  69.     local MsgTable = {}
  70.     local Recieved = false
  71.     net.Receive( "PlayerSaidSomethin", function( len, ply )
  72.         -- Destroy duplicate messages
  73.         if Recieved then return else Recieved = true timer.Simple(0.5, function() Recieved = false end) end
  74.        
  75.         local Data = net.ReadTable()
  76.         local ply = Data.ply
  77.         local msg = Data.txt
  78.         msg = string.Trim(msg) -- Trimming whitespace is a good idea
  79.         table.insert(MsgTable, 1, msg)
  80.        
  81.         PlayerColor(ply)
  82.        
  83.         if #MsgTable > maxMessages then -- To prevent the a tower of messages
  84.             table.remove( MsgTable, #MsgTable ) -- Remove the last key/oldest message
  85.         end
  86.        
  87.         if timer.Exists(ply:UniqueID().."_ChatMessage") then -- If chat is already displaying
  88.             local tleft = timer.TimeLeft(ply:UniqueID().."_ChatMessage")
  89.             timer.Adjust( ply:UniqueID().."_ChatMessage", tleft + 3, 1, function() -- Adjust it
  90.                 hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
  91.                 table.Empty(MsgTable)
  92.             end)
  93.         end
  94.        
  95.         hook.Add( "PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage", function()  
  96.             if ply == LocalPlayer() and not plyCanSeeOwnMsg then return end
  97.             if not ply:Alive() then return end
  98.            
  99.             if #MsgTable < 1 then -- No messages
  100.                 timer.Simple(0.5, function() -- Delay for effect
  101.                     hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
  102.                     table.Empty(MsgTable)
  103.                 end)
  104.             end
  105.             local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
  106.             local BonePos, BoneAng = ply:GetBonePosition( BoneIndx )
  107.             local pos = BonePos + Vector(0,0,80) -- Place above head bone
  108.             local eyeang = LocalPlayer():EyeAngles().y - 90 -- Face upwards
  109.             local ang = Angle( 0, eyeang, 90 )
  110.            
  111.             -- Start drawing
  112.             cam.Start3D2D(pos, ang, 0.1)
  113.                 local Height = 255
  114.                 local Width = 2
  115.                 local Buffer = 30
  116.                
  117.                 -- Background
  118.                 surface.SetDrawColor( 255, 255, 255, 100 )
  119.                 surface.DrawRect(0-(Width/2), 600, Width, Height )
  120.                 surface.DrawRect(0-(Height/2), 600, Height, Width )
  121.                
  122.                 for k, v in pairs(MsgTable) do
  123.                     if string.len(v) > maxLength then
  124.                         -- Prevent long messages from appearing, they will be in chat so all is good
  125.                         v = "[Message Omitted - Length]"
  126.                     end
  127.                     -- Draw the message
  128.                     draw.DrawText( v, "Overhead_Msg", 0+2, 600-Buffer+2, textShadowColor, TEXT_ALIGN_CENTER )
  129.                     draw.DrawText( v, "Overhead_Msg", 0, 600-Buffer, textColor, TEXT_ALIGN_CENTER )
  130.                     Buffer = Buffer + 30 -- Increase buffer by initial value
  131.                 end
  132.                
  133.                 draw.DrawText( ply:Nick()..":", "Overhead_Name", 0+2, 600-Buffer+2, plyShadowColor, TEXT_ALIGN_CENTER )
  134.                 draw.DrawText( ply:Nick()..":", "Overhead_Name", 0, 600-Buffer, plyColor, TEXT_ALIGN_CENTER )
  135.             cam.End3D2D()
  136.         end)
  137.        
  138.         timer.Create(ply:UniqueID().."_OldChatRemover", 5, #MsgTable, function()
  139.             -- Removes the oldest message, one element at a time.
  140.             table.remove( MsgTable, #MsgTable )
  141.         end)
  142.         timer.Create(ply:UniqueID().."_ChatTimer", (#MsgTable*5)+6, 1, function()
  143.             -- Removes the actual Hook when its not needed anymore
  144.             hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
  145.             table.Empty(MsgTable)
  146.         end)
  147.     end)
  148. end
Advertisement
Add Comment
Please, Sign In to add comment