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 :
[CODE]
bad argument #1 to 'pairs' (table expected, got nil)
[/CODE]
+ 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 :
[CODE]
sound.Add( {
name = "Snare_Sound",
volume = 1.0,
sound = "snaresound.wav"
} )
-----------------------------------------------------------------------------------------------
-- SOUND NAMES --
RSoundNames = {
"Snare_Sound"
}
[/CODE]
SERVER :
[CODE]
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)
[/CODE]
CLIENT :
[CODE]
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)
[/CODE]
I hate to put up all my code but I seriously cant find the problem.
print(RSoundNames) ?
[QUOTE=Pypsikan;52574149]print(RSoundNames) ?[/QUOTE]
Im confused lol
[QUOTE=ZeroToHero;52574160]Im confused lol[/QUOTE]
Make print on client and give me result.
If I do this :
[CODE]
local cbox = vgui.Create("DComboBox", frame)
cbox:SetPos(100, 150)
cbox:SetSize(120, 30)
cbox:SetValue("Select Sound")
print(RSoundNames)
cbox.OnSelect = function(panel, index, value)
print(value .. " was Selected!")
end
[/CODE]
It prints "nil"
Table not passed to the client :buckteeth:
[editline]15th August 2017[/editline]
you write addon or gamemode?
if addon then put your sh_config in %name_addon%/lua/autorun
cl_alert.lua in %name_addon%/lua/autorun/client
sv_alert.lua in %name_addon%/lua/autorun/server
remove include and AddCSLuaFile
This should help
Still getting the error
Sorry, you need to Log In to post a reply to this thread.