Spectator Team. Deathrun

So I’ve recently started to host a Deathrun server. I’ve occurred a few problems. One of these is the spectator team.

So what i want is a spectator team that users can join individually. And be moved to if AFK for an amount of time.

I’ve looked in the shared.lua and all i see is


function GM:CreateTeams()    TEAM_DEATH = 2
    team.SetUp( TEAM_DEATH, "Death", Color( 180, 60, 60, 255 ), false )
    team.SetSpawnPoint( TEAM_DEATH, "info_player_terrorist" )


    TEAM_RUNNER = 3
    team.SetUp( TEAM_RUNNER, "Runner", Color( 60, 60, 180, 255 ), false )
    team.SetSpawnPoint( TEAM_RUNNER, "info_player_counterterrorist" )


    team.SetUp( TEAM_SPECTATOR, "Spectator", Color( 125, 125, 125, 255 ), true )
end

The TEAM_SPECTATOR i do not understand. No where on the tab list is there a team called spectator and there is no way to join it.

[lua]
ply:SetTeam(TEAM_SPECTATOR)
ply:Spectate(OBS_MODE_ROAMING)
[/lua]

Is how the gamemode sets spectator.

I’m completely lost. How do i make it so that users can set their own team to spectator?

You’d have to set up either commands or a menu.

Are you able to link something that would work?

If you’re asking what I think, look at the PlayerSay wiki page and what has already been posted

I’ve looked and It’s unfortunately not what i look for. What I’m asking is for a way to users to just change their team to spectators.



hook.Add( "PlayerSay", "PlayerSayExample", function( ply, text, team )
	if ( string.sub( text, 1, 4 ) == "/afk" ) then
		ply:SetTeam(TEAMNAME)
	end
end)


???

Oh shit. I’m really stupid.

Where should put this code?

Serverside, so throw it inside init.lua or autorun/server

Just as a thing though, that might not be enough. You may want to also kill the player silently and change their observation mode

How? :blush:

EDIT : I’ve added to command, And it works sort of, It moves me to the spectator team. But i as you said i need to “You may want to also kill the player silently and change their observation mode”

Thank you very much for this, It cleared up most things.

For some reason the user still has the crowbar in his hand, He’s unable to use it but is there a way to remove it?

Just as a tip, which should help you out in future, when you come across an issue like this, google what you’re trying to do or a few important key terms along with gmod/facepunch on the end

Usually you can find help before someone replies and helps you become self-efficient, which is always good! Here’s an example:

You can use that link, or this one if the player has more than one item,

[lua]ply:StripWeapons()[/lua] will remove his crowbar and any other weapons he may have

[editline]1337[/editline]
Niandra of course you ninja’d me

Thank you all for the help!

It’s working now.