Spectator Mode

How would I place a player that has died in spectator mode?

In the base game-mode there is a useful function:

	Name: gamemode:PlayerSpawnAsSpectator( )
	Desc: Player spawns as a spectator
function GM:PlayerSpawnAsSpectator( pl )

So, using PlayerDeath hook with arguments for ( victim, weapon, killer ) you can set the victim to spawn as spectator:

hook.Add( "PlayerDeath", "DeathEqualsSpectator", function( _victim, _w, _killer )
	hook.Call( "PlayerSpawnAsSpectator", GAMEMODE, _victim );
end );

You may need to do more depending on your game-mode such as modify PlayerDeathThink, etc to prevent them from respawning as a player.

Here’s an example of how to make a spectator system with essentially everything needed to force a player to join the game as a spectator:

Hopefully these tutorials and information helps. As always, to view the Lua from any of my tutorials to enable copy/pasting ( HTML doesn’t copy/paste well in terms of HTML / CSS Highlighted Lua ), remove .html from the url.