Do the trace from player's eyes to first get the player's aim origin as well as checking if it hit an entity.
Keep that first hit entity in a unique variable saved for later.
Then at small intervals, do a find_ent_in_sphere() check with small radius, following the trace line path.
If you find something in that sphere that is not solid, return that entity.
If you don't find anything, return the entity you found in the beginning.