# Help with table ranomisation!

``````
_G[v[1].."_WINNER"] = {}
table.insert( _G[v[1].."_WINNER"], _G[v[1]][ math.random( _G[v[1]] ) ] )

if tostring(_G[v[1].."_WINNER"]):GetNWInt( v[1] ) != nil then
tostring(_G[v[1].."_WINNER"]):SetNWInt( v[1], 2 )
table.Empty( _G[v[1].."_WINNER"]) )
end

table.Empty( _G[v[1]] )

``````

That is a snip from my code. Firstly, table v[1] is defined properly, but the true problem is the table.insert I am just trying to define the winner from _G[ v[1] ] so I can give them a reward.

What is v[1] defined as? You should not have to store it in _G.

``````
LocalPlayer():SetNWInt( v[1], 1 )

if timer.Exists( v[1] ) then
else
timer.Create( v[1], (v[5] * 60), 1, function()

_G[v[1].."_WINNER"] = {}
table.insert( _G[v[1].."_WINNER"], _G[v[1]][ math.random( _G[v[1]] ) ] )

if tostring(_G[v[1].."_WINNER"]):GetNWInt( v[1] ) != nil then
tostring(_G[v[1].."_WINNER"]):SetNWInt( v[1], 2 )
table.Empty( _G[v[1].."_WINNER"]) )
end

table.Empty( _G[v[1]] )

``````

and the v[1] is

``````
for k,v in pairs( Items ) do
_G[v[1]] = {}

timer.Create( "refresh2", 0.1, 0, function()
if LocalPlayer():GetNWInt( tostring(v[1]) ) == 1 then
if table.HasValue( _G[v[1]], LocalPlayer() ) then
else
table.insert( _G[v[1]], LocalPlayer() )
end
end
end)

``````

[editline]11th February 2017[/editline]

``````
timer.Create( "refresh1", 0.1, 1, function()
for k,v in pairs( Items ) do
_G[v[1]] = {}

timer.Create( "refresh2", 0.1, 0, function()
if LocalPlayer():GetNWInt( tostring(v[1]) ) == 1 then
if table.HasValue( _G[v[1]], LocalPlayer() ) then
else
table.insert( _G[v[1]], LocalPlayer() )
end
end
end)

local ListItem = List:Add( "DPanel" )
ListItem:SetSize( 600, 100 )
ListItem.Paint = function()
draw.RoundedBox( 0, 0, 0, ListItem:GetWide(), ListItem:GetTall(), Color( 255, 100, 0, 255 ) )
draw.SimpleText( tostring(v[1]), "CreateButton", 2.5, 0, Color( 255, 255, 255, 255 ) )
draw.SimpleText( "Entered: "..table.Count( _G[v[1]]), "CreateButton", 450, 10, Color( 255, 255, 255, 255 ) )
if timer.Exists( v[1] ) then
draw.SimpleText( "Time Left: "..timer.TimeLeft( tostring(v[1]) ), "CreateButton", 2.5, 20, Color( 255, 255, 255, 255 ) )
end
draw.SimpleText( v[2], "GDescription", 2.5, 75, Color( 200, 200, 200, 255 ) )
end

local ItemImage = vgui.Create( "DImage", ListItem )
ItemImage:SetPos( 200, 0 )
ItemImage:SetSize( 250, 100 )
ItemImage:SetImage( v[4] )

local Enter = vgui.Create( "DButton", ListItem )
Enter:SetPos( 450, 50 )
Enter:SetSize( 100, 50 )
Enter:SetText( '' )
Enter.Paint = function()
if Enter:IsHovered() then
if LocalPlayer():GetNWInt( v[1] ) == 1 then
draw.RoundedBox( 0, 0, 0, Enter:GetWide(), Enter:GetTall(), Color( 255, 120, 0, 255 ) )
draw.SimpleText( "Entered!", "CreateButton", 15, 0, Color( 200, 200, 200, 255 ) )
else
draw.RoundedBox( 0, 0, 0, Enter:GetWide(), Enter:GetTall(), Color( 255, 120, 0, 255 ) )
draw.SimpleText( "Enter", "CreateButton", 15, 0, Color( 200, 200, 200, 255 ) )
draw.SimpleText( "\$"..v[3], "CreateButton", 5, 25, Color( 25, 126, 0, 255 ) )
end
else
if LocalPlayer():GetNWInt( v[1] ) == 1 then
draw.RoundedBox( 0, 0, 0, Enter:GetWide(), Enter:GetTall(), Color( 255, 140, 0, 255 ) )
draw.SimpleText( "Entered", "CreateButton", 15, 0, Color( 255, 255, 255, 255 ) )
else
draw.RoundedBox( 0, 0, 0, Enter:GetWide(), Enter:GetTall(), Color( 255, 140, 0, 255 ) )
draw.SimpleText( "Enter", "CreateButton", 15, 0, Color( 255, 255, 255, 255 ) )
draw.SimpleText( "\$"..v[3], "CreateButton", 5, 25, Color( 51, 152, 0, 255 ) )
end
end
end
Enter.DoClick = function()
if LocalPlayer():GetNWInt( v[1] ) == 1 then
else

if gmod.GetGamemode() == "DarkRP" then
if LocalPlayer():canAfford(v[3]) then
end
--else
--if LocalPlayer():PS_HasPoints(v[3]) then
--LocalPlayer():PS_TakePoints(v[3])
--end
end

LocalPlayer():SetNWInt( v[1], 1 )

if timer.Exists( v[1] ) then
else
timer.Create( v[1], (v[5] * 60), 1, function()

_G[v[1].."_WINNER"] = {}
table.insert( _G[v[1].."_WINNER"], _G[v[1]][ math.random( _G[v[1]] ) ] )

if tostring(_G[v[1].."_WINNER"]):GetNWInt( v[1] ) != nil then
tostring(_G[v[1].."_WINNER"]):SetNWInt( v[1], 2 )
table.Empty( _G[v[1].."_WINNER"]) )
end

table.Empty( _G[v[1]] )

if string.find( v[6], 'M_', 1 ) then
for k,_ in pairs( player.GetAll() ) do

if _:GetNWInt( v[1] ) == 2 then
if gmod.GetGamemode() == "DarkRP" then

else
_:PS_GivePoints( string.sub(v[6], 3) )
end
end

end
else
for k,_ in pairs( player.GetAll() ) do

if _:GetNWInt( v[1] ) == 2 then
net.Start( "GiveWeaponS" )
net.WriteEntity( _ )
net.WriteString( string.sub(v[6], 3) )
net.SendToServer()
end

end
end
end)
end
end
end

``````

[editline]11th February 2017[/editline]

This is client sided.

[editline]11th February 2017[/editline]

The idea is that each item name is entied with a table that can be edited?
Example:
ItemName = { ply, LocalPlayer(), v } (just players <-- added to the roster then draw out)
of that single item group?

Why are you using _G (you shouldnâ€™t have to) and setting a networked integer on a string clientside? Read

``````

tostring(_G[v[1].."_WINNER"]):SetNWInt( v[1], 2 )  -- ???

``````