GM/PlayerInitialSpawn

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Hook |Name=PlayerInitialSpawn |Parent=GM |Description=Called when the player spawns for the first time. |Realm=Server }} {{Arg |type=Player |name=player |desc=The pl...")
 
m
 
(13 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{Hook
 
{{Hook
|Name=PlayerInitialSpawn
 
|Parent=GM
 
 
|Description=Called when the player spawns for the first time.
 
|Description=Called when the player spawns for the first time.
 +
 +
See {{HookFunction|GM|PlayerSpawn}} for a hook called every player spawn.
 +
 +
{{Note|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 {{ClassFunction|Entity|GetModel}} function will return the default model ("player/default.mdl")}}
 +
{{Warning|Due to the above note, sending {{Lib|net}} messages to the spawned player in this hook is highly unreliable, and they most likely won't be received. See https://github.com/Facepunch/garrysmod-requests/issues/718. A quick and dirty work-around is to delay any sending using {{LibraryFunction|timer|Simple}} with at least 5 seconds delay.}}
 
|Realm=Server
 
|Realm=Server
 +
|Predicted=No
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 9: Line 13:
 
|name=player
 
|name=player
 
|desc=The player who spawned.
 
|desc=The player who spawned.
 +
}}
 +
{{Arg
 +
|type=boolean
 +
|name=transition
 +
|desc=If true, the player just spawned from a map transition.
 
}}
 
}}
 
{{Example
 
{{Example
| Description = Prints the name of the player joining.
+
|Description=Prints the name of the player joining.
| Code = function GM:PlayerInitialSpawn(ply)
+
|Code=function GM:PlayerInitialSpawn(ply)
print( ply:GetName().." joined the server.\n" )
+
print( ply:GetName().." joined the server.\n" )
 
end
 
end
 +
 
-- That way you are overriding the default hook
 
-- That way you are overriding the default hook
 
-- you can use hook.Add to make more functions get called when this event occurs
 
-- you can use hook.Add to make more functions get called when this event occurs
 
local function spawn(ply)
 
local function spawn(ply)
print( ply:GetName().." joined the game.\n")
+
print( ply:GetName().." joined the game.\n")
 
end
 
end
 
hook.Add( "PlayerInitialSpawn", "some_unique_name", spawn )
 
hook.Add( "PlayerInitialSpawn", "some_unique_name", spawn )
| Output = <somebody> joined the game
+
|Output=Player1 joined the game
 
}}
 
}}

Latest revision as of 18:02, 5 November 2019

 GM:PlayerInitialSpawn( )

Contents

Description

Called when the player spawns for the first time.

See GM:PlayerSpawn for a hook called every player spawn.

NOTE

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 ("player/default.mdl")

WARNING

Due to the above note, sending net library messages to the spawned player in this hook is highly unreliable, and they most likely won't be received. See https://github.com/Facepunch/garrysmod-requests/issues/718. A quick and dirty work-around is to delay any sending using timer.Simple with at least 5 seconds delay.

Arguments

Player player

The player who spawned.

Arguments

boolean transition

If true, the player just spawned from a map transition.

Examples

Example

Prints the name of the player joining.

function GM:PlayerInitialSpawn(ply)
	print( ply:GetName().." joined the server.\n" )
end

-- That way you are overriding the default hook
-- you can use hook.Add to make more functions get called when this event occurs
local function spawn(ply)
	print( ply:GetName().." joined the game.\n")
end
hook.Add( "PlayerInitialSpawn", "some_unique_name", spawn )

Output:

Player1 joined the game
Personal tools
Navigation