Jump to content
Sign in to follow this  
beta

One-shot M136, scripting only

Recommended Posts

I have made a script that will make all M136s a single-shot weapon. After you have shot it, you cannot access the gear menu (to get around dropping and picking it up again to use it), and once you bring back your rifle, the tube will disappear. The AT round is included with the launcher, so it is not necessary to carry or place "spares". Just the tubes.

Also, this will not interfere with any other missile/rocket launchers.

Potential problems:

- if you die after firing it, other players will probably be able to use it again

- switching to a pistol may not delete the tube

- players can drop an infinite amount of M136 rounds, they are unable to be used however

If there is significant issues, I could try to come up with some fixes for these known problems, but I don't see them being too great an issue for the amount of potential overhead.

With that out of the way ...

This is what you need to get it done:

In your init.sqf (/sqs), place the following code to be executed on all clients:

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

//remove M136 after being fired, require only a launcher

player addEventHandler ["fired", {if (_this select 1 == "M136") then {[_this select 0, _this select 1] execVM "remove_at_launcher.sqf";};}];

player addEventHandler ["animdone", {if (_this select 1 == "amovpknlmstpsraswrfldnon_amovpknlmstpsraswlnrdnon") then {[] execVM "add_at_ammo.sqf";};}];

This adds the required event handlers to all players.

Create a file named "add_at_ammo.sqf", in it place the following code:

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

//Written by beta

//Adds a loaded M136 when player selects it and

//removes the M136 round if deselected

_exit = false;

if (!("M136" in weapons player)) then

{

if (true) exitWith {};

}

else

{

player removeWeapon "M136";

player addMagazine "M136";

player addWeapon "M136";

player selectWeapon "M136";

player switchMove "amovpknlmstpsraswlnrdnon";

//infinite loop

while {true} do

{

//if player is crouching or prone with a rifle

if (animationState player == "amovppnemstpsraswrfldnon" || animationState player == "amovpknlmstpsraswrfldnon") then

{

player removeMagazine "M136";

if (true) exitWith {_exit = true;};

};

if (_exit) exitWith {};

sleep 0.3;

};

};

if (true) exitWith {};

Create another file called "remove_at_launcher.sqf", in it place the following code:

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

//Written by beta

//Remove an M136 launcher after it has been fired

//when player switches to rifle or trys to reload it

_unit = _this select 0;

_weapon = _this select 1;

_exit = false;

//infinite loop

while {true} do

{

//if prone, crouching, or reloading launcher

if (animationState _unit == "amovppnemstpsraswrfldnon" || animationState _unit == "amovpknlmstpsraswrfldnon" || animationState _unit == "launcherreloadkneel") then

{

_unit removeWeapon "M136";

if (true) exitWith {_exit = true;};

};

_obj = nearestObject [_unit, "WeaponHolder"]; //get nearest dropped item

deleteVehicle _obj; //delete dropped item until switched back (removes gear dialog)

if (_exit) exitWith {};

sleep 0.3;

};

if (true) exitWith {};

Once all of that is done, it is ready to play. All players in the mission will now have one-shot AT weapons (including OPFOR players).

I have no plans to make this work with AI, I'll wait for ACE for that smile_o.gif

EDIT: Updated code to fix problems of incompatibility with other shoulder fired missiles/rockets.

EDIT 2: Fixed weapons check code to be more efficient, simply checks if there isn't a M136, instead of the presence of all others.

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  

×