The HELLAS2XMM survey. VII. The hard X-ray luminosity function of AGNs up to z=4: More absorbed AGNs at low luminosities and high redshifts