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 = {}
util.AddNetworkString("Whatever")
net.Receive( "Whatever", function( len, pl )
if ( not MyBuffer[ pl ] ) then MyBuffer[ pl ] = {} end
table.insert( MyBuffer[ pl ], net.ReadInt( 3 ) );
end)
--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
print("Success!")
--elseif (etc) then
--etc
end
end
MyBuffer[ pl ] = nil
end
print("------TODO: Disguise System------")
player_manager.SetPlayerClass( ply, "player_combine" )
player_manager.OnPlayerSpawn( ply )
player_manager.RunClass( ply, "SetModel" )
ply:SetupHands()
player_manager.RunClass( ply, "Loadout" )
ply:UnSpectate()
end
--Clientside
--This is in a derma menu code
local dpan = vgui.Create( "DButton", frame )
dpan:SetPos(20,100)
dpan:SetSize(150,50)
dpan:SetText("Test")
dpan.DoClick = function()
net.Start("Whatever")
net.WriteInt(3,2)
net.SendToServer()
end