Ok so i’m trying to make a script that plays a sound when someone enters the name of it in the chat.
alE = file.Find(("sound/*.ogg"), "GAME")
hook.Add([[Initialize]], [[findSounds]], function()
file.Write("soundlist.txt", table.concat(alE, "
"))
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)
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:
[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
And I have another script that makes a console command that shows all the sounds:
alE = file.Find(("sound/*.ogg"), "GAME")
function seeEmotes()
reg_alE = table.concat(alE, "
")
MsgN(reg_alE)
end
concommand.Add("emote_list", seeEmotes)
But I just get this:
1048attack.ogg
1048special.ogg
Alarm2.ogg
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…