GM/PlayerSpawn

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Corrected spelling mistake.)
(player_spawn alternative)
Line 1: Line 1:
 
{{Hook
 
{{Hook
|Description=Called whenever a player spawns, including respawns.
+
|Description=Called whenever a player spawns, including respawns. See the [[Game_Events|player_spawn gameevent]] for a shared version of this hook.
  
{{Warning|By default, in "base" derived gamemodes, this hook will also call {{HookFunction|GM|PlayerLoadout}} and {{HookFunction|GM|PlayerSetModel}}, which may override some of your calls from hooking to this hook using the {{Lib|hook}}, such as {{ClassFunction|Entity|SetModel}}.
+
{{Warning|By default, in "base" derived gamemodes, this hook will also call {{HookFunction|GM|PlayerLoadout}} and {{HookFunction|GM|PlayerSetModel}}, which may override your {{ClassFunction|Entity|SetModel}} and {{ClassFunction|Player|Give}} calls. Consider using the other hooks or a 0-second timer.}}
 
+
See function definition for GM:PlayerSpawn in base gamemode.}}
+
 
|Realm=Server
 
|Realm=Server
 
|Predicted=No
 
|Predicted=No

Revision as of 19:44, 10 August 2018

 GM:PlayerSpawn( )

Contents

Description

Called whenever a player spawns, including respawns. See the player_spawn gameevent for a shared version of this hook.

WARNING

By default, in "base" derived gamemodes, this hook will also call GM:PlayerLoadout and GM:PlayerSetModel, which may override your Entity:SetModel and Player:Give calls. Consider using the other hooks or a 0-second timer.

Arguments

Player player

The player who spawned.

Examples

Example

Prints a message when a player spawns.

function GM:PlayerSpawn( ply )
    MsgN( ply:Nick() .. " has spawned!" )
end

Output:

Player1 has spawned!

Examples

Example

Prints a message when a player spawns using a hook.

local function spawn( ply )
	print( ply:Nick().. " has spawned!.")
end
hook.Add( "PlayerSpawn", "some_unique_name", spawn )

Output:

Player1 has spawned!
Personal tools
Navigation