Alright, I finally played around with the script in-game, and it's great! Looks awesome (with the T80 at least), and it works like a charm.
I ran into one bug, although I doubt it can be fixed: when I am in the gunner seat and I use the script, the smoke will always pop out of the front of the tank (not the turret). This means a player gunner cannot control the direction the smoke gets fired. Again, I suspect an OFP 'feature' at work, but perhaps try having the vehicle's gunner fire, instead of the vehicle itself.
Actually, there is another, major bug in the script. Currently, if you use the smoke action, then immediately fire some other weapon, that other weapon will also fire smoke for a second or so. Its really bad with the MG.
This problem occurs because of the 1 second delay between when the EH is added and when it is removed. You also remove the first EH added to the tank, whether or not that was the EH added by this script. So if a mission editor was running some other fired EH on that tank, then this script wouldn't work properly at all, and would mess up that other EH.
------------------------------
The best way to eliminate both of these problems is with a handy little trick that I've been using more and more in scripts. Basically, you set up a self-removing EH. The trick comes from using a combination of the format command, as well as the way that EH's index themselves when added and removed. Essentially you just get the index of the EH you will be adding, and then you put that number into the EH's code via the 'format' command:
First off, getting the EH's index. When you add the first EH of a type to an object, it starts with idx 0. The next added EH then gets idx 1, and so on. However, when you REMOVE an EH at, say, idx 1, then all EHs of idx > 1 have their idxs REDUCED by one. Contrast this to action idxs, which always stay the same, even after removing other actions.
So, to get the index of an EH we are about to add, we can just add an EH, store the returned idx, then remove that EH:
_idx = _tank addeventhandler ["fired", {}]
_tank removeEventHandler ["fired",_idx]
Okay, now we have the index of the NEXT EH we are about to add. So now we can 'imbed' that number into that EH we are going to add, via the format command. The EH in the following example will make a hint appear, and then remove itself IMMEDIATELY:
_tank addeventhandler [ "fired", format[{hint "ping!"; (_this select 0) removeEventHandler["fired", %1]}, _idx] ]
Notice that the 'format' command will FIRST format the code string in the EH, and will replace the %1 with the value of the variable _idx.
So, as long as no EHs are removed after we add this EH, the EH will remove itself right as soon as it fires. Note that if an EH was removed before the one we just added goes off, then the _idx we 'passed' to the EH might no longer be valid (because of the way OFP decrements all indexes after removing EHs). This means one should only use this trick when you know there will only be a short delay between when the EH is added and when it is removed. In your case, this will work perfectly.
----------------
So, for your script, it could look like this:
; if the tank has no mg ammo it gets some
_removeMag = false
? (_tank ammo _mg) < 1 : _tank addMagazine _mg; _removeMag=true
; this gives the tank an EH from which we can extract the direction of the turret
_tank addEventHandler ["fired",{[_this select 0, %1, %2] exec "smoke2.sqs"}, _idx, _removeMag]]
~0.01
; now make the tank fire silently so the EH can pick up the direction
0 fadeSound 0
0 fadeMusic 0.5
_tank selectWeapon _mg
_tank fire _mg
exit
Note that I also imbedded the variable _removeMag into the EH, so the magazine is removed exactly once the weapon is fired. The following parameters will be passed to smoke2.sqs:
[tank, EH idx, removeMag?]
I hope that all made sense. It might seem like a complicated workaround, but it is actually fairly simple, and once you understand how it works, you can suddenly do a whole lot more with EHs.