To attach a hat you need only :
Code:
new Hat = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
engfunc( EngFunc_SetModel, Hat, "models/YourHatModel.mdl" )
set_pev( Hat, pev_movetype, MOVETYPE_FOLLOW );
set_pev( Hat, pev_aiment, PlayerId );