Advertisement
Guest User

Untitled

a guest
Mar 14th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. if not SERVER then return end
  2.  
  3. local table = table
  4. local string = string
  5. local hook = hook
  6.  
  7. module "chatcommand"
  8.  
  9. -- Settings
  10. Blocking        = false
  11. PrefixPrivate   = "/"
  12. PrefixPublic    = "!"
  13.  
  14. local _commands = {}
  15.  
  16. function Add( name, func )
  17.     _commands[name:lower()] = func
  18. end
  19.  
  20. function Remove( name )
  21.     _commands[name:lower()] = nil
  22. end
  23.  
  24. function Run( player, command, arguments )
  25.     local func = _commands[command:lower()]
  26.    
  27.     if not func then
  28.         if player:IsValid() and Blocking == true then
  29.             player:ChatPrint( "Unknown command: '" .. command .. "'\n" )
  30.         end
  31.         return false
  32.     end
  33.    
  34.     func( player, command, arguments )
  35.    
  36.     return true
  37. end
  38.  
  39. local function ParseChat( player, text, team )
  40.     local txt = text
  41.     local prefix = txt:sub( 1,1 )
  42.     if prefix ~= PrefixPublic and prefix ~= PrefixPrivate then return end
  43.  
  44.     local cmd
  45.     txt = txt:gsub( "^.(%S+)", function( match )
  46.         cmd = match
  47.         return ""
  48.     end, 1 )
  49.  
  50.     if not cmd or not txt or cmd == txt then return "" end
  51.    
  52.     -- This chunk of code is from Lexi, thanks :3
  53.     -- http://www.facepunch.com/showthread.php?t=827179
  54.     local quote = txt:sub( 1, 1 ) ~= '"'
  55.     local ret = {}
  56.     for chunk in txt:gmatch( '[^"]+' ) do
  57.         quote = not quote
  58.         if quote then
  59.             table.insert( ret, chunk )
  60.         else
  61.             for chunk in chunk:gmatch( "%S+" ) do
  62.                 table.insert( ret, chunk )
  63.             end
  64.         end
  65.     end
  66.    
  67.     local exists = Run( player, cmd, ret )
  68.    
  69.     return (exists or Blocking) and ((prefix == PrefixPublic) and text or "") or text
  70. end
  71. hook.Add( "PlayerSay", "ChatCommand.ParseChat", ParseChat )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement