Sick, this is a quite interesting topic, while it is a bit offtopic into this particulat topic. To do not let it die, you might open an individual topic to discuse call, spawn and execVM advantages and disadvantages and risks, as well as possible corrections to the BIKI which might apply also to the current OFPEC Comref.
Now back on topic:
Sparticus, I understand _firer is the vehicle which is firing at the target, and it is armed with a single "M2".
Didnt check it, but the line of sight check added here should work.
private[....,....,...,...., "_los", "_losok", "_posasl", "_distance", "_wdir"];
.....
.....
While {alive _target} do
{
_ammo = _firer ammo "M2";
_burst = _ammo - 20;
_los = "logic" createVehicleLocal [0,0,0];
while {(_ammo > _burst) && (alive _target)} do
{
_gunner dotarget _target;
Sleep 1;
WaitUntil{unitready _gunner};
_distance = _firer distance _target;
_losok = true;
_posasl = [getPosASL _firer select 0, getPosASL _firer select 1, (getPosASL _firer select 2) + 2];
_wdir = _firer weaponDirection "M2";
for [{_i=0},{(_i < _distance) && (_losok)},{_i = _i + 10}] do
{
_los setPosASL [(_posasl select 0)+(_wdir select 0)*_i,(_posasl select 1)+(_wdir select 1)*_i,(_posasl select 2)+(_wdir select 2)*_i];
if ((getPos _los select 2) < 0.1) then
{
_losok = false;
};
};
if (_losok) then
{
_firer action ["useWeapon", _firer, _gunner, 0];
_ammo = _firer ammo "M2";
};
sleep 0.18;
};
deleteVehicle _los;
sleep 1;
};