Move to spec on afk?

I’m using the ulx AAFK script and I’m trying to make it move the player to spectate once they are flagged as afk. This is the part that flags them as afk:


        if pl.afkc >= GetConVarNumber( "ulx_afk_flagminutes" ) then
            if pl.afk == false then
                pl.afk = true
                ulx.fancyLogAdmin( pl, "#A went AFK!" )
                ULib.tsayColor(_, Color(0,0,0,255), "[AAFK] ", team.GetColor(pl:Team()), pl:Nick(), Color(255,255,255), " went ", Color(255,0,0,255), "AFK.")
            end
        end

In the murderer game mode it uses a concommand “mu_movetospectate” to move the player to spectate. So I tried to use that command inside the aafk script, but it’s not working:


       
if pl:Alive() && pl.afk == true then
        RunConsoleCommand("mu_movetospectate", pl:EntIndex())
end

is this structure all wrong? Am I calling the right things?

Use
[lua]pl:Nick()[/lua]
Instead of
[lua]pl:EntIndex()[/lua]

Tried that. It only flags them as afk it seems.

Where have you got the second bit of code placed? Try putting
[lua]RunConsoleCommand(“mu_movetospectate”, pl:EntIndex())[/lua]
under
[lua]ULib.tsayColor(_, Color(0,0,0,255), "[AAFK] ", team.GetColor(pl:Team()), pl:Nick(), Color(255,255,255), " went ", Color(255,0,0,255), “AFK.”)[/lua]

Here’s how to make a player become spectator when they first join a server:
https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/spectating_players_system.lua.html

To make them become spectator in the middle of a “round”, do something like this ( PlayerDeathThink should prevent the player from spawning, ):

This should work:


// Spectator mid-round
local META_PLAYER = FindMetaTable( "Player" );
function META_PLAYER:MoveToSpectator( )
	if ( !IsValid( self ) ) then return false; end

	self:SetTeam( TEAM_SPECTATOR );
	self:Spectate( OBS_MODE_ROAMING );

	if ( self:Alive( ) ) then self:KillSilent( ); end
end

I only need it to move them to spec once flagged ask afk by the afk system.

Would something like this work?


        if pl.afkc >= GetConVarNumber( "ulx_afk_flagminutes" ) then
            if pl.afk == false then
                pl.afk = true
                ulx.fancyLogAdmin( pl, "#A went AFK!" )
                ULib.tsayColor(_, Color(0,0,0,255), "[AAFK] ", team.GetColor(pl:Team()), pl:Nick(), Color(255,255,255), " went ", Color(255,0,0,255), "AFK.")
                pl:SetTeam(TEAM_SPECTATOR)
            end
        end

/E Yeah this new script did something. It removed the player from the team, but didn’t put them in the spectators team. Either way, I think I can figure it out myself from here. Thanks for the help everyone.