• I just can't figure this out
    7 replies, posted
I'm having trouble with GM:PlayerInitialSpawn for base I'm trying to make the Team menu pop up on first spawn it's been a real pain and could use some help Here are my codes [b]shared.lua[/b] [lua]GM.Name = "PlayerLineWars" --Set the gamemode name GM.Author = "Zargero" --Set the author name GM.Email = "N/A" --Set the author email GM.Website = "N/A" --Set the author website team.SetUp( 1, "Red", Color( 255, 0, 0, 255 ) ) --Here we make the team Guests team.SetUp( 2, "Blue", Color( 0, 0, 255 , 225 ) )[/lua] [b]init.lua[/b] [lua]AddCSLuaFile( "cl_init.lua" ) --Tell the server that the client need to download cl_init.lua AddCSLuaFile( "shared.lua" ) --Tell the server that the client need to download shared.lua include( 'shared.lua' ) --Tell the server to load shared.lua include( 'cl_init.lua' ) --Tell the server to load cl_init.lua function GM:PlayerInitialSpawn( ply ) --"When the player first joins the server and spawns" function RunConsoleCommand( "team_menu" ) --Run the console command when the player first spawns end --End the "when player first joins server and spawn" function function GM:PlayerLoadout( ply ) --Weapon/ammo/item function if ply:Team() == 1 then --If the player is in team 1 ply:Spawn() -- Make the player respawn elseif ply:Team() == 2 then --If the player is in team 2 ply:Spawn() -- Make the player respawn end --Here we end the if condition end --Here we end the Loadout function function team_1( ply ) ply:SetTeam( 1 ) end function team_2( ply ) ply:SetTeam( 2 ) end concommand.Add( "team_1", team_1 ) concommand.Add( "team_2", team_2 )[/lua] [b]cl_init.lua[/b] [lua]include( 'shared.lua' ) --Tell the client to load shared.lua function set_team() local frame = vgui.Create( "DFrame" ) frame:SetPos( ScrW() / 2, ScrH() / 2 ) --Set the window in the middle of the players screen/game window frame:SetSize( 250, 250 ) --Set the size frame:SetTitle( "Choose Team" ) --Set title frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() team_1 = vgui.Create( "DButton", frame ) team_1:SetPos( frame:GetTall() / 2, 5 ) --Place it half way on the tall and 5 units in horizontal team_1:SetSize( 50, 100 ) team_1:SetText( "Red" ) team_1.DoClick = function() --Make the player join team 1 RunConsoleCommand( "team_1" ) RunConsoleCommand( "kill" ) end team_2 = vgui.Create( "DButton", frame ) team_2:SetPos( frame:GetTall() / 2, 105 ) --Place it next to our previous one team_2:SetSize( 50, 100 ) team_2:SetText( "Blue" ) team_2.DoClick = function() --Make the player join team 2 RunConsoleCommand( "team_2" ) RunConsoleCommand( "kill" ) end end concommand.Add( "team_menu", set_team )[/lua] I'm not sure if you need this but [b]Info.txt[/b] [lua]"Gamemode" { "name" "PlayerLineWars" "version" "0.1" "up_date" "1/08/2009" // The date this version was published. Set before release! "author_name" "Zargero" "author_email" "Zargero10@hotmail.com" "author_url" "http://steamcommunity.com/id/Zargeroz" "info" "Send Waves of NPCs to the other team to win" "icon" "" // Icon to show in the Mods list inside Garry's Mod "hide" "0" // Do not hide this gamemode from the Mods list inside Garry's Mod "mappattern" // This sets all maps with gt_ before the name to default the map gamemode to "GM_test" { "1" "^gt_" } } [/lua]
It's probably better if you use usermessages. [b]init.lua:[/b] [lua]function GM:PlayerInitialSpawn( ply ) umsg.Start("TeamMenu", ply) umsg.End() end[/lua] [b]cl_init.lua:[/b] [lua]usermessage.Hook("TeamMenu", function() local frame = vgui.Create( "DFrame" ) frame:SetPos( ScrW() / 2, ScrH() / 2 ) --Set the window in the middle of the players screen/game window frame:SetSize( 250, 250 ) --Set the size frame:SetTitle( "Choose Team" ) --Set title frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() team_1 = vgui.Create( "DButton", frame ) team_1:SetPos( frame:GetTall() / 2, 5 ) --Place it half way on the tall and 5 units in horizontal team_1:SetSize( 50, 100 ) team_1:SetText( "Red" ) team_1.DoClick = function() --Make the player join team 1 RunConsoleCommand( "team_1" ) RunConsoleCommand( "kill" ) end team_2 = vgui.Create( "DButton", frame ) team_2:SetPos( frame:GetTall() / 2, 105 ) --Place it next to our previous one team_2:SetSize( 50, 100 ) team_2:SetText( "Blue" ) team_2.DoClick = function() --Make the player join team 2 RunConsoleCommand( "team_2" ) RunConsoleCommand( "kill" ) end end)[/lua]
Or replace [lua]RunConsoleCommand( "team_menu" )[/lua] with [lua]ply:ConCommand( "team_menu" )[/lua] in init.lua. RunConsoleCommand will run the command on the server.
Thanks guys it works but now im getting an error when i change team [code]PlayerLineWars\gamemode\init.lua:28: attempt to call method 'SetTeam' (a nil value) PlayerLineWars\gamemode\init.lua:34: attempt to call method 'SetTeam' (a nil value)[/code] and my lines 28 -34 are.. [lua]function team_1( ply ) ply:SetTeam( 1 ) end function team_2( ply ) ply:SetTeam( 2 ) end concommand.Add( "team_1", team_1 ) concommand.Add( "team_2", team_2 )[/lua]
.
[QUOTE=NullPoint;19623457]It's probably better if you use usermessages. [b]init.lua:[/b] [lua]function GM:PlayerInitialSpawn( ply ) umsg.Start("TeamMenu", ply) umsg.End() end[/lua] [b]cl_init.lua:[/b] [lua]usermessage.Hook("TeamMenu", function() local frame = vgui.Create( "DFrame" ) frame:SetPos( ScrW() / 2, ScrH() / 2 ) --Set the window in the middle of the players screen/game window frame:SetSize( 250, 250 ) --Set the size frame:SetTitle( "Choose Team" ) --Set title frame:SetVisible( true ) frame:SetDraggable( false ) frame:ShowCloseButton( true ) frame:MakePopup() team_1 = vgui.Create( "DButton", frame ) team_1:SetPos( frame:GetTall() / 2, 5 ) --Place it half way on the tall and 5 units in horizontal team_1:SetSize( 50, 100 ) team_1:SetText( "Red" ) team_1.DoClick = function() --Make the player join team 1 RunConsoleCommand( "team_1" ) RunConsoleCommand( "kill" ) end team_2 = vgui.Create( "DButton", frame ) team_2:SetPos( frame:GetTall() / 2, 105 ) --Place it next to our previous one team_2:SetSize( 50, 100 ) team_2:SetText( "Blue" ) team_2.DoClick = function() --Make the player join team 2 RunConsoleCommand( "team_2" ) RunConsoleCommand( "kill" ) end end)[/lua][/QUOTE] This worked perfectly thank you but is there a way to make lets say F2 pop that menu up also just encase someone wants to change teams
Add this to your init.lua: [lua]function GM:ShowTeam(ply) umsg.Start("TeamMenu", ply) umsg.End() end[/lua] [b][url=wiki.garrysmod.com/?title=Gamemode.ShowTeam]Gamemode.ShowTeam [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is a gamemode function that is called when someone presses F2.
Thanks again NullPoint you alot of help
Sorry, you need to Log In to post a reply to this thread.