Issue553

Title Lua Function to Play Sounds (and associated sounds)
Priority idea Status resolved
Assigned To Keywords
Linked issues Watchers

Submitted on 2011-12-06 07h30 by salimiles, last changed by jesusalva.

Messages
Author: salimiles Date: 2011-12-06   07h30
I think that it would be cool if we could have a set of sounds that we could use
in lua events.

So we could set it up so you step on a trap, and all of a sudden there is a gong
sound, followed by a number bots appearing all around you.

Or maybe a set of industrial sounds are triggered when you finally get the
AutoFactory working.
Author: matthiaskrgr Date: 2011-12-06   09h12
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
Author: jesusalva Date: 2016-01-05   17h31
This was included some time ago but this bug report was forgotten.
I'm closing it to reduce number of open bugs.
History
Date User Action Args
2016-01-05 17:31:13jesusalvasetstatus: open -> resolved
messages: + msg3298
2011-12-06 09:12:52matthiaskrgrsetmessages: + msg2099
2011-12-06 07:30:15salimilescreate