Advertisement
my_hat_stinks

Clipboard

May 6th, 2015
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. -- Simple net library usage example
  2. if SERVER then
  3.     util.AddNetworkString( "NetLibrary ChatExample" ) -- This is required server-side for every net message you use
  4.    
  5.     local function SendMessage( str, ply )
  6.         net.Start("NetLibrary ChatExample") -- Should match the AddNetworkString name
  7.             net.WriteString( str )
  8.         net.Send( ply ) -- This sends to a specific player. You can also use net.Broadcast() to send to everyone, or net.SendToServer() clientside to send to the server
  9.     end
  10. end
  11. if CLIENT then
  12.     local Col = {
  13.         Tag = Color(100,255,0), Text = Color(255,255,255),
  14.     }
  15.     Col.Tag.Glow = true -- Make the tag glow. Glow will be ignored by default chatbox
  16.     Col.Tag.GlowTarget = Color(100,0,255) -- Color it glows to (Optional, defaults to white)
  17.    
  18.     local Icon = "icon16/controller.png"
  19.     local Emote = "icon16/star.png"
  20.     net.Receive( "NetLibrary ChatExample", function(len) -- Again, should match other strings. function arguments are MessageLength, SendingPlayer (nil clientside)
  21.         local str = net.ReadString() -- Data should be read in the same order it was written
  22.         if not str or str=="" then return end
  23.        
  24.         chat.AddText(
  25.             HatsChat and {"LINEICON", Icon} or "", -- Badly coded custom chatboxes may error with a non-colour table, Default chatbox will just ignore it. This line only adds the table if HatsChat is installed
  26.             Col.Tag, "[MyAddon] ", -- Glowing colour with tag
  27.             HatsChat and {"EMOTE", mat=Material(Emote), str=":star:", size={16,16}, matpath=Emote} or "", -- Same again, this time with an emote
  28.             Col.Text, str -- Standard arguments
  29.         )
  30.     end)
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement