That would be a great feature to have!
I did a very quick research and found this:
ChatCommands = {} -- Create the table to store the commands.
function AddChatCommand(cmd, callback)
for k,v in pairs(ChatCommands) do
if cmd == v.cmd then return end -- If it already exists then don't add another.
end
table.insert(ChatCommands, {cmd = cmd, callback = callback}) -- Add to the table.
end
function ChatCommandSay(ply, text)
-- Loop through the table of chat commands.
for k, v in pairs(ChatCommands) do
if string.lower(v.cmd) == string.Explode(" ", string.lower(text))[1] then
return v.callback(ply, "" .. string.sub(text, string.len(v.cmd) + 2,
string.len(text)))
end
end
end
hook.Add("PlayerSay", "ChatCommandSay", ChatCommandSay)
function PlayTheSound(ply, args)
local Sound = Sound("weapons/mortar/mortar_shell_incomming1.wav") -- This is
the sound to play.
ply:ConCommand("play " .. Sound)
return ""
end
AddChatCommand("/playsound", PlayTheSound)
source: http://www.facepunch.com/threads/836201 |