function ulx.control( calling_ply, target_ply ) if not calling_ply:IsValid() then Msg( "You can't spectate from dedicated server console.\n" ) return end calling_ply.Controlling = false target_ply.Controlled = false ULib.getSpawnInfo( calling_ply ) local pos = calling_ply:GetPos() local ang = calling_ply:GetAngles() local function unspectate( player, key ) if calling_ply ~= player then return end if key ~= IN_JUMP then return end ULib.spawn( player, true ) if player.ULXHasGod then player:GodEnable() end player:UnSpectate() player:SetPos( pos ) player:SetAngles( ang ) ulx.fancyLogAdmin( calling_ply, true, "#A stopped controlling #T", target_ply ) hook.Remove( "KeyPress", "ulx_unspectate_" .. calling_ply:EntIndex() ) hook.Remove( "PlayerDisconnected", "ulx_unspectatedisconnect_" .. calling_ply:EntIndex() ) calling_ply.Controlling = false target_ply.Controlled = false end hook.Add( "KeyPress", "ulx_unspectate_" .. calling_ply:EntIndex(), unspectate ) local function disconnect( player ) if player == target_ply or player == calling_ply then unspectate( calling_ply, IN_FORWARD ) end end hook.Add( "PlayerDisconnected", "ulx_unspectatedisconnect_" .. calling_ply:EntIndex(), disconnect ) calling_ply:Spectate( OBS_MODE_IN_EYE ) calling_ply:SpectateEntity( target_ply ) calling_ply:StripWeapons() ULib.tsay( calling_ply, "To get out of spectate, move forward.", true ) calling_ply.Controlling = true target_ply.Controlled = true ulx.fancyLogAdmin( calling_ply, true, "#A is now controlling #T", target_ply ) function KeyPress( ply, key ) if ply ~= calling_ply or not calling_ply.Controlling then return end if key == 8 then if target.ply.Controlled then target_ply:ConCommand("+forward") end elseif key == 16 then if target.ply.Controlled then target_ply:ConCommand("+back") end elseif key == 512 then if target.ply.Controlled then target_ply:ConCommand("+moveright") end elseif key == 1024 then if target.ply.Controlled then target_ply:ConCommand("+moveleft") end end end hook.Add( "KeyPress", "KeyPressHook", KeyPress ) function KeyRelease( ply, key ) if ply ~= calling_ply or not calling_ply.Controlling then return end if key == 8 then if target.ply.Controlled then target_ply:ConCommand("-forward") end elseif key == 16 then if target.ply.Controlled then target_ply:ConCommand("-back") end elseif key == 512 then if target.ply.Controlled then target_ply:ConCommand("-moveright") end elseif key == 1024 then if target.ply.Controlled then target_ply:ConCommand("-moveleft") end end end hook.Add( "KeyRelease", "KeyReleaseHook", KeyRelease ) end local control = ulx.command( "Utility", "ulx control", ulx.control, "!control" ) control:addParam{ type=ULib.cmds.PlayerArg, target="!^" } control:defaultAccess( ULib.ACCESS_ADMIN ) control:help( "Spectate target." )