Writing two things about an weapon to a table.

Hi there, I am trying to resume my work on this gun chest addon however I am currently having an issue whereby I need to write the weapon name and the model to the table.

The player will be able to get the weapon back afterwards however I am unsure of how to write multiple things to tables or how to do it in the correct layout/syntax.

Here is my code so far.

init.lua
[lua]
function ENT:StartTouch(entity)
print(entity:GetClass())
if entity:GetClass() == “spawned_weapon” then
table.insert(weaponsInsideChest, entity:GetWeaponClass())
entity:Remove()
PrintTable(weaponsInsideChest)
end
end

net.Receive(“WeaponRetrieval”,function(len,ply)

local chosengun = net.ReadString()
if table.HasValue(weaponsInsideChest, chosengun) then
            --Here is where I need to give the player the weapon
	table.remove(weaponsInsideChest, chosengun)
end

end)
[/lua]

cl_init.lua
[lua]
include(‘shared.lua’)

function ENT:Draw()

self:DrawModel()

end

function WeaponsInsideDerma()

local frame = vgui.Create("DFrame")
frame:SetSize(500,500)
frame:Center()
frame:SetDraggable(false)
frame:MakePopup()
frame:SetSizable(false)
frame:ShowCloseButton(false)
function frame.Paint(s,w,h)
	draw.RoundedBox(5,0,0,w,h,Color(20,20,20,240))
end

local scroll = vgui.Create( "DScrollPanel",frame)
scroll:SetSize( 35, 420 )
scroll:Dock(FILL)

for k,v in pairs(weaponsInsideChest) do
	local panel = vgui.Create("DPanel",scroll)
	panel:Dock(TOP)
	panel:DockMargin(0,3,0,0)
	panel:SetSize(0,75)
	function panel.Paint(s,w,h)
		draw.RoundedBox(5,0,0,w,h,Color(210,60,70))
	end

	local buttonClose = vgui.Create("DButton", frame)
	buttonClose:SetSize(50,20)
	buttonClose:SetPos(445,5)
	buttonClose:SetText("Close")
	buttonClose:SetFont("bebas18")
	buttonClose:SetTextColor(color_white)
	function buttonClose.Paint(s,w,h)
			
		draw.RoundedBox(4,0,0,w,h,Color(255,0,0))

	end
	buttonClose.DoClick = function(self)
		frame:Close()
	end

	local model = vgui.Create("DModelPanel",panel)
	model:Dock(LEFT)
	model:SetSize(64, 64)
	model:SetModel(v.Mdl)
	local mn, mx = model.Entity:GetRenderBounds()
	local size = 0
	size = math.max( size, math.abs( mn.x ) + math.abs( mx.x ) )
	size = math.max( size, math.abs( mn.y ) + math.abs( mx.y ) )
	size = math.max( size, math.abs( mn.z ) + math.abs( mx.z ) )
	model:SetFOV( 45 )
	model:SetCamPos( Vector( size, size, size ) )
	model:SetLookAt( ( mn + mx ) * 0.5 )
	function model:LayoutEntity( Entity ) return end

	local button = vgui.Create("DButton",panel)
	button:Dock(RIGHT)
	button:DockMargin(0,10,10,10)
	button:SetSize(60,60)
	button:SetText("Retrieve")
	button.DoClick = function(self)
		net.Start("WeaponRetrieval")
		net.WriteString(k)
		net.SendToServer()
	end
end

end

net.Receive(“OpenWeaponsInsideMenu”, function()

WeaponsInsideDerma()

end)
[/lua]

By the looks of it, you’re only writing the weapon info to the table serverside. You’re gonna need to use the net library to send the table/contents to the client.

To get the name of a weapon, you can use

Weapon:GetPrintName or just access the PrintName value in the table(ex WEP.PrintName). PrintName is usually only stored clientside, so you’ll have to send the weapon class to the client, then access it there. To get the world model of a weapon, you can use

Weapon:GetWeaponWorldModel or just access the WorldModel value.