Advertisement
captmicro

chat box era 2009

Dec 10th, 2012
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.02 KB | None | 0 0
  1. require("command")
  2. MDA_ChatBox = {}
  3. MDA_ChatBox.Font = "coolvetica"
  4. MDA_ChatBox.NewFont = "MDA_ChatBox"
  5. MDA_ChatBox.FontSize = 14
  6. MDA_ChatBox.ChatBoxSize = 0.15
  7. MDA_ChatBox.ChatBox = nil
  8. MDA_ChatBox.ChatQue = {}
  9. MDA_ChatBox.SpawnIcon = ""
  10. surface.CreateFont(MDA_ChatBox.Font, MDA_ChatBox.FontSize, 510, false, false, MDA_ChatBox.NewFont)
  11. surface.SetFont(MDA_ChatBox.NewFont)
  12. MDA_ChatBox.TextSizeX, MDA_ChatBox.TextSizeY = surface.GetTextSize("`~!@#$%^&*()_+1234567890-=qQwWeErRtTyYuUiIoOpP[{]}aAsSdDfFgGhHjJkKlL;:'\"zZxXcCvVbBnNmM,<.>/?")
  13. MDA_ChatBox.EntryDropColor = Color(0,124,210,255)
  14. local removeIDXs = {}
  15. function MDA_CreateChatBox()
  16.     local ChatBox = vgui.Create("DTextEntry")
  17.     ChatBox:SetPos(ScrW() * 0.05, ScrH() * 0.95)
  18.     ChatBox:SetSize(ScrW() * 0.35, 15)
  19.     MDA_ChatBox.ChatBox = ChatBox
  20. end
  21.  
  22. function MDA_StartChat(TeamSay)
  23.     if !ValidPanel(MDA_ChatBox.ChatEntry) then
  24.         MDA_CreateChatBox()
  25.     else
  26.         MDA_ChatBox.ChatBox:SetVisible(true)
  27.     end
  28.     gui.EnableScreenClicker(true)
  29.     return true
  30. end
  31. hook.Add("StartChat","MDA_StartChat",MDA_StartChat)
  32.  
  33. function MDA_FinishChat(TeamSay)
  34.     if ValidPanel(MDA_ChatBox.ChatBox) then
  35.         MDA_ChatBox.ChatBox:SetVisible(false)
  36.     end
  37.     gui.EnableScreenClicker(false)
  38. end
  39. hook.Add("FinishChat","MDA_FinishChat",MDA_FinishChat)
  40.  
  41. function MDA_ChatTextChanged(text)
  42.     MDA_ChatBox.ChatBox:SetText(text)
  43.     if string.Left(text,1) == "#" then
  44.         MDA_ChatBox.EntryDropColor = Color(255,0,0,255)
  45.     elseif string.Left(text,1) == "$" then
  46.         MDA_ChatBox.EntryDropColor = Color(255,140,0,255)
  47.     else
  48.         MDA_ChatBox.EntryDropColor = Color(0,124,210,255)
  49.     end
  50. end
  51. hook.Add("ChatTextChanged","MDA_ChatTextChanged",MDA_ChatTextChanged)
  52.  
  53. function MDA_ChatTextAddQue(ply, text, teamchat, alive)
  54.     if ply == LocalPlayer() and string.sub(text,1,9) == "#fontsize" then
  55.         MDA_ChatBox.FontSize = tonumber(string.sub(text,11))
  56.         RunConsoleCommand("gm_clearfonts")
  57.         command.ServerCommand("lua_run_cl surface.CreateFont(\""..MDA_ChatBox.Font.."\", "..MDA_ChatBox.FontSize..", 400, false, false, \"MDA_ChatBox\")\n")
  58.         surface.SetFont(MDA_ChatBox.NewFont)
  59.         MDA_ChatBox.TextSizeX, MDA_ChatBox.TextSizeY = surface.GetTextSize("`~!@#$%^&*()_+1234567890-=qQwWeErRtTyYuUiIoOpP[{]}aAsSdDfFgGhHjJkKlL;:'\"zZxXcCvVbBnNmM,<.>/?")
  60.     end
  61.     if ply == LocalPlayer() and string.sub(text,1,5) == "#font" then
  62.         MDA_ChatBox.Font = string.sub(text,7)
  63.         RunConsoleCommand("gm_clearfonts")
  64.         command.ServerCommand("lua_run_cl surface.CreateFont(\""..MDA_ChatBox.Font.."\", "..MDA_ChatBox.FontSize..", 400, false, false, \"MDA_ChatBox\")\n")
  65.         surface.SetFont(MDA_ChatBox.NewFont)
  66.         MDA_ChatBox.TextSizeX, MDA_ChatBox.TextSizeY = surface.GetTextSize("`~!@#$%^&*()_+1234567890-=qQwWeErRtTyYuUiIoOpP[{]}aAsSdDfFgGhHjJkKlL;:'\"zZxXcCvVbBnNmM,<.>/?")
  67.     end
  68.     if ply == LocalPlayer() and string.sub(text,1,5) == "#size" then
  69.         MDA_ChatBox.ChatBoxSize = tonumber(string.sub(text,7))
  70.     end
  71.     if ply == LocalPlayer() and string.Left(text,1) == "$" then
  72.         command.ServerCommand(string.sub(text,2).."\n")
  73.     end
  74.     table.insert(MDA_ChatBox.ChatQue, {CurTime(),ply,alive,teamchat,text,Color(255,255,255,255)})
  75. end
  76. hook.Add("OnPlayerChat","MDA_ChatTextAddQue",MDA_ChatTextAddQue)
  77.  
  78. function MDA_ChatBox_PlayerConnect(name, ip, sid)
  79.     local text = "Player "..name.." has joined the server. ["..ip..", "..sid.."]"
  80.     table.insert(MDA_ChatBox.ChatQue {CurTime(),"PlyConnect",text,Color(0,0,255,255)})
  81. end
  82. hook.Add("PlayerConnect", "MDA_ChatBox_PlayerConnect", MDA_ChatBox_PlayerConnect)
  83.  
  84. function MDA_ChatBox_Nofity_JoinLeave(ply, name, text, mtype)
  85.     if mtype == "joinleave" then
  86.         table.insert(MDA_ChatBox.ChatQue, {CurTime(),"PlyJoinLeave",text,Color(0,0,255,255)})
  87.     elseif mtype == "none" then
  88.         if string.sub(text,1,22) == "Generated Spawn Icon (" then
  89.             MDA_ChatBox.SpawnIcon = text
  90.             if string.sub(1,23) == "Generated Spawn Icon (0" then
  91.                 timer.Simple(0.4, function() MDA_ChatBox.SpawnIcon = "" end)
  92.             end
  93.         else
  94.             table.insert(MDA_ChatBox.ChatQue, {CurTime(),"Notify",text,Color(0,0,200,255)})
  95.         end
  96.     end
  97. end
  98. hook.Add("ChatText", "MDA_ChatBox_Nofity_JoinLeave", MDA_ChatBox_Nofity_JoinLeave)
  99.  
  100. function MDA_ChatBoxDraws()
  101.     local t_x, t_y, t_w, t_h
  102.     if ValidPanel(MDA_ChatBox.ChatBox) then
  103.         rt_x, rt_y = MDA_ChatBox.ChatBox:GetPos()
  104.         t_x, t_y = MDA_ChatBox.ChatBox:GetPos()
  105.         t_x = t_x + ScrW() * 0.004
  106.         t_y = t_y + ScrH() * 0.004
  107.         t_w, t_h = MDA_ChatBox.ChatBox:GetSize()
  108.         if MDA_ChatBox.ChatBox:IsVisible() then
  109.             draw.RoundedBox(4, t_x, t_y, t_w, t_h, MDA_ChatBox.EntryDropColor)
  110.             rt_x, rt_y = MDA_ChatBox.ChatBox:GetPos()
  111.             t_x, t_y = MDA_ChatBox.ChatBox:GetPos()
  112.             t_y = t_y - ScrW() * MDA_ChatBox.ChatBoxSize
  113.             surface.SetDrawColor(255, 0, 0, 255)
  114.             surface.DrawLine(t_x - 3, t_y, t_x - 3 + t_w + ScrW() * 0.004 + 2, t_y)
  115.             surface.DrawLine(t_x - 3, rt_y - 2, t_x - 3 + t_w + ScrW() * 0.004 + 2, rt_y - 2)
  116.             surface.DrawLine(t_x - 3 + t_w + ScrW() * 0.004 + 2, t_y, t_x-3 + t_w + ScrW() * 0.004 + 2, rt_y - 2)
  117.             surface.DrawLine(t_x - 3, t_y, t_x - 3, rt_y - 2)
  118.         end
  119.     end
  120.     --Actual chat
  121.     if ValidPanel(MDA_ChatBox.ChatBox) then
  122.         rt_x, rt_y = MDA_ChatBox.ChatBox:GetPos()
  123.         t_x, t_y = MDA_ChatBox.ChatBox:GetPos()
  124.         t_y = t_y - ScrW() * MDA_ChatBox.ChatBoxSize
  125.         removeIDXs = {}
  126.         for idx,info in pairs(MDA_ChatBox.ChatQue) do
  127.             if CurTime() <= info[1] + 4 then
  128.                 if pcall(function()
  129.                     surface.SetFont(MDA_ChatBox.NewFont)
  130.                     local namesizex, namesizey = surface.GetTextSize(info[2]:Nick()..": ")
  131.                     draw.DrawText(info[2]:Nick()..": ", MDA_ChatBox.NewFont, t_x, t_y + (MDA_ChatBox.TextSizeY * (idx - 1)), team.GetColor(info[2]:Team()), TEXT_ALIGN_LEFT)
  132.                     draw.DrawText(info[5], MDA_ChatBox.NewFont, t_x + namesizex, t_y + (MDA_ChatBox.TextSizeY * (idx - 1)), info[6], TEXT_ALIGN_LEFT) end)
  133.                 then
  134.                     --Do nothing
  135.                 else
  136.                     if info[2] == "PlyJoinLeave" then
  137.                         draw.DrawText(info[3], MDA_ChatBox.NewFont, t_x, t_y + (MDA_ChatBox.TextSizeY * (idx - 1)), info[4], TEXT_ALIGN_LEFT)
  138.                     elseif info[2] == "Notify" then
  139.                         draw.DrawText(info[3], MDA_ChatBox.NewFont, t_x, t_y + (MDA_ChatBox.TextSizeY * (idx - 1)), info[4], TEXT_ALIGN_LEFT)
  140.                     end
  141.                 end
  142.             else
  143.                 table.insert(removeIDXs, idx)
  144.             end
  145.             --print(-(t_y-rt_y-2),MDA_ChatBox.TextSizeY,math.floor(-(t_y-rt_y-2) / MDA_ChatBox.TextSizeY))
  146.             if idx == math.floor(-(t_y-rt_y-2) / MDA_ChatBox.TextSizeY) then
  147.                 table.remove(MDA_ChatBox.ChatQue, 1)
  148.             end
  149.             surface.SetDrawColor(255, 0, 0, 255)
  150.             surface.DrawLine(t_x - 3, t_y, t_x - 3 + t_w + ScrW() * 0.004 + 2, t_y)
  151.             surface.DrawLine(t_x - 3, rt_y - 2, t_x - 3 + t_w + ScrW() * 0.004 + 2, rt_y - 2)
  152.             surface.DrawLine(t_x - 3 + t_w + ScrW() * 0.004 + 2, t_y, t_x-3 + t_w + ScrW() * 0.004 + 2, rt_y - 2)
  153.             surface.DrawLine(t_x - 3, t_y, t_x - 3, rt_y - 2)
  154.         end
  155.         if MDA_ChatBox.SpawnIcon ~= "" then
  156.             draw.DrawText(MDA_ChatBox.SpawnIcon, MDA_ChatBox.NewFont, t_x, t_y - MDA_ChatBox.TextSizeY, Color(0,128,128,255), TEXT_ALIGN_LEFT)
  157.         end
  158.         for i,idxToRem in pairs(removeIDXs) do
  159.             table.remove(MDA_ChatBox.ChatQue, idxToRem)
  160.         end
  161.     end
  162. end
  163. hook.Add("HUDPaint","MDAChatBox",MDA_ChatBoxDraws)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement