I was given a 2005 ram 1500 hemi. But they said it needs an engine.150,000 miles on 2005 Dodge Ram 1500

It will start an run as long as foot is on gas. It has a loud and sometimes not so loud tick on passenger side of engine. It runs very rough, check engine lights for running to rich are on. Mechanic changed the sensor temperature in airflow to no help. All help with this is greatly appreciated.

Asked by for the 2005 Dodge Ram 1500
possible head gasket check the compression