I have a config which has a table in it (RSoundNames) and I am creating a DComboBox with all the contents in the table as choices for the combobox. How do I do that. Heres what I got:
ERROR :
bad argument #1 to 'pairs' (table expected, got nil)
- I am running this in client in net.Receive()
I am trying to make it where when someone types /sound it opens a menu and they can press a sound that they added in the config then play it for every player. Here is the code :
CONFIG :
sound.Add( {
name = "Snare_Sound",
volume = 1.0,
sound = "snaresound.wav"
} )
-----------------------------------------------------------------------------------------------
-- SOUND NAMES --
RSoundNames = {
"Snare_Sound"
}
SERVER :
AddCSLuaFile("cl_alert.lua")
AddCSLuaFile("sh_config.lua")
include("sh_config.lua")
util.AddNetworkString("ROpenSound")
util.AddNetworkString("REmitSound")
util.AddNetworkString("RFinalSound")
hook.Add("PlayerSay", "ROpenSoundMenu", function(ply, text, team, public)
text = string.lower(text)
if text == "/sound" then
net.Start("ROpenSound")
net.Send(ply)
end
end)
net.Receive("REmitSound", function()
for k,v in pairs(player.GetAll()) do
net.Start("RFinalSound")
net.Send(v)
end
end)
CLIENT :
include("sh_config.lua")
net.Receive("ROpenSound", function()
local frame = vgui.Create("DFrame")
frame:SetPos(ScrW()/2 - 100, ScrH()/2 - 150)
frame:SetSize(200, 300)
frame:ShowCloseButton(true)
frame:SetDraggable(true)
frame:MakePopup()
local cbox = vgui.Create("DComboBox", frame)
cbox:SetPos(100, 150)
cbox:SetSize(120, 30)
cbox:SetValue("Select Sound")
for k,v in pairs(RSoundNames) do
cbox:AddChoice(v)
end
cbox.OnSelect = function(panel, index, value)
print(value .. " was Selected!")
end
local rb = vgui.Create("DButton", frame)
rb:SetPos(100, 200)
rb:SetSize(100, 100)
rb:SetText("")
rb.DoClick = function()
if value != "Select Sound" then
if value != "" then
net.Start("REmitSound")
net.SendToServer()
end
end
end
end)
net.Receive("RFinalSound", function()
LocalPlayer():EmitSound(value)
end)
I hate to put up all my code but I seriously cant find the problem.