I'm not sure I understand everything you want, but as a start, you could take a look at this previous related posting:
[
afni.nimh.nih.gov]
<[
afni.nimh.nih.gov];
The script there takes a list of 0's and 1's to identify sub-bricks to include in an output dataset. It does this by generating a sub-brick list that is then used as part of the dataset name. In your case, you could use 3dTstat to combine the specified subbricks into a an average dataset for each event type. Basically, you end up doing something like this for each type :
3dTstat -mean -prefix avg_typeA dset+orig'[1,3,5]'
If you want to then combine the averaged types back into a single dataset, you could do that with
3dTcat -prefix avg_all_types avg_type?+orig.HEAD
You can also take a look at this previous posting that also discusses a similar question.
[
afni.nimh.nih.gov]
<[
afni.nimh.nih.gov];
Hope these help.