Ok so i'm trying to make a script that plays a sound when someone enters the name of it in the chat.
[CODE]
alE = file.Find(("sound/*.ogg"), "GAME")
hook.Add([[Initialize]], [[findSounds]], function()
file.Write("soundlist.txt", table.concat(alE, "\n"))
end)
function checkText(ply, text, tc, alE)
if (file.Exists("sound", "GAME") == true) then
for k, v in ipairs(alE) do
if text == v then
return text
end
end
end
sound.Play(([[garrysmod/sound/]]..text), ply:GetPos())
end
hook.Add("PlayerSay", "soundSystem", checkText)
[/CODE]
I'm trying to make it check to see if the text the user entered is one of the sounds. And if it is, it takes that string and plays it from the directory.
But I get this:
[CODE]
[ERROR] lua/autorun/esounds.lua:13: bad argument #1 to 'ipairs' (table expected,
1. ipairs - [C]:-1
2. fn - lua/autorun/esounds.lua:13
3. unknown - addons/ulib-master/lua/ulib/shared/hook.lua:109
[/CODE]
And I have another script that makes a console command that shows all the sounds:
[CODE]
alE = file.Find(("sound/*.ogg"), "GAME")
function seeEmotes()
reg_alE = table.concat(alE, "\n")
MsgN(reg_alE)
end
concommand.Add("emote_list", seeEmotes)
[/CODE]
But I just get this:
[CODE]
1048attack.ogg
1048special.ogg
Alarm2.ogg
[/CODE]
Which are not the right sounds... The folder is in the "garrysmod" directory called sound, so I am not really sure why it's not going there.
And I am not really sure why it says it's expecting a table with ipairs when alE is a table...
Don't redefine alE as a function parameter for checkText().
[QUOTE=go4040;52887583]Don't redefine alE as a function parameter for checkText().[/QUOTE]
Thanks. It works now, but I have no idea where the table is getting those sounds.
Could it just be getting them from the client instead of the server or something?
Sorry, you need to Log In to post a reply to this thread.