I have this lua file in my server’s files (server IP and port) > lua > autorun > server
With this code…
[lua]
ChatCommands = {bettywhite} – 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(“bettywhite”, string.lower(text))[1] then
return v.callback(ply, “bettywhite” … 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(“69.197.190.77 port 27015/sound/bettywhite.wav”) – This is the sound to play.
ply:ConCommand("play " .. Sound)
return ""
end
AddChatCommand("!playsound", PlayTheSound)
You need to put that into your servers “autorun/lua/server/” folder, in a lua file name of your choice.
For example, “autorun/lua/server/SoundPlayer.lua” <- Code goes inside the lua file.
[/lua]
Now I almost have no idea what I am doing with lua. I am trying to get it so that when a player types in “bettywhite” in the chat bar that plays a sound called bettywhite.
I have the bettywhite sound in my (server IP and port)> sound file.
Thanks.