Class Menu

Hey Everyone,

I’m working on a mod called ‘Badass Mod’ in which a death match between players with Lightsabers, Smoke Bombs, shuirukens and lightning, occurs. I have managed to code all of this so far relatively without error, and my problems are minimal. I just need help/a tutorial/ an easy example of how to make a custom menu. I just need an empty menu with a button, and I could get the rest.

EDIT:
I just realized how not detailed that was… I need a menu for class selection, so it needs to not be attached to Q, it needs to be separate, and with a button that has an attached function.

Thanks,
Fish

I’ll whip one up for you. You just want a list of buttons right?

Yes, that’s all.

Cheers man!

[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.

:open_mouth: That was fast! I’ll try that and report back.

Thanks!

[editline]02:50PM[/editline]

K, I got it working. Thanks for the help!

Nice, I was looking for something similar. :slight_smile:
But where to add the table? :slight_smile:

bump

that was a stupid bump, make your own thread.

If I did that, I would just get a referance to this one… This was for not spamming the forum.

Better to bump than make another pointless thread.

The table can go right in the derma file.