Retrieving Weapon Help

Hello everyone, I’m working on a little inventory system and I made it so it checks to see if the players ActiveWeapon is the same as the key in a table, and if it is then the classname of the weapon gets saved to a text file. I’m trying to figure out a way so when I press a button on a menu it gives the player the weapon and removes the weapon from the text file, but I can’t for the life of me figure out what to do now.

Here’s what I have right now:

– Clientside
for k, v in pairs( Weapons ) do

for a, b in pairs( InventoryItems ) do

if v == a then

    local WeaponPanel = vgui.Create("DPanel")
    WeaponPanel:SetSize( 250, 25 )

   local DButtonTesting = vgui.Create("DButton", WeaponPanel)
   DButtonTesting:SetSize( 245, 20 )
   DButtonTesting:SetText(  )
   DButtonTesting:SetPos( 5, 5 )
   DButtonTesting.DoClick = function ()
	RunConsoleCommand("UseWeapon", b)
  IconList:AddItem( WeaponPanel )


– Serverside
function RetrieveWeapon(ply, cmd, args)

local Gear = file.Read(“Inventory/” … ply:FormatSteamID() … “.txt” )
local Weapons = string.Explode( "
", Gear )

for k, v in pairs( Weapons ) do -- loop through the text file

	for a, b in pairs( InventoryItems ) do -- loop through the table

		local ent = ents.Create( a ) -- Create the weapon and give it to the player
		ent:SetModel( b.model)


concommand.Add(“UseWeapon”, RetrieveWeapon)

– Shared
InventoryItems = {

            weapon_glock = {
               name = "Glock",
               model = "models/weapons/w_pist_glock18.mdl",
               description = "This is a glock and I'm testing description and stuff"
            }, -- End Glock Table
            weapon_m4 = {
                name = "M4",
                model = "models/weapons/w_rif_m4a1.mdl",
                description = "This is a m4 and I'm testing description and stuff"
            }, -- End M4 Table
	weapon_mp5 = {
	     name = "MP5",
	     model = "models/weapons/w_smg_mp5.mdl",
	     description = "This is a mp5 and I'm testing description and stuff"
	} -- End MP5 Table

} – End Inventory Table

I would appreciate any help!

There are a couple things wrong.

  • You never use the arguments (args parameter) from the concommand that you call clientside. So the ‘b’ that you pass is just lost. You’ll need to do something like local index = tonumber( args[1] ) and then use that throughout.
  • You are passing the whole table as an argument. Your ‘b’ in the concommand that you call. Your information is shared, so all you have to do is pass the key and then use the shared information to access the table via the key that is passed.
  • Are you making a database with text files? If you are then I’d suggest looking into implementing a database or at least using PData.
  • Do you have entities made called “weapon_glock” etc… ? If so, why do you have the model in the table? Do you plan to use a dmodelPanel somewhere? You should still set the world model and view model in the swep itself not when you spawn it.

Okay thanks for the info man! I’ll work on it and if I have any questions I’ll post back here. And I do plan on adding a DModelPanel, but I was just trying to get everything to work before I added it to the menu.