Spectator Team

I’m attempting to get it to work but for the love of me I can not get it working I’ve tried all this stuff like


if ply:Team() == "TEAM_SPEC" then
ply:Spectate(OBS_MODE_ROAMING)
return
end

But that just dosen’t even let me go into the team at all.

If anyone could help really I want the team to be-able to swap between each player.

Player:Team()

That dosen’t really help.

Read the page…

It returns an integer not a string.

Unless he’s set the team indexes to variables like TEAM_SPEC = 1 so it’s easier to remember, in which case he meant [lua]if ply:Team() == TEAM_SPEC then
ply:Spectate(OBS_MODE_ROAMING)
return
end[/lua]

Alright but how do I make the player acctualy spectate another? And like be-able to switch between players with left mouse click?

This is what I use. Seems to be quite effective[lua]local modes = { OBS_MODE_ROAMING, OBS_MODE_CHASE, OBS_MODE_IN_EYE }

hook.Add( “KeyPress”, “SpectatorControls”, function( ply, key )
if ply:Team() ~= TEAM_SPECTATOR then return end

if key == IN_ATTACK then 
	ply.specply = (ply.specply +1) % (#team.GetPlayers( TEAM_GUNNER ))
	ply:SpectateEntity( team.GetPlayers( TEAM_GUNNER )[ply.specply +1] )

elseif key == IN_ATTACK2 then

	ply.specply = (ply.specply -1) % (#team.GetPlayers( TEAM_GUNNER ))
	ply:SpectateEntity( team.GetPlayers( TEAM_GUNNER )[ply.specply +1] )

elseif key == IN_JUMP then
	ply.specmode = (ply.specmode +1) % #modes
	ply:Spectate( modes[ply.specmode +1] )

end

end )[/lua]

[editline]23rd December 2013[/editline]

Then this is my function to set a player to spectator[lua] self:SetTeam( TEAM_SPECTATOR )
self:StripWeapons()
self:SetNWInt( LEVEL, 1 )

if #team.GetPlayers( TEAM_GUNNER ) > 0 then
	self:Spectate( OBS_MODE_IN_EYE )
	self:SpectateEntity( team.GetPlayers( TEAM_GUNNER )[1] )
	self.specmode = 3
else
	self:Spectate( OBS_MODE_ROAMING )
	self.specmode = 1
end
	[/lua]