How to open panel on player spawn?

I’m trying to make simple gamemode to learn a bit of gmod lua and I wanted to display panel to player after he spawns, if I understand what I’ve learned so far, it must be done client side. Currently in player class I have this:

function PLAYER:Spawn()

	local oldhands = self.Player:GetHands();
	if ( IsValid( oldhands ) ) then

	local hands = ents.Create( "gmod_hands" )
	if ( IsValid( hands ) ) then
		hands:DoSetup( self.Player )
	self.Player:GiveAmmo( 256,	"Pistol", 		true )
	self.Player:Give( "weapon_pistol" )

	if (CLIENT) then

and it runs only on server side… I marked this file for sending to client and included it in shared.lua without any effect. According to wiki this hook is supposed to run on both client and server.

Do I have to do something more in shared lua than including player class file?

In your cl_init.lua, try hooking the PlayerInitialSpawn or PlayerSpawn.


local function openframe()
    local frame = vgui.create("DFrame")
    frame:SetSize( 400, 300 )
    frame:SetPos( ScrW() / 2 - frame:GetWide(), SchH() / 2 - frame:GetTall() )
    --blah blah blah

hook.Add( "PlayerSpawn", "DermaShit", openframe )

Nope, it doesn’t work… It seems like this event is never run on client. I can set up client-side KeyPress hook and it works, but not “Spawn” or “PlayerSpawn”…

Those are server side hooks.

You could use the user message library, or the net library.

In your init.lua file, add a section at the top for net messages. You’ll probably need more as the gamemode progresses. eg

Then you will pool your net message like so:

// Net Messages

util.AddNetworkString( “OpenSpawnMenu” )

You have to allow a few seconds for the message to do it’s thing after you add it.

Then, in your serverside PlayerSpawn function you can do

net.Start( “OpenSpawnMenu” )
net.Send( ply ) // or whatever you’re defining the player as

Then in cl_init.lua, or whatever clientside file you want to make the menu in, you do:

net.Receive( “OpenSpawnMenu”, function()
//make your frame

You can also send things from the server, so you could add this to your spawn function:

net.Start( “OpenSpawnMenu” )
net.WriteString( ply:Nick() )
net.WriteString( “Hello” )
net.Send( ply )

and then you can read it on the client.

(You can send multiple strings, they will be categorized in order of first added.
net.Receive( “OpenSpawnMenu”, function()
local playername = net.ReadString()
local message2 = net.ReadString()

print( message2 )
print( playername )

Here is the net library

Here’s the introduction on the wiki if you don’t understand still

Good luck!