Hi,
I am very new to gmod lua and i have started to make an event addon where the whole server would get a notifcation about an event and they could then enter by typing !event in chat. Although right now i am having issues with listing the players in DListView. I want them to be able to be in that list so staff can press one button and TP them all to the event.
This is my current error.
[ERROR] lua/includes/modules/team.lua:174: attempt to call field 'Copy' (a nil value)
1. GetColor - lua/includes/modules/team.lua:174
2. v - gamemodes/darkrp/gamemode/modules/fspectate/sv_init.lua:149
3. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:139
my current code that seems to be causing this problem:
net.Receive("EnteredEvent",function()
local name = net.ReadString()
for i = 1,100 do
table = {}
table[1] = name
end
for k,v in pairs(table) do
net.Start("NameOfPersonn")
net.WriteTable(table)
net.Broadcast()
end end)
for some reason it says endend) on the forum, its not like that in my code fyi.
here you can see my clientside code that should have the players appear in the List.
net.Receive("NameOfPersonn", function()
namee = net.ReadTable()
print(namee)
end)
local AppList = vgui.Create( "DListView", dframe )
AppList:Dock( FILL )
AppList:SetMultiSelect( false )
AppList:AddColumn( "Name" )
AppList:AddColumn( "Event" )
AppList.OnRowSelected = function( lst, index, pnl )
AppList:AddLine( namee, "entered event" )
end
Any help would be greatly appreciated.
You're overriding the global 'table', and if you're only networking 1 name at a time you should use net.WriteString.
The first issue I can see without actually testing anything is that you're using the name table and you're also declaring it globally. This means you're overwriting the Table library which contains all of the functions regarding Lua tables.
My guess is that the error you're getting is because the function table.Copy() no longer exists since you overwrote table with a new empty object. To fix this, you should first use local to set the scope of the variable to the current block of code, and it's good practice to never use the names of existing global functions/variables/tables, so tbl and not table.
Lastly, you're creating a new table every iteration in the loop, I will assume this is unintentional. If you want to create a table of names, it would be something like this:
local eventtable = {} -- This creates a local table that will not get overwritten every time someone enters an event
net.Receive("EnteredEvent",function()
local name = net.ReadString() --reads the name of the person who entered the event
table.insert(eventtable, name) -- Adds the name of the person to the table
net.Start("NameOfPersonn")
net.WriteTable(eventtable)
net.Broadcast() -- Sends the table to all clients
end)
Clientside, you'll want to use PrintTable instead of print:
namee = net.ReadTable()
PrintTable(namee)
If you're new to Lua, you might find it helpful to have a read through the Lua Tutorials on the Garry's Mod Wiki.
Thanks alot, i think i did it. I just need to be testing some more with friends.
This is how my clientside code looks like now, the serverside is pretty much good.
local AppList = vgui.Create( "DListView", dframe )
AppList:Dock( FILL )
AppList:SetMultiSelect( false )
AppList:AddColumn( "Number" )
AppList:AddColumn( "Name" )
for k,v inpairs( namee ) do
AppList:AddLine( k, v )
end
AppList:AddLine( "Bot01", "testing")--for testing
AppList.OnRowSelected = function( lst, index, pnl )for k, v inpairs( namee ) do
RunConsoleCommand("say","/bring "..v)
endend
Sorry, you need to Log In to post a reply to this thread.