Jump to content
Sign in to follow this  
djdeluxe76

Add action Enable M107 tracer ammo to action menu

Recommended Posts

Hi all,

I am trying my first steps as mission creator, in that I want to create a sniper training mission.

I have it all working quite nicely so far, I've got briefing, triggers and scripts that deal with task and objective state etc.

What I want to do now is to add an action to the MOUSEWHEEL menu that lets you choose from using tracer ammo for the M107.

As my mission will be centered around A.C.E. v2 v1.5b sniping interface, preferably using tracers from A.C.E. v2 (if vanilla doesn't have them) as to eliminate another mod dependency.

I have found addAction but I can't seem to find out the class name regarding tracers so I can addMagazine them in the script that's bound to the action.

Does anyone know what I need to make this possible from the action menu?

Thanks for reading!

DJ

Share this post


Link to post
Share on other sites

ACE 2 Ammo Classlists

I believe that the above website has all the class names for the ACE ammo. The one that you are looking for is like 5 down from the top of the list. I don't think you need to use the addaction thing, you just need to add the magazine to the unit and the action menu should automatically add the option to reload the tracer mag. However, as I do not use ACE, I cannot be sure. This is my best guess though. Below has the classlists for ammo, weapons, infantry, vehicles, etc.

ACE 2 Classlists

Share this post


Link to post
Share on other sites

That class list sure is handy! I didn't know about that.

Thanks for providing me with the link.

I did what you suggested and it adds the tracer ammo just fine but it doesn't make it optional and also not via any action menu commands.

It seems then some scripting is needed after all...

Do you know how I can replace magazines of a unit, but just the ones of a specific type?

I mean I'd need a command like "magazines" that accepts a string as parameter and returns an array with all the mags whose name/type matched that string.

I suspect some form of stringing together for or forEach with count or somesuch?

The biki seems a bit shallow on this end.

Again thanks for helping :)

Share this post


Link to post
Share on other sites

My god! I can't believe it... I spent the better part of a day and night

trying to get around a problem in my toggle tracers script.

Only to ultimately realise that all that was wrong was writing a capital M in a string instead of a small letter m.

I mean, the scripting language is pretty much case insenstive for all its commands...

but of course string comparisons of class names aren't - should have known.

You wouldn't believe the amount of stuff I tried - the scripter in me died a few times over...

but, nevertheless, learning a lot from this odyssey.

Anyway here's my fSwapMagazines.sqf script in case someone finds it useful:

// 
//  Swap Magazines Script v0.01
//
//  Copyright 2010, djdeluxe76
//
//  License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
//  See http://creativecommons.org/licenses/by-sa/3.0
//  
//  What Is It
//
//  Makes it easier to swap just the magazines of a certain class name on a unit
//  for magazines of another class name, either all of them or up to a specified limit.
//
//  Usage
// 
//  1. Add script to mission folder.
//
//            -Either-
// 
//  2a. Compile this script in your init.sqf like so:
//      f_SwapMagazines = compile (preProcessFileLineNumbers "fSwapMagazines.sqf");
// 
//      Then call it in another script, trigger or init like so:
//      nul = [<args>] call f_SwapMagazines;
// 
//      Where <args> is a placeholder for the script's arguments, 
//      which are explained in detail below.
//
//             -Or-
//
//  2b. Use execVM like for example:
//      nul = [<args>] execVM "fSwapMagazines.sqf";
//
//  Arguments
// 
//      unit        object      the unit whose mags should be swapped
//      old ammo    string      class name of the current ammo
//      new ammo    string      class name of the new ammo
//      limit       number      how many should be swapped, or 0 for all of them
//      reload      bool        automatically reload after swapping the mags?
//
//

private ["_c", "_mc", "_max", "_lim", "_doReload"];

_unit = _this select 0;
_oldAmmo = _this select 1;
_newAmmo = _this select 2;
_lim = _this select 3; // limit
_doReload = _this select 4;

if (isNil "_unit") then { _unit = player; };
_mc = count magazines _unit;

if (_lim == 0) then {
   _lim = 1000;
};
if (_lim > _mc) then { 
   _lim = _mc; 
};

if (isNil "toggle") then {toggle = 1;};
if (toggle == 1) then {
   toggle = 0;
} else {
   _oldAmmo = _this select 2;
   _newAmmo = _this select 1;
   toggle = 1;
};

_max = 0;
_c = 0; // counter
if (_oldAmmo in (magazines _unit)) then {
   // hint formatText ["%1 has ammo type %2", _unit, _oldAmmo];
   // find out how many mags of type
   {
       if (_x == _oldAmmo) then {
           _c = _c + 1;
       };
   } forEach magazines _unit;
   // determine what is smaller _lim or _c 
   if (_c < _lim) then {
       _max = _c;
   } else {
       _max = _lim;
   };
   // remove all mags of type
   for "_i" from 1 to _max do {_unit removeMagazine _oldAmmo;};
   // add mags of other type
   for "_i" from 1 to _max do {_unit addMagazine _newAmmo;};
   // hint formatText ["magazines = %1, count = %2", (str (magazines _unit)), _max];
   if (_doReload) then {reload _unit;};
} else {
   if (_newAmmo in (magazines _unit)) then {
           // find out how many mags of type
           {
               if (_x == _newAmmo) then {
                   _c = _c + 1;
               };
           } forEach magazines _unit;
           // determine what is smaller _lim or _c 
           if (_c > _lim) then {
               _max = _lim;
           } else {
               _max = _c;
           };
           // remove all mags of type
           for "_i" from 1 to _c do {_unit removeMagazine _newAmmo;};
           // add mags of other type
           for "_i" from 1 to _c do {_unit addMagazine _oldAmmo;};
           // hint formatText ["magazines = %1, count = %2", (str (magazines _unit)), _max];
           if (_doReload) then {reload _unit;};
   } else {
       hint formatText ["No mags found, neither %1 nor %2", _oldAmmo, _newAmmo];
       sleep 1;
       hint formatText ["magazines _unit = %1", str magazines _unit];
       sleep 2;
   };
};

And then I have the fToggleTracerAmmo.sqf script for the action:

private ["_args", "_unit", "_normalAmmo", "_tracerAmmo", "_swapLimit"];

_args = _this select 3;

_unit = _args select 0;
_normalAmmo = _args select 1;
_tracerAmmo = _args select 2;
_swapLimit = _args select 3;
_reload = _args select 4;

nul = [_unit, _normalAmmo, _tracerAmmo, _swapLimit, _reload] execVM "fSwapMagazines.sqf";

which as one can see at line 2 is intended for the addAction extended syntax, for example in my init.sqf:

waituntil {!isnull player};
waituntil {time > 0};

toggleAction = player addAction ["Toggle tracer ammo", "fToggleTracerAmmo.sqf", [player, "10Rnd_127x99_m107", "ACE_10Rnd_127x99_T_m107", 0, true], 1, false, true, "", "true"];

Works quite nicely as in that it will swap the exact amount of mags

that I had before with the same amount of tracer mags.

To my mission this is somewhat crucial since the mission failed condition

checks to see if you have hit all targets before running out of M107 bullets.

Again thanks for all the help!

DJ

Edited by djdeluxe76
fixed a typo in the script

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  

×