Mad Pup,
You can simplify the whole thing to two scripts (init.sqs and checker.sqs). Also, if checker.sqs is more general it will work with any unit and any two targets and any weapon/ammo type you give him. Here I use the magazines command to determine when he is out of magazines. Also, note that I added a short delay in the loop. It is good practice to put some kind of delay in repeating loops to help reduce lag. For simple missions with just one or two scripts running it is not much of an issue, but if you make more complex missions where many scripts might be running at the same time, loops with no delay can cause lag.
init.sqs:
removeallweapons eastm
eastm addmagazine "ak47"
eastm addmagazine "ak47"
eastm addweapon "ak47"
[eastm, cap1, cap2] exec "checker.sqs"
;this will execute the script checker.sqs sending eastm, cap1 and cap2 as parameters to that script
Checker.sqs:
_man = _this select 0
_targ1 = _this select 1
_targ2 = _this select 2
;these above lines draw out the parameters sent to the script and sets local variables representing each parameter
_targ = _targ1
;this line sets the local variable _targ to be equal to _targ1
#resetTarg
;this is a label, labels can be used in scripts with the goto command to make the script jump to new locations or repeat loops
_man doWatch _targ
_man doFire _targ
;the _man (in this case eastm) will watch the _targ and fire at the _targ (the _targ starts as cap1 but changes later to cap2)
#loop
? ! alive _targ && _targ == _targ1 : _targ = _targ2; goto "resetTarg"
;this conditional will make the script jump to reset _targ to become _targ2 (cap2) when _targ1 (cap1) is dead
~ .01
? count magazines _man > 0 : goto "loop"
;this loop repeats until the man is out of ammo
? _man == player : hint format ["%1.... you are out of ammo. Bye......", name _man]
;send hint when human player is out of ammo
exit
The reason one makes a script with local variable is so the script is more general. If you only used global variables, then you would have to make a new script for every group of different units running the script. Using a local variable script, one script can work for many units with different names, even several units can run the same script at the same time and the multiple cases of the script running will not have any effect on each other, because the local variable stay local to the script. So, this one script can check the ammo status of eastm, eastm1, eastm2, eastm3 etc. And each of these units can be shooting at cap1, cap2, cap3, cap4, etc.
As you play around with scripting you will learn ways to make them even more general. You can even send parameters to scripts that are unique commands that the script can execute using the call command. Using arrays in scripts allow even greater flexibility. Keep trying new things and examine other scripts to see what others have done (download stuff from the editors depot and examine the scripts that are used in those resources. You can learn from those and sometimes even figure out better ways of scripting things than the original author.