I am trying to make a gmod deathmatch gamemode. I have 3 classes and two teams, which you can switch between using console commands.
I would like to have it so that when you type in the command to change class, a window comes up with a button for each class, and then the same to select a primary and secondary weapon for that class (from a selection).
Currently I have (in shared.lua):
function ChangeMyClass(ply, cmd,input) local Frame = vgui.Create( "DFrame" ) Frame:SetPos( 5, 5 ) Frame:SetSize( 300, 150 ) Frame:SetTitle( "loadout window" ) Frame:SetVisible( false ) Frame:SetDraggable( false ) Frame:ShowCloseButton( true ) if(input=="1" )then Frame:SetVisible(true) Frame:MakePopup() local Button1 = vgui.Create("DButton",Frame) Button1:SetText( "M1A1" ) Button:SetTextColor( Color( 255, 255, 255 ) ) Button:SetPos( 100, 100 ) Button:SetSize( 100, 30 ) Button.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) ) end print("assault") player_manager.SetPlayerClass(ply,"player_assault") ply:Spawn() end if(input=="2")then print("sniper") player_manager.SetPlayerClass(ply,"player_sniper") ply:Spawn() end if(input=="3")then print("heavy") player_manager.SetPlayerClass(ply,"player_heavy") ply:Spawn() end end concommand.Add("set_class",ChangeMyClass)
I’ve only set it up for one class for now, just to determine how to make it work.
However, when I type “set_class 1” into the console I get an error message: “attempt to index global ‘vgui’ (a nil value)”
I know that vgui is undefined, and that I need to define it in order to use it, but I have no idea how. The gmod wiki hasn’t helped at all, and neither has google. The only cause for this problem that ive found so far is either vgui is being called before its being defined (I’m not defining it at all), or that it has been undefined by an addon, and that gmod will normally have vgui automatically defined.
Any help would be greatly appreciated.