Garry's Mod Wiki

Revision Difference

GM:PlayerSpawn#511150

<function name="PlayerSpawn" parent="GM" type="hook">⤶ <ishook>yes</ishook>⤶ <description>⤶ Called whenever a player spawns, including respawns.⤶ ⤶ See <page>GM:PlayerInitialSpawn</page> for a hook called only the first time a player spawns.⤶ ⤶ See the [player_spawn gameevent](/gmod/Game_Events) for a shared version of this hook.⤶ ⤶ <warning>By default, in "base" derived gamemodes, this hook will also call <page>GM:PlayerLoadout</page> and <page>GM:PlayerSetModel</page>, which may override your <page>Entity:SetModel</page> and <page>Player:Give</page> calls. Consider using the other hooks or a 0-second timer.</warning>⤶ </description>⤶ <realm>Server</realm>⤶ <predicted>No</predicted>⤶ <args>⤶ <arg name="player" type="Player">The player who spawned.</arg>⤶ <arg name="transition" type="boolean">If true, the player just spawned from a map transition. You probably want to not touch player&#x27;s weapons if this is set to true from this hook.</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>Prints a message when a player spawns.</description>⤶ <code>⤶ function GM:PlayerSpawn( ply )⤶ MsgN( ply:Nick() .. " has spawned!" )⤶ end⤶ </code>⤶ <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output>Player1 has spawned!</output>⤶ ⤶ </example>⤶ ⤶ ⤶ <example>⤶ <description>Prints a message when a player spawns using a hook.</description>⤶ <code>⤶ local function spawn( ply )⤶ print( ply:Nick().. " has spawned!.")⤶ end⤶ hook.Add( "PlayerSpawn", "some_unique_name", spawn )⤶ </code>⤶ <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output>Player1 has spawned!</output>⤶ ⤶ </example>