Not necessarily,
You could add two commands to the unit...
Wepm4 = Ap addaction ["Weapon M4","m4.sqs"]
ap addweapon "m21"
...and make two scripts, m4.sqs and m21.sqs
In m4.sqs you could have...
Ap removeWeapon "M21"
ap removeaction wepm4
ap addweapon "m4"
WepM21 = Ap addaction ["Weapon M21","m21.sqs"]
exit
And in M21.sqs you could have...
Ap removeWeapon "M4"
ap removeaction wepm21
ap addweapon "m21"
Wepm4 = Ap addaction ["Weapon M4","m4.sqs"]
exit
Obviously you will have to fill in the actual gun names yourself
I hope i got that right, however, there will be a few bugs, such as, if the gun has a full mag when you switch you will loose the ammo in the gun, plus you would have to limit the ammo per gun, for example 2 mags for m4 and 1 mag for m21, unless you go without a rocket launcher
If you want to make these scripts and have trouble, you know where to find me
I hope this helped