How to say (chat) commands with evolve?

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.

[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(“bettywhite.wav”) – This is the sound to play.

ply:ConCommand(“play " … Sound)
return “”
end
AddChatCommand(”!playsound", PlayTheSound)[/lua]

[lua ] tag your code [ /lua]

Your code is a mess lol, I’ll fix tomorrow tired now if no one fixes it before me :stuck_out_tongue: i bet there is always someone.

Thank you for editing this code for me! And btw, I got that code from another website. And sorry, I didn’t know about the [lua] part.

Also could you include where to put the .lua file when you are done? It is much appreciated by me, thanks so much for helping out a lil’ ol’ noob like me :D.

[lua]function ChatCommandSay(ply, text)
if string.find(string.lower(text), “bettywhite”) then – if they type hello bettywhite it will play or BeTtyWhite
ply:EmitSound(“bettywhite.wav”,500, 200)
end
end
hook.Add(“PlayerSay”, “ChatCommandSay”, ChatCommandSay)[/lua]

Goes in lua/autorun/server/sound.lua in the server files not client.

where do you put custom sounds in your server? I put them in my (server IP folder) > sound, but people are still saying when they join that they aren’t downloading the custom sounds. :confused:

I don’t think the code is the problem… because when I type in bettywhite it doesn’t work.

Did you add the custom sound as a resource? You need to “tell” the client to download the new file.

I didn’t, I am very new at this, an extreme noob if you will, where do you put the sounds in order to “tell” clients to download them?

Just add this line in your chat command file:
[lua]
Resource.AddSingleFile ( “sound/bettywhite.wav” )
[/lua]