Need help with a system I'm making for my gamemode

For my gamemode, I’m trying to do something that, upon a player clicking a derma menu button, adds a certain string to a table and upon the player spawning, gives them what the table contains(the strings I implement are weapons names, like weapon_ar2). However, I’ve had no luck with this and the methods I’ve been trying have confused me to the max. Can anyone help by posting an example code as to how I should do this? In case you don’t know what desired effect I’m trying to get, I’m trying to have players select buttons on a derma menu, and when they spawn, they are given those weapons. I’m NOT trying to give players weapons WHEN they click the derma menu, just the next time they spawn. Any help would be greatly appreciated.

In case you want to help me fix up the current method I’ve tested(credit to James xX for giving me example code), then here:

--Serverside code

local MyBuffer = {}


net.Receive( "Whatever", function( len, pl )

if ( not MyBuffer[ pl ] ) then MyBuffer[ pl ] = {} end

table.insert( MyBuffer[ pl ], net.ReadInt( 3 ) );


--just ignore the stuff below the if statement
function GM:PlayerSpawn(ply)

   if ( MyBuffer[ pl ] ) then

  for _, ButtonID in pairs( MyBuffer[ pl ] ) do

 if (ButtonID == 1) then


--elseif (etc) then




MyBuffer[ pl ] = nil


print("------TODO: Disguise System------")

player_manager.SetPlayerClass( ply, "player_combine" )

player_manager.OnPlayerSpawn( ply )

player_manager.RunClass( ply, "SetModel" )


player_manager.RunClass( ply, "Loadout" )



--This is in a derma menu code

local dpan = vgui.Create( "DButton", frame )




dpan.DoClick = function()





Add a hook on playerspawn with the weapons they select, then remove the hook when the hook is called

Why are you doing net.WriteInt( 3, 2 ) after they do the DoClick. Shouldn’t it be sending the class name (like weapon_ttt_m16 for example) to the server and then giving that weapon to the player when they spawn? Also, your coding style is hideous.

That would be my fault. When I suggested the code, I didn’t know what it would be used for, so I made it work with enumerations instead of strings. My thinking was that maybe he wanted to do other stuff as well as weapons.