Ehm.
So.
How do I make so the menu I make, will be there when I start up the server?
Like.
I start up the server -> I join -> The first things that comes is the menu, where I have the jobs.
Thanks.
You need to have a server-side lua file which hooks into the Gamemode.PlayerInitialSpawn.
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html?title=Gamemode.PlayerInitialSpawn[/url]
The code would presumably be something like this (untested):
[B]Server Side File[/B]
[lua]
function FirstSpawn( ply )
ply:ConCommand("{CustomCommand}")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
[/lua]
[B]Client Side File[/B]
[lua]
function LaunchVGui()
{
/* code here */
}
concommand.add("launchVgui", LaunchVGui)
[/lua]
[QUOTE=SharpCoder;34742073]You need to have a server-side lua file which hooks into the Gamemode.PlayerInitialSpawn.
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html?title=Gamemode.PlayerInitialSpawn[/url]
The code would presumably be something like this (untested):
[B]Server Side File[/B]
[lua]
function FirstSpawn( ply )
ply:ConCommand("{CustomCommand}")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
[/lua]
[B]Client Side File[/B]
[lua]
function LaunchVGui()
{
/* code here */
}
concommand.add("launchVgui", LaunchVGui)
[/lua][/QUOTE]
Well im such a noob in lua, so.
I dont even know what client side files and server side files is.
I got these files: shared.lua , cl_init.lua, init.lua
cl_init.lua is a clientside file, init.lua is a serverside file, shared.lua is a shared file(Shared gets sent to both serverside and clientside)
Ok, so im just trying to learn some coding.
And I cant get the gamemode to work.
Look through this please.
[b]shared.lua[/b]
[lua]
----------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 = "Test Mod"
GM.Author = "Markus Olsen"
GM.Email = ""
GM.Website = "www.serveraim.net"
TEAM_1 = Mayor
TEAM_2 = SWAT
TEAM_3 = Police
TEAM_4 = Army
team.SetUp( TEAM_1, "Mayor", clrTable["Green"] )
team.SetUp( TEAM_2, "SWAT", clrTable["Blue"] )
team.SetUp( TEAM_3, "Police", clrTable["Red"] )
team.SetUp( TEAM_4, "Army", clrTable["Brown"] )
[/lua]
[b]init.lua[/b]
[lua]
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_Mayor( 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.
ply:Give( "weapon_physgun" ) -- ...then give them the Gravity Gun.
ply:Give( "weapon_physcannon" )
ply:Give( "keys" )
ply:Give( "weapon_mad_fists" )
end -- End the function
concommand.Add("TEAM_Mayor", TEAM_Mayor) -- Adding a concommand (Console Command) for the team.
function TEAM_SWAT( ply )
ply:UnSpectate()
ply:SetTeam( 2 )
ply:Spawn()
ply:Give( "weapon_physgun" ) -- ...then give them the Phys Gun.
ply:Give( "weapon_physcannon" )
ply:Give( "keys" )
ply:Give( "arrest_stick" )
ply:Give( "unarrest_stick" )
ply:Give( "stunstick" )
ply:Give( "weapon_mad_fists" )
ply:Give( "weapon_mad_mp5" )
end
concommand.Add("TEAM_SWAT", TEAM_SWAT)
function TEAM_Police( ply )
ply:UnSpectate()
ply:SetTeam( 3 )
ply:Spawn()
ply:Give( "weapon_physgun" ) -- ...then give them the Phys Gun.
ply:Give( "weapon_physcannon" )
ply:Give( "keys" )
ply:Give( "arrest_stick" )
ply:Give( "unarrest_stick" )
ply:Give( "stunstick" )
ply:Give( "weapon_mad_fists" )
ply:Give( "weapon_mad_mp5" )
end
concommand.Add("TEAM_Police", TEAM_Police)
function TEAM_Army( ply )
ply:UnSpectate()
ply:SetTeam( 4 )
ply:Spawn()
ply:Give( "weapon_physgun" ) -- ...then give them the Phys Gun.
ply:Give( "weapon_physcannon" )
ply:Give( "keys" )
ply:Give( "arrest_stick" )
ply:Give( "unarrest_stick" )
ply:Give( "stunstick" )
ply:Give( "weapon_mad_fists" )
ply:Give( "weapon_mad_mp5" )
ply:Give( "weapon_mad_m3" )
end
concommand.Add("TEAM_Army", TEAM_Army)
end
function GM:PlayerInitialSpawn( ply ) --"When the player first joins the server and spawns" function
ply:ConCommand( "TeamMenu" ) --Run the console command when the player first spawns
end --End the "when player first joins server and spawn" function
function GM:PlayerLoadout( ply ) --"The weapons/items that the player spawns with" function
ply:StripWeapons() -- This command strips all weapons from the player.
end -- This ends the if/elseif.
end -- This ends the function.
[/lua]
[b]cl_init.lua[/b]
[lua]
include( "shared.lua"
-- Welcome Message
function FirstSpawn( ply )
ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
-- TEAMS
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( "Mayor" ) -- 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_Mayor" )
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( "S.W.A.T" )
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_SWAT" )
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( "Police" )
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_Police" )
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( "Army" )
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_Army" )
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.
[/lua]
Okay good job on attempting to implement the code!! A few things to note: if you wrap the code with [ lua ] tags when you post it here, it makes it much easier to read.
Secondly, I don't see anything that actually opens the vgui window. Try adding this at the end of your "TeamMenu" function.
[lua]
TeamMenu:Open()
[/lua]
I could be wrong, but I believe you need that. Lastly, probably a typo, but at the top you have:
[lua]
include( "shared.lua"
[/lua]
Notice it is missing a closing parenthesis. Make sure that is not how it looks in the real code!
Hope this helps.
[QUOTE=SharpCoder;34742637]Okay good job on attempting to implement the code!! A few things to note: if you wrap the code with [ lua ] tags when you post it here, it makes it much easier to read.
Secondly, I don't see anything that actually opens the vgui window. Try adding this at the end of your "TeamMenu" function.
[lua]
TeamMenu:Open()
[/lua]
I could be wrong, but I believe you need that. Lastly, probably a typo, but at the top you have:
[lua]
include( "shared.lua"
[/lua]
Notice it is missing a closing parenthesis. Make sure that is not how it looks in the real code!
Hope this helps.[/QUOTE]
Added lua tags.
Will check if it works now.
[b]EDIT:[/b] Lua error: [lua\includes\modules\team.lua:30] table index is nil
Registering gamemode 'Test' derived from 'base'
[b]EDIT2:[/b]: There must be something wrong in this. I follow this topic, while I change some stuff.
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7f3d.html?title=Persious%27s_team_menu_guide[/url]
If anyone wanna try to edit or something, I can send you the gamemode.
[url]http://www.2shared.com/file/iJztxeSf/Test_Gamemode.html[/url]
[QUOTE=Keyword;34742768]Added lua tags.
Will check if it works now.
[b]EDIT:[/b] Lua error: [lua\includes\modules\team.lua:30] table index is nil
Registering gamemode 'Test' derived from 'base'
[b]EDIT2:[/b]: There must be something wrong in this. I follow this topic, while I change some stuff.
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7f3d.html?title=Persious%27s_team_menu_guide[/url]
If anyone wanna try to edit or something, I can send you the gamemode.
[url]http://www.2shared.com/file/iJztxeSf/Test_Gamemode.html[/url][/QUOTE]
Well after downloading your code it looks like you still have a missing parenthesis.
[lua]
// This needs to be changed
include( "shared.lua"
// To
include( "shared.lua" )
// Notice how I have a close parenthesis at the end? You need that too.
[/lua]
Everything else looks fairly reasonable.
[QUOTE=SharpCoder;34742992]Well after downloading your code it looks like you still have a missing parenthesis.
[lua]
// This needs to be changed
include( "shared.lua"
// To
include( "shared.lua" )
// Notice how I have a close parenthesis at the end? You need that too.
[/lua]
Everything else looks fairly reasonable.[/QUOTE]
Well. I uploaded that version of the gamemode, before I changed it. I have changed it, and I got that error I wrote. May you try to launch it? And see what happens?
Sorry, you need to Log In to post a reply to this thread.