Ah, I see..
So then you need to check whether the unit has the mags left and then check that ammo too..
So, first you check whether the unit has the mags you want or not and if not, exit and don't go to the ammo check yet, something like:
#checkmags
? (primaryWeapon player) in (magazines player): exit
goto "checkammo"
#checkammo
? (player ammo (primaryWeapon player)) == 0: goto "out"
exit
No guarantees whatsoever...
Of course that method requires that the magazine is named the same as the weapon itself, like "M16"...