[lua]
– CLIENT
local PANEL = {}
function PANEL:Init( )
self:SetTitle(“Class Selection”)
self:SetSize(200,500)
self.Label = vgui.Create( “DLabel”, self )
self.Label:SetText( “Click on a button to choose a class.” )
self.Label:SetTextColor( Color( 255, 255, 255, 255 ) )
self.Label:SizeToContents( )
self.Buttons = { }
self:AddClass("Lightsabers")
self:AddClass("Big man")
self:AddClass("some class")
end
function PANEL:AddClass(class)
local b = vgui.Create(“DButton”,self)
b:SetText(class)
function b.DoClick( b )
RunConsoleCommand(“join_class”, class)
end
table.insert( self.Buttons, b )
end
function PANEL:PerformLayout( )
self:StretchToParent( 2, 24, 2, 2 )
self.Label:SetPos( 2, 2 )
local y = self.Label:GetTall( ) + 4
for k,v in pairs( self.Buttons ) do
v:SetPos( 2, y )
v:SetSize( self:GetWide( ) - 4, 25 )
y = y + 27
end
end
vgui.Register( “class_menu”, PANEL, “DFrame” )
function OpenClassMenu()
vgui.Create(“class_menu”)
end
concommand.Add(“open_class”, OpenClassMenu)
---- ON THE SERVER
function Join_class(args)
ply.Class = args[1]
//Do some other stuff with classes here like set their weapon stuff etc
end
concommand.Add(“join_class”, Join_class)
[/lua]
Should work.
If you have a table of classes like:
[lua]
CLASSES = {}
CLASSES[1] = {Name = “Scout”, Weapons = {“weapon_smg1”, “weapon_pistol”}}
CLASSES[2] = {Name = “Heavy”, Weapons = {“weapon_ar2”, “weapon_rpg”}}
[/lua]
Then just do this when you are adding buttons to the menu:
[lua]
for k,v in pairs(CLASSES) do
self:AddButton(v.Name)
end
[/lua]
You will have to adjust the server side console command though.