Hi guys,
i'm the one working to implement bayonet in cw mod.
There is no difficulty into implementing a working melee attack (bayonet or strokegun or anything else).
The weapon must have two muzzles : one with classical ammo magazine, and the other with strokegun one.
class yourweapon: riffle
{
muzzles[]={"classicalmuzzle","strokegunmuzzle"};
class classicalmuzzle: weaponmag
{
magazines[]={"weaponmag","strokegun modified"};
ammo="whatyouwant";
};
class strokegunmuzzle: weaponmag
{
magazines[]={"strokegun modified"};
ammo="bayonetAmmo (like "strokegunhit")"
};
};
The AI (even with ammo left) will chose between the two muzzles depending of the efficiency of it at given distance. A few things must be known about :
Ammo : the ammo of the strokegun mag is called strokegunhit. The strokeguhit ammo must be modified to be more effective at short range than the classical ammo of the gun (through "hit" and through "min/med/maxRangeProbab" for each range.)
The mag for strokegunhit (ie "strokegun") : the ofp one has a very low priority (primary=false), so just write primary=10. An other strange thing i learnt is that the initspeed must'nt be set to 0 (as ofp one). So i set "initSpeed=300" and it works.
Finally, if you wanna see bayonet appearing when soldiers choses close combat muzzle, just write in the config of the strokegun mag :modelSpecial="name of the p3d of the gun with bayonet". I don't like that (not realistic), but Taiwan Workshop did it.
Finally, I think modern weapons are very efficient, even at short range (even wwii ones), so maybe by doing this, AI will still prefer shooting than close combat. It works well with civil war guns, because efficiency of riffles at short range was not that good (and soldiers were stressed with reloading their gun in front of enemies). So maybe with modern weapons, a scripted attack (and laggy one through nearestobject command) is more effective. But anyone can chose how he wants to mod.