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:
[CODE]
function PLAYER:Spawn()
local oldhands = self.Player:GetHands();
if ( IsValid( oldhands ) ) then
oldhands:Remove()
end
local hands = ents.Create( "gmod_hands" )
if ( IsValid( hands ) ) then
hands:DoSetup( self.Player )
hands:Spawn()
end
self.Player:RemoveAllAmmo()
self.Player:GiveAmmo( 256, "Pistol", true )
self.Player:Give( "weapon_pistol" )
if (CLIENT) then
self.Player:ChatPrint("Client")
else
self.Player:ChatPrint("Server")
end
end
[/CODE]
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.
eg.
[code]
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
end
hook.Add( "PlayerSpawn", "DermaShit", openframe )
[/code]
[QUOTE=Koolaidmini;42296724]In your cl_init.lua, try hooking the PlayerInitialSpawn or PlayerSpawn.
eg.
[/QUOTE]
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:
[LUA]
// Net Messages
util.AddNetworkString( "OpenSpawnMenu" )
[/LUA]
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
[LUA]
net.Start( "OpenSpawnMenu" )
net.Send( ply ) // or whatever you're defining the player as
[/LUA]
Then in cl_init.lua, or whatever clientside file you want to make the menu in, you do:
[LUA]
net.Receive( "OpenSpawnMenu", function()
//make your frame
end)
[/LUA]
You can also send things from the server, so you could add this to your spawn function:
[LUA]
net.Start( "OpenSpawnMenu" )
net.WriteString( ply:Nick() )
net.WriteString( "Hello" )
net.Send( ply )
[/LUA]
and then you can read it on the client.
(You can send multiple strings, they will be categorized in order of first added.
[LUA]
net.Receive( "OpenSpawnMenu", function()
local playername = net.ReadString()
local message2 = net.ReadString()
print( message2 )
print( playername )
end)
[/LUA]
[URL=http://wiki.garrysmod.com/page/Category:net]Here is the net library[/URL]
[URL=http://wiki.garrysmod.com/page/Using_the_net_library]Here's the introduction on the wiki if you don't understand still[/URL]
Good luck!
Sorry, you need to Log In to post a reply to this thread.