Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not SERVER then return end
- local table = table
- local string = string
- local hook = hook
- module "chatcommand"
- -- Settings
- Blocking = false
- PrefixPrivate = "/"
- PrefixPublic = "!"
- local _commands = {}
- function Add( name, func )
- _commands[name:lower()] = func
- end
- function Remove( name )
- _commands[name:lower()] = nil
- end
- function Run( player, command, arguments )
- local func = _commands[command:lower()]
- if not func then
- if player:IsValid() and Blocking == true then
- player:ChatPrint( "Unknown command: '" .. command .. "'\n" )
- end
- return false
- end
- func( player, command, arguments )
- return true
- end
- local function ParseChat( player, text, team )
- local txt = text
- local prefix = txt:sub( 1,1 )
- if prefix ~= PrefixPublic and prefix ~= PrefixPrivate then return end
- local cmd
- txt = txt:gsub( "^.(%S+)", function( match )
- cmd = match
- return ""
- end, 1 )
- if not cmd or not txt or cmd == txt then return "" end
- -- This chunk of code is from Lexi, thanks :3
- -- http://www.facepunch.com/showthread.php?t=827179
- local quote = txt:sub( 1, 1 ) ~= '"'
- local ret = {}
- for chunk in txt:gmatch( '[^"]+' ) do
- quote = not quote
- if quote then
- table.insert( ret, chunk )
- else
- for chunk in chunk:gmatch( "%S+" ) do
- table.insert( ret, chunk )
- end
- end
- end
- local exists = Run( player, cmd, ret )
- return (exists or Blocking) and ((prefix == PrefixPublic) and text or "") or text
- end
- hook.Add( "PlayerSay", "ChatCommand.ParseChat", ParseChat )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement