Spectating

I want to add something so when players die, they switch team and get set to free roam spectator mode. I tried the code beneath. Can you help me?
[LUA]function GM:PlayerSpawn( ply )
if ply:Team() == 4 then
ply:StripAll()
ply:Spectate(OBS_MODE_ROAMING)
return
end
end[/LUA]

You can start by changing function name to PlayerDeath

Also, instead of Roaming, you can hook into CalcView when they are spectating and set the view to a specific player instead of allowing free roam, then add additional controls which lets them jump to different players.

I tried PlayerDeath and It kind of changed something. Im still using a playermodel and I can’t freeroam. It’s more like normal walking around with jumping but when you just normally walk on the floor, you kind of rubberband a little bit. Like going up a little and down a little and repeat.

Make sure on function GM:PlayerDeathThink( Player ) you return false when in spectate mode so they can’t respawn.

Ok that worked way better but it seems that gravity still kind of pulls you down and to go up in spectator, you need to look at the floor and hold s.

There are a few more hooks I think.

You may also need this one:
[lua]function GM:PlayerSelectSpawn( Player )

end[/lua]

Which hooks are you using so far?

I use: PlayerSpawn, PlayerDeath, PlayerDeathThink, PlayerInitialSpawn, PlayerSelectSpawn to set spectator when they first join. That should be all the functions; I had a similar issue with the sluggish or gravity movement until I utilized all methods above.

I fixed it! I forgot to use an argument on the PlayerDeathThink to return false if ply:Spectate(didn’t put argument here)