GM:PlayerInitialSpawn
Description
Called when the player spawns for the first time.
See GM:PlayerSpawn for a hook called every player spawn.
This hook is called before the player has fully loaded, when the player is still in seeing the
Starting Lua
screen. For example, trying to use the Entity:GetModel function will return the default model (models/player.mdl
).Due to the above note, sending net messages to the spawned player in this hook may cause them to be received before the player finishes loading, for example LocalPlayer might return NULL since GM:InitPostEntity may have not been called yet clientside though the net message won't be lost and the client still should receive it (more information here: https://github.com/Facepunch/garrysmod-requests/issues/718).
local load_queue = {}
hook.Add( "PlayerInitialSpawn", "myAddonName/Load", function( ply )
load_queue[ ply ] = true
end )
hook.Add( "StartCommand", "myAddonName/Load", function( ply, cmd )
if load_queue[ ply ] and not cmd:IsForced() then
load_queue[ ply ] = nil
-- Send what you need here if it requires the client to be fully loaded!
end
end )
-- CLIENT
hook.Add( "InitPostEntity", "Ready", function()
net.Start( "cool_addon_client_ready" )
net.SendToServer()
end ) -- SERVER
util.AddNetworkString( "cool_addon_client_ready" )
net.Receive( "cool_addon_client_ready", function( len, ply )
-- Send what you need here!
end )
Workaround without networking:
With networking:
Arguments
Example
Prints the name of the player joining.
Output: Player1 joined the game.