Hi Ladies and Gentlemen,
Yes that's right "M16" is not an ArmA weapon but OFP.
You must check your execution command of the script. You can't launch a .sqf script like a .sqs by a simple exec.
Something like
player exec myscript.sqf makes ArmA to execute it like a .sqs then all specific .sqf commands and syntax will return errors.
A good execution will be
script = [ ] execVM "myscript.sqf"where arguments will be passed through the [] if needed.
or
whatever = [ ] execVM "myscript.sqf"
firstnameofyourgirlfriend = [ ] execVM "myscript.sqf" Otherwise try this:
private ["_compWeap","_loop","_MNU"];
//make list of bayonette compatible weapons
_compWeap = ["M16A2","M16A2GL","M16A4","M16A4_ACG","M16A4_ACG_GL","M16A4GL","M4","M4A1GL","M4A1","M4AIM","M4GL"];
//now the loop
for [{_loop=0},{_loop<1 or alive player},{_loop=_loop}] do
{
if ((primaryweapon player) in _compWeap and (vehicle player)==player) then
}
_MNU = player addaction ["Attach Bayonette","bayonette.sqf"];
}
else
{
player removeaction _MNU;
};
sleep 0.5;
};
I've changed the loop "while" by a loop "for" because loops "while" are limited to 10,000 rounds until the loop exit by itself. In your case with sleep 0.5 sec makes 5,000 sec (~ 1h30). I replaced MNU by _MNU because here's no reason to create a global variable.
I put all M16 and M4 weapon versions in the _compWeap array but i'm not sure if the versions having grenade launcher allow a bayonette down the muzzle in reality. Could be dangerous ...
PrimaryWeapon doesn't return the current active weapon (in hands) but what's loaded in 1st slot. Then if your soldier is not supposed to attach a bayonette on a handgun may be you should start your bayonette.sqf by:
player selectWeapon (primaryweapon player);
That's just couple of ideas ...