Open a window when a player joins

When a player joins (fully gets into the game) I want it to prompt him with this code. On the wiki I couldn’t find anything to do with playerjoin.


function steamgroup()
	local window = vgui.Create( "DFrame" )
	if ScrW() > 320 then -- Make it larger if we can.
		window:SetSize( ScrW()*0.9, ScrH()*0.9 )
	else
		window:SetSize( 320, 240 )
	end
	window:Center()
	window:SetTitle( "Steam Group" )
	window:SetVisible( true )
	window:MakePopup()

	local button = vgui.Create( "DButton", window )
	button:SetText( "Close" )
	button.DoClick = function() window:Close() end
	button:SetSize( 50, 20 )
	button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
end

How would I do this?

Add at the bottom, it might not be InitialSpawn but I think this is it.
hook.Add(“PlayerInitialSpawn”,“PlayerInitialSpawn”,steamgroup);

I added that and all it did was remove my weapons and didn’t prompt any window :s


if SERVER then
	
	// We need to pool the net message using the util library
	// otherwise you'll have an error thrown at you
	util.AddNetworkString("OpenSteamGroupMenu")

	// 'PlayerInitialSpawn' is serverside, so
	// need to hook it to send a net message
	hook.Add("PlayerInitialSpawn", "PlayerInitMenu",
				function( ply )
					net.Start("OpenSteamGroupMenu")
					net.Send( ply )
				end )

else

	function steamgroup()
		local window = vgui.Create( "DFrame" )
		if ScrW() > 320 then -- Make it larger if we can.
			window:SetSize( ScrW()*0.9, ScrH()*0.9 )
		else
			window:SetSize( 320, 240 )
		end
		window:Center()
		window:SetTitle( "Steam Group" )
		window:SetVisible( true )
		window:MakePopup()

		local button = vgui.Create( "DButton", window )
		button:SetText( "Close" )
		button.DoClick = function() window:Close() end
		button:SetSize( 50, 20 )
		button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
	end
	
	// This receive will only run the function when
	// the server sends the net message
	net.Receive("OpenSteamGroupMenu", function() steamgroup() end)

end

If you’re just using a single file to do this, you can use your server’s autorun folder to include it both clientside & serverside, or you can put it into an addon and make sure it runs on the shared realm.


if SERVER then
	
	// We need to pool the net message using the util library
	// otherwise you'll have an error thrown at you
	util.AddNetworkString("OpenSteamGroupMenu")

	// 'PlayerInitialSpawn' is serverside, so
	// need to hook it to send a net message
	hook.Add("PlayerInitialSpawn", "PlayerInitMenu",
				function( ply )
					net.Start("OpenSteamGroupMenu")
					net.Send( ply )
				end )

else

	function steamgroup()
		local window = vgui.Create( "DFrame" )
		if ScrW() > 320 then -- Make it larger if we can.
			window:SetSize( ScrW()*0.9, ScrH()*0.9 )
		else
			window:SetSize( 320, 240 )
		end
		window:Center()
		window:SetTitle( "Steam Group" )
		window:SetVisible( true )
		window:MakePopup()

		local button = vgui.Create( "DButton", window )
		button:SetText( "Close" )
		button.DoClick = function() window:Close() end
		button:SetSize( 50, 20 )
		button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
	end
	
	// This receive will only run the function when
	// the server sends the net message
	net.Receive("OpenSteamGroupMenu", steamgroup )

end

Use what Lucky Luke suggested ( above ) or this:

I’m probably gonna get a lot of hate for this:

[lua]
if SERVER then
hook.Add( “PlayerInitialSpawn”, “OpenThing”, function( ply ) ply:SendLua( steamgroup() ) )
else
function steamgroup()
local window = vgui.Create( “DFrame” )
if ScrW() > 320 then – Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 320, 240 )
end
window:Center()
window:SetTitle( “Steam Group” )
window:SetVisible( true )
window:MakePopup()

local button = vgui.Create( "DButton", window )
button:SetText( "Close" )
button.DoClick = function() window:Close() end
button:SetSize( 50, 20 )
button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
end

end
[/lua]

I literally had this problem lol.
http://forum.facepunch.com/showthread.php?t=1406810&p=45301564#post45301564

This is how I solved it:



hook.Add("HUDPaint", "FirstFrame", function()
	steamgroup();
	hook.Remove("HUDPaint", "FirstFrame");
end)


Goes in same file with your steamgroup function (clientside)

I did want to add another response to your thread sack. I provided what you were asking, however if it is only needed clientside the same can be done by adding the HUDPaint hook without needing the networking to simplify things.

I’d still recommend a PlayerFullyConnected hook be utilized from the server which is then distributed/called on both client and server: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_hook_playerfullyconnected.rar

Thanks all!

I just said this in another thread. You all are making it WAY more hacky then it needs to be. Just hook into OnEntityCreated.

Edit:
Mista tea has the better solution for this application.

The Player entity is created before they are fully connected, as in fully in-game and able to manipulate the camera, toggle console, etc; the loading sequence has completed 100% and the user has control over the game. That is why I don’t use that method.

Its all fine and it works great!

Just for future reference, InitPostEntity on the client is one of the easiest things to use when you want to know the player has fully initialized in the server.

It doesn’t have to be any more complicated than adding


hook.Add( "InitPostEntity", "CreateSteamGroupFrame", steamgroup )

after end. You don’t have to network anything or rely on the server for PlayerInitialSpawn. You don’t have to do something as hacky like OnEntityCreated, which is going to get called hundreds of times depending on your gamemode (e.g., Sandbox), etc.

InitPostEntity is pretty much called as soon as the player can see in-game and start moving.