Persious's team menu guide
From GMod Wiki
Persious' Team Selection Menu
IMPORTANT! This is for a gamemode!
This is tested, and works.
Okay, let's get started. I was thinking about, making a realy simple and funny, but where you can learn new things.
Let's get started. 1. Go and make your own gamemode folder in C:\Program Files (x86)\Steam\steamapps\YOUR USERNAME\garrysmod\garrysmod\gamemodes Ill just call mine "Test".
2. Make a info.txt file and copy this:
"Gamemode" { "name" "Gamemode name" "version" "1.0" "author_name" "Your name" "author_email" "Your email" "author_url" "" "info" "Detail about your gamemode" "hide" "0" }
3. Go inside the gamemode, and make 3 files. cl_init.lua - init.lua - shared.lua
4. First, open shared.lua and copy this text in it.
----------Colors--------- local clrTable = {} //Color table clrTable["Green"] = Color(20, 150, 20, 255) clrTable["Blue"] = Color(25, 25, 170, 255) clrTable["Red"] = Color(150, 20, 20, 255) clrTable["Brown"] = Color(102, 34, 0, 255) ------------------------- GM.Name = "Gamemode name" GM.Author = "Your name here" GM.Email = "" GM.Website = "" TEAM_1 = 1 TEAM_2 = 2 TEAM_3 = 3 TEAM_4 = 4 team.SetUp( TEAM_1, "Team 1", clrTable["Green"] ) team.SetUp( TEAM_2, "Team 2", clrTable["Blue"] ) team.SetUp( TEAM_3, "Team 3", clrTable["Red"] ) team.SetUp( TEAM_4, "Team 4", clrTable["Brown"] )
Now, let's open init.lua. Copy this code.
AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) // You can make a simple function using arguements to make this less messier but this would be the simplest way to explain what it does. function TEAM_1( ply ) -- Creating the function. ply:UnSpectate() -- As soon as the person joins the team, he get's Un-spectated ply:SetTeam( 1 ) -- We'll set him to team 1 ply:Spawn() -- Let's spawn him. end -- End the function concommand.Add("TEAM_1", TEAM_1) -- Adding a concommand (Console Command) for the team. function TEAM_2( ply ) ply:UnSpectate() ply:SetTeam( 2 ) ply:Spawn() end concommand.Add("TEAM_2", TEAM_2) function TEAM_3( ply ) ply:UnSpectate() ply:SetTeam( 3 ) ply:Spawn() end concommand.Add("TEAM_3", TEAM_3) function TEAM_4( ply ) ply:UnSpectate() ply:SetTeam( 4 ) ply:Spawn() end concommand.Add("TEAM_4", TEAM_4)
Last part, and the best part. The Derma menu. Open up cl_init.lua, and copy this.
include( "shared.lua" ) function TeamMenu( ) -- Starting the function. // all the buttons I'm about to create are just a simple way to explain everything. I would make a table and make buttons that way but look through some more tutorials about loops till you do that. local TeamMenu = vgui.Create( "DFrame" ) -- Creating the Vgui. TeamMenu:SetPos( ScrW() +250, ScrH() / 2 -200 ) -- Setting the position of the menu. TeamMenu:SetSize( 260, 210 ) -- Setting the size of the menu. TeamMenu:SetTitle( "My test team selection menu" ) -- The menu title. TeamMenu:ShowCloseButton( false ) -- Want us to see the close button? No. TeamMenu:SetVisible( true ) -- Want it visible? TeamMenu:SetDraggable( false ) -- Setting it draggable? TeamMenu:MakePopup( ) -- And now we'll make it popup function TeamMenu:Paint() -- This is the funny part. Let's paint it. draw.RoundedBox( 8, 0, 0, self:GetWide(), self:GetTall(), Color( 0,0,0,200 ) ) -- This paints, and round's the corners etc. end -- Now we ONLY end the painting function. -- This is a part which I had to add for the fun sake. if !TeamMenu.Open then -- If the menu is closed, then TeamMenu:MoveTo(ScrW() / 2 - 250, ScrH() / 2 - 200, 1.6, 0,1) -- When you open it, it will slide trough the screen, not teleport. end -- Ending the if statement -- Button time. local team_1 = vgui.Create( "DButton", TeamMenu ) Creating the vgui of the button. team_1:SetPos( 5, 30 ) -- Setting the position. team_1:SetSize( 250, 30 ) -- Setting the size team_1:SetText( "Team 1" ) -- Setting the text of the button team_1.Paint = function() -- The paint function surface.SetDrawColor( 0, 255, 0, 255 ) -- What color do You want to paint the button (R, B, G, A) surface.DrawRect( 0, 0, team_1:GetWide(), team_1:GetTall() ) -- Paint what cords end -- Ending the painting team_1.DoClick = function() --Make the player join team 1 RunConsoleCommand( "TEAM_1" ) TeamMenu:Close() -- Close the DFrame (TeamMenu) end -- Ending the button. -- Now, this will be going on for 3 other buttons. local team_2 = vgui.Create( "DButton", TeamMenu ) team_2:SetPos( 5, 70 ) team_2:SetSize( 250, 30 ) team_2:SetText( "Team 2" ) team_2.Paint = function() -- The paint function surface.SetDrawColor( 0, 0, 255, 255 ) -- What color do You want to paint the button (R, B, G, A) surface.DrawRect( 0, 0, team_2:GetWide(), team_2:GetTall() ) -- Paint what cords (Used a function to figure that out) end team_2.DoClick = function() --Make the player join team 2 RunConsoleCommand( "TEAM_2" ) TeamMenu:Close() end local team_3 = vgui.Create( "DButton", TeamMenu ) team_3:SetPos( 5, 110 ) --Place it next to our previous one team_3:SetSize( 250, 30 ) team_3:SetText( "Team 3" ) team_3.Paint = function() -- The paint function surface.SetDrawColor( 255, 0, 0, 255 ) -- What color do You want to paint the button (R, B, G, A) surface.DrawRect( 0, 0, team_3:GetWide(), team_3:GetTall() ) -- Paint what cords (Used a function to figure that out) end team_3.DoClick = function() --Make the player join team 3 RunConsoleCommand( "TEAM_3" ) TeamMenu:Close() end local team_4 = vgui.Create( "DButton", TeamMenu ) team_4:SetPos( 5, 150 ) --Place it next to our previous one team_4:SetSize( 250, 30 ) team_4:SetText( "Team 4" ) team_4.Paint = function() -- The paint function surface.SetDrawColor( 102, 34, 0, 255 ) -- What color do You want to paint the button (R, B, G, A) surface.DrawRect( 0, 0, team_3:GetWide(), team_3:GetTall() ) -- Paint what cords (Used a function to figure that out) end team_4.DoClick = function() --Make the player join team 4 RunConsoleCommand( "TEAM_4" ) TeamMenu:Close() end -- Here we are, the close button. The last button for this, because this is used instead of ShowCloseButton( false ) local close_button = vgui.Create( "DButton", TeamMenu ) close_button:SetPos( 5, 185 ) close_button:SetSize( 250, 20 ) close_button:SetText( "Close this menu" ) close_button.Paint = function() draw.RoundedBox( 8, 0, 0, close_button:GetWide(), close_button:GetTall(), Color( 0,0,0,225 ) ) surface.DrawRect( 0, 0, close_button:GetWide(), close_button:GetTall() ) end close_button.DoClick = function() TeamMenu:Close() end end -- Now we'll end the whole function. concommand.Add("TeamMenu", TeamMenu) -- Adding the Console Command. So whenever you enter your gamemode, simply type TeamMenu in console.