Jump to content
Sign in to follow this  
Inkompetent

Single shot M136

Recommended Posts

Cheers! I've been trying to make the M136 as a single shot, disposable weapon as it is IRL. But somewhere on the way I fail.

Here are the two essential parts of my script:

config.cpp

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class CfgPatches

{

class Real_M136

{

units[] = {};

weapons[] = {"M136"};

requiredVersion = 0.1;

requiredAddons[] = {"CAWeapons","CAAir"};

};

};

class cfgWeapons

{

/*external*/ class Launcher;

class M136 : Launcher {

class Eventhandlers

{

fired = "_this execVM ""\Real_M136\Scripts\realm136.sqf""";

};

};

class M136Used : M136 {

displayName = "M136 Launcher (Used)";

magazines[] = {FakeMagazine};

};

};

realm136.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0;

_weapon = _this select 2;

if ((_weapon in ["M136"]) && (local _unit)) then {

_weaponused = switch (_weapon) do {

case "M136":{"M136Used"};

};

sleep 0.5;

_unit removeWeapon _weapon;

_unit addWeapon _weaponused;

_unit selectWeapon _weaponused;

_unit action ["DROPWEAPON",_unit,_weaponused];

};

I managed to get the above to start when the eventhandler was specified for a unit class. But since that will only work with the units that have that eventhandler added I wanted to make it actual for the weapon itself, thus compatible with other units.

When I did this however I can't get it to work anymore. Is it because the "_this select 0" and so are directed at other things since I'm running the eventhandler from the weapon's class, or what could it be?

PS: Yes, the script is made to be modular so that if one has an M72 LAW, RPG-22 or whatever they can be added too.

Share this post


Link to post
Share on other sites

I have used and modified his script in trying to make a one-shot M136. The fired event handler worked great from the weapon.

Share this post


Link to post
Share on other sites

How about if you added it to a gamelogic that then added the eventhandler to all the units used in that particular mission (its an arsey way of doing it, but its a lot easier than adding the code to each unit's init manually). That way all mission makers need to do if they want to use the one-shot M136 is just add the gamelogic and it will automatically be added to everyone's init.

Share this post


Link to post
Share on other sites

The addon changes the CAManBase class to have it's init start the script. So the init field is taken care of automatically.

EDIT: The init script thingy works fine in: offline, hosting your own MP, but has sketchy working when a client is on a dedicated server. Some of the units worked while others never got their M136_Hidden magazine in the mail. More testing is required, perhaps a more reliable (extended eventhandlers mod?) or mundane method of making sure all AT-4 /not used/ weapon holders are given shiny magazines automatically.

The weapon swap out script works beautifully as always.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×