Garry's Mod Wiki

GM:PlayerSelectSpawn

  Entity GM:PlayerSelectSpawn( Player ply, boolean transition )

Description

Called to determine a spawn point for a player to spawn at.

The spawn point entity will also impact the player's eye angle. For example, if the entity is upside down, the player's view will be as well.

Arguments

1 Player ply
The player who needs a spawn point
2 boolean transition
If true, the player just spawned from a map transition (trigger_changelevel). You probably want to not return an entity for that case to not override player's position.

Returns

1 Entity
The spawn point entity to spawn the player at

Example

Find a random spawn point

hook.Add("PlayerSelectSpawn", "RandomSpawn", function(pl) local spawns = ents.FindByClass("info_player_start") local random_entry = math.random(#spawns) return spawns[random_entry] end)