Don't like ads? PRO users don't see any ads ;-)
Guest

lolz

By: a guest on Jul 15th, 2012  |  syntax: Lua  |  size: 12.86 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. surface.CreateFont("Tahoma", 14, 1000, true, false, "PEChatFont")
  3.  
  4. local IsTeamChat = false;
  5. local IsChatOn = false;
  6. local ChatLog = {};
  7. local LinesToShow = 10;
  8. local CurrentText = "";
  9.  
  10. local ChatColors_PrintMessage = Color(75, 255, 75, 255);
  11. local ChatColors_Normal = Color(255, 100, 100, 255);
  12. local ChatColors_OffServer = Color(150, 100, 255, 255);
  13. local ChatColors_LocalChat = Color(200, 200, 200, 255);
  14. local ChatColors_YourLocalChat = Color(255, 255, 255, 255);
  15. local ChatColors_YourTalk = Color(255, 150, 150, 255);
  16. local ChatColors_ServerBroadcast = Color(255, 0, 0, 255);
  17. local ConsoleColor = Color(255, 51, 255);
  18.  
  19. local function AddMessage ( FromText, FromColor, Message, Type, Admin, SuperAdmin, Owner )
  20.         if string.find(Message, "Kicked by Console") then return false; end
  21.         if string.find(Message, "RETSASIRHC") or string.find(Message, "@@@@@@@") then return false; end
  22.         if string.find(Message, "MINGEBAGS ARE TAKING OVER GMOD") then return false; end
  23.        
  24.         if string.find(Message, "left the game") then
  25.                 local UserName = string.Explode(Message, " ")[2];
  26.                
  27.                 if !UserName or UserName == "" then return false; end
  28.                
  29.                 Message = UserName .. " has left the game.";
  30.         end
  31.        
  32.         if string.find(Message, "joined the game") then Message = Message .. "."; end
  33.        
  34.         if FromText != '' then
  35.                 Msg(FromText .. ": " .. Message .. "\n");
  36.         else
  37.                 Msg(Message .. "\n");
  38.         end
  39.        
  40.         if (Type == 1 or Type == 0 or Type == 4 or Type == 5) and string.len(FromText) > 20 then
  41.                 FromText = string.sub(FromText, 1, 18) .. "...";
  42.         end
  43.  
  44.         local FormTable = {};
  45.        
  46.         FormTable.DrawColor = ChatColors_Normal;
  47.        
  48.         if Type == 1 then
  49.                 FormTable.DrawColor = ChatColors_YourTalk;
  50.         elseif Type == 2 then
  51.                 FormTable.DrawColor = ChatColors_PrintMessage;
  52.         elseif Type == 3 then
  53.                 FormTable.DrawColor = ChatColors_OffServer;
  54.         elseif Type == 4 then
  55.                 FormTable.DrawColor = ChatColors_LocalChat;
  56.         elseif Type == 5 then
  57.                 FormTable.DrawColor = ChatColors_YourLocalChat;
  58.         elseif Type == 6 then
  59.                 FormTable.DrawColor = ChatColors_ServerBroadcast;
  60.         end
  61.        
  62.         if Admin then
  63.                 FormTable.IsAdmin = true;
  64.         end
  65.                        
  66.         if SuperAdmin then
  67.                 FormTable.IsSuperAdmin = true;
  68.         end
  69.        
  70.         if Owner then
  71.                 FormTable.IsOwner = true;
  72.         end
  73.        
  74.         FormTable.FromText = string.Trim(tostring(FromText));
  75.         FormTable.FromColor = FromColor;
  76.         FormTable.Message = Message;
  77.         FormTable.Time = CurTime();
  78.        
  79.         table.insert(ChatLog, FormTable);
  80. end
  81.  
  82. local CustomChatColors = {};
  83. function AddCustomChatID ( ID, Color2 )
  84.         CustomChatColors[ID] = {};
  85.         CustomChatColors[ID].TextColor = Color2;
  86. end
  87.  
  88. local function GetCustomChat ( UMsg )
  89.         local Player = UMsg:ReadEntity()
  90.         local Text = UMsg:ReadString();
  91.         local SetupID = UMsg:ReadShort();
  92.        
  93.         if Text == '' or Text == ' ' or Text == '   ' then return false; end
  94.        
  95.         local FormTable = {};
  96.         local Suffix;
  97.         if !Player or !Player:IsValid() or !Player:IsPlayer() then
  98.                 Suffix = ''
  99.         else
  100.                 FormTable.FromColor = team.GetColor(Player:Team());
  101.                 Suffix = Player:Nick();
  102.                
  103.                 if Player:GetNetworkedBool('duty', false) then
  104.                         if Player:IsAdmin() then
  105.                                 FormTable.IsAdmin = true;
  106.                         end
  107.                        
  108.                         if Player:IsSuperAdmin() then
  109.                                 FormTable.IsSuperAdmin = true;
  110.                         end
  111.                        
  112.                         if Player:IsOwner() then
  113.                                 FormTable.IsOwner = true;
  114.                         end
  115.                 end
  116.         end
  117.                
  118.         if !CustomChatColors[SetupID] then Msg('CUSTOM CHAT COLOR ID ' .. SetupID .. ' NOT FOUND.\n'); end
  119.        
  120.         FormTable.FromText = Suffix;
  121.         FormTable.Message = Text;
  122.         FormTable.DrawColor = CustomChatColors[SetupID].TextColor;
  123.         FormTable.Time = CurTime();
  124.        
  125.         if Suffix != '' then
  126.                 Msg(Suffix .. ": " .. Text .. "\n");
  127.         else
  128.                 Msg(Text .. "\n");
  129.         end
  130.        
  131.         table.insert(ChatLog, FormTable);
  132.        
  133.         surface.PlaySound(Sound('common/talk.wav'));
  134. end
  135. usermessage.Hook('PE_CUSTOMCHAT', GetCustomChat);
  136.  
  137. local function GetLocalChat ( UMsg )
  138.         local Player = UMsg:ReadEntity();
  139.         local Text = UMsg:ReadString();
  140.                
  141.         local MessageType = 4;
  142.        
  143.         surface.PlaySound(Sound('common/talk.wav'));
  144.  
  145.         if Player == LocalPlayer() then MessageType = 5; end
  146.                
  147.         if Player and Player:IsValid() then
  148.                 AddMessage(Player:Name(), team.GetColor(Player:Team()), Text, MessageType, Player:IsAdmin(), Player:IsSuperAdmin(), Player:IsOwner());
  149.         end
  150. end
  151. usermessage.Hook('PE_LOCALCHAT', GetLocalChat);
  152.  
  153. local function GetGlobalChat ( UMsg )
  154.         local Player = UMsg:ReadEntity();
  155.         local Text = UMsg:ReadString();
  156.                
  157.         local MessageType = 0;
  158.        
  159.         surface.PlaySound(Sound('common/talk.wav'));
  160.  
  161.         if Player == LocalPlayer() then MessageType = 1; end
  162.                
  163.         if Player and Player:IsValid() then
  164.                 AddMessage(Player:Name(), team.GetColor(Player:Team()), Text, MessageType);
  165.         end
  166. end
  167. usermessage.Hook('PE_GLOBALCHAT', GetGlobalChat);
  168.  
  169. local function GetOffServerChat ( UMsg )
  170.         local PlayerName = UMsg:ReadString();
  171.         local Text = UMsg:ReadString();
  172.         local ServerName = UMsg:ReadString();
  173.        
  174.         surface.PlaySound(Sound('common/talk.wav'));
  175.        
  176.         if ServerName == "SVRBRD" then
  177.                 AddMessage("", Color(255, 255, 255, 255), Text, 6);
  178.         else
  179.                 local MessageType = 3;
  180.                        
  181.                 if string.len(PlayerName) > 10 then
  182.                         PlayerName = string.sub(PlayerName, 1, 8) .. "...";
  183.                 end
  184.                        
  185.                 AddMessage(PlayerName .. " [ " .. ServerName .. " ]", Color(255, 255, 255, 255), Text, MessageType);
  186.         end
  187. end
  188. usermessage.Hook('PE_OFFSERVER_CHAT', GetOffServerChat);
  189.  
  190. local function AddChatPaintInit ( Player )
  191.         function GAMEMODE:ChatText ( PlayerIndex, PlayerName, Text, MessageType )
  192.                 if tonumber(PlayerIndex) == 0 then
  193.                         //if MessageType == 'none' then
  194.                                 AddMessage('', ConsoleColor, Text, 2);
  195.                         //else
  196.                         //      AddMessage("Console", ConsoleColor, Text, 0);
  197.                         //end
  198.                 else
  199.                         return false;
  200.                 end
  201.         end
  202.  
  203.         function GAMEMODE.ChatPaint ( )
  204.                 if GAMEMODE.RestrictChatting then return false; end
  205.                
  206.                 local x, y = 160, math.Round(ScrH() - (ScrH() * .25));
  207.                
  208.                 if GAMEMODE.HighChat then
  209.                         y = math.Round(ScrH() - (ScrH() * .35));
  210.                 end
  211.                
  212.                 local Number = 0;
  213.                 local Total = 0;
  214.                
  215.                 local Cos = math.abs(math.sin(CurTime() * 2));
  216.                
  217.                 for k, v in pairs(ChatLog) do
  218.                         if (v.Time + 15 > CurTime() or IsChatOn) and k > #ChatLog - LinesToShow then
  219.                                 Total = Total + 1
  220.                         end
  221.                 end
  222.                
  223.                 for k, v in pairs(ChatLog) do
  224.  
  225.                         if (v.Time + 15 > CurTime() or IsChatOn) and k > #ChatLog - LinesToShow then   
  226.                                 local Alpha = 255;
  227.                                
  228.                                 if !IsChatOn and v.Time + 10 < CurTime() then
  229.                                         local TimeLeft = v.Time + 15 - CurTime();
  230.                                        
  231.                                         Alpha = (255 / 5) * TimeLeft;
  232.                                 end
  233.                                
  234.                                 if v.FromText != '' then                                       
  235.                                         if v.FromColor.r == 0 and v.FromColor.g == 0 and v.FromColor.b == 0 then
  236.                                                 draw.SimpleText(v.FromText .. ": ", "PEChatFont", x + 1, y - Total * 15 + Number * 15 + 1, Color(255, 255, 255, Alpha), 2);
  237.                                         else
  238.                                                 draw.SimpleText(v.FromText .. ": ", "PEChatFont", x + 1, y - Total * 15 + Number * 15 + 1, Color(0, 0, 0, Alpha), 2);
  239.                                         end
  240.                                        
  241.                                         if v.IsOwner then
  242.                                                 draw.SimpleTextOutlined(v.FromText .. ": ", "PEChatFont", x, y - Total * 15 + Number * 15, Color(v.FromColor.r, v.FromColor.g, v.FromColor.b, Alpha), 2, 0, 1, Color(255 * Cos, 0, 0, math.Clamp(Alpha * Cos, 0, 255)));
  243.                                         elseif v.IsSuperAdmin then
  244.                                                 draw.SimpleTextOutlined(v.FromText .. ": ", "PEChatFont", x, y - Total * 15 + Number * 15, Color(v.FromColor.r, v.FromColor.g, v.FromColor.b, Alpha), 2, 0, 1, Color(0, 255 * Cos, 0, math.Clamp(Alpha * Cos, 0, 255)));
  245.                                         elseif v.IsAdmin then
  246.                                                 draw.SimpleTextOutlined(v.FromText .. ": ", "PEChatFont", x, y - Total * 15 + Number * 15, Color(v.FromColor.r, v.FromColor.g, v.FromColor.b, Alpha), 2, 0, 1, Color(0, 0, 255 * Cos, math.Clamp(Alpha * Cos, 0, 255)));
  247.                                         else
  248.                                                 draw.SimpleText(v.FromText .. ": ", "PEChatFont", x, y - Total * 15 + Number * 15, Color(v.FromColor.r, v.FromColor.g, v.FromColor.b, Alpha), 2);
  249.                                         end
  250.                                 end
  251.  
  252.                                 draw.SimpleText(v.Message, "PEChatFont", x + 1, y - Total * 15 + Number * 15 + 1, Color(0, 0, 0, Alpha));
  253.                                 draw.SimpleText(v.Message, "PEChatFont", x, y - Total * 15 + Number * 15, Color(v.DrawColor.r, v.DrawColor.g, v.DrawColor.b, Alpha));
  254.  
  255.                                 Number = Number + 1
  256.                         end
  257.                 end
  258.                
  259.                 if IsChatOn then
  260.                         local Prefix = "Local: ";
  261.                         local Suffix = CurrentText .. ' ';
  262.                        
  263.                         if string.find(CurrentText, "!") == 1 or string.find(CurrentText, "/") == 1 then
  264.                                 if GAMEMODE.Name == 'PERP' then
  265.                                         if string.find(CurrentText, "///") == 1 then
  266.                                                 Prefix = "Local OOC: ";
  267.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-3);
  268.                                         elseif string.find(CurrentText, "/citizenradio") == 1 then
  269.                                                 Prefix = "Citizen Radio: ";
  270.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-13);
  271.                                         elseif string.find(CurrentText, "//") == 1 then
  272.                                                 Prefix = "OOC: ";
  273.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-2);
  274.                                         elseif string.find(CurrentText, "/ooc") == 1 then
  275.                                                 Prefix = "OOC: ";
  276.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-4);
  277.                                         elseif string.find(CurrentText, "/looc") == 1 then
  278.                                                 Prefix = "Local OOC: ";
  279.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-5);
  280.                                         elseif string.find(CurrentText, "/whisper") == 1 then
  281.                                                 Prefix = "Whisper: ";
  282.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-8);
  283.                                         elseif string.find(CurrentText, "/warrant") == 1 then
  284.                                                 Prefix = "Warrant: ";
  285.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-8);
  286.                                         elseif string.find(CurrentText, "/yell") == 1 then
  287.                                                 Prefix = "Yell: ";
  288.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-5);
  289.                                         elseif string.find(CurrentText, "/y") == 1 then
  290.                                                 Prefix = "Yell: ";
  291.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-2);
  292.                                         elseif string.find(CurrentText, "/pm") == 1 then
  293.                                                 Prefix = "Private Message: ";
  294.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-3);
  295.                                         elseif string.find(CurrentText, "/radio") == 1 then
  296.                                                 Prefix = "Police Radio: ";
  297.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-6);
  298.                                         elseif string.find(CurrentText, "/report") == 1 then
  299.                                                 Prefix = "[Report]: ";
  300.                                                 //Suffix = string.Right(Suffix, string.len(Suffix)-6);
  301.                                         elseif string.find(CurrentText, "/reply") == 1 then
  302.                                                 Prefix = "Reply to PM: ";
  303.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-6);
  304.                                         elseif string.find(CurrentText, "/me") == 1 then
  305.                                                 Prefix = "Action: ";
  306.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-3);
  307.                                         elseif string.find(CurrentText, "/advert") == 1 then
  308.                                                 Prefix = "Advert: ";
  309.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-7);
  310.                                         elseif string.find(CurrentText, "/broadcast") == 1 then
  311.                                                 Prefix = "Broadcast: ";
  312.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-10);
  313.                                         elseif string.find(CurrentText, "/broad") == 1 then
  314.                                                 Prefix = "Broadcast: ";
  315.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-6);
  316.                                         elseif string.find(CurrentText, "/organization") == 1 then
  317.                                                 Prefix = "Organization: ";
  318.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-13);
  319.                                         elseif string.find(CurrentText, "/org") == 1 then
  320.                                                 Prefix = "Organization: ";
  321.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-4);
  322.                                         elseif string.find(CurrentText, "/911") == 1 or string.find(CurrentText, "/999") == 1 or string.find(CurrentText, "/000") == 1 or string.find(CurrentText, "/112") == 1 then
  323.                                                 Prefix = "Emergency Call: ";
  324.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-4);
  325.                                         else
  326.                                                 Prefix = "Command: ";
  327.                                                 Suffix = string.Right(Suffix, string.len(Suffix)-1);
  328.                                         end
  329.                                 else
  330.                                         Prefix = "Command: ";
  331.                                         Suffix = string.Right(Suffix, string.len(Suffix)-1);
  332.                                 end
  333.                         elseif IsTeamChat then
  334.                                 Prefix = "Organization: ";
  335.                                 Suffix = string.Right(Suffix, string.len(Suffix)-4);
  336.                         end
  337.                        
  338.                         surface.SetFont("PEChatFont");
  339.                         local w, h = surface.GetTextSize(Prefix .. string.sub(Suffix, 0, string.len(Suffix)-1))
  340.                        
  341.                         draw.RoundedBox(4, x - 5, y + 5, w + 14, h + 1, Color(255, 255, 255, 150))
  342.                        
  343.                         surface.SetTextColor(0, 0, 0, 150)
  344.                         surface.SetTextPos(x + 2, y + 5);
  345.                         surface.DrawText(Prefix .. Suffix);
  346.                        
  347.                         if (math.sin(CurTime() * 5) * 10) > 0 then
  348.                                 surface.SetTextPos(x + w + 1, y + 5)
  349.                                 surface.DrawText('|');
  350.                         end
  351.                 end
  352.         end
  353.         hook.Add("HUDPaint", "ZZGM.ChatPaint", GAMEMODE.ChatPaint);
  354.  
  355.         function GAMEMODE:StartChat()
  356.                 if !GAMEMODE.RestrictChatting then
  357.                         IsChatOn = true;
  358.                 end
  359.                
  360.                 return true;
  361.         end
  362.        
  363.         function GAMEMODE:FinishChat()
  364.                 if !GAMEMODE.RestrictChatting then
  365.                         IsChatOn = false;
  366.                         IsTeamChat = false;
  367.                         CurrentText = "";
  368.                 end
  369.         end
  370.        
  371.         function GAMEMODE:ChatTextChanged ( Text ) CurrentText = Text; end
  372.        
  373.         function GAMEMODE.StartTeamChat ( Player, Bind )
  374.                 if string.find(Bind, "messagemode2") and !GAMEMODE.RestrictChatting then
  375.                         IsTeamChat = true;
  376.                 end
  377.         end
  378.         hook.Add("PlayerBindPress", "GM.StartTeamChat", GAMEMODE.StartTeamChat)
  379.        
  380.         /*
  381.         function HideShitbox ( What )
  382.                 if What == "CHudChat" then
  383.                         return false;
  384.                 end
  385.         end
  386.         hook.Add("HUDShouldDraw", "HideShitbox", HideShitbox)
  387.         */
  388. end
  389. hook.Add("Initialize", "GAMEMODE.AddChatPaintInit", AddChatPaintInit);