Jump to content

Recommended Posts

Hello community,

 

I'm wondering if anyone may know of a concise way to script replacement of regular magazines with tracer magazines, including magazines currently loaded into a units' weapon. I think I can achieve this, but it would require parsing a fair bit of weapon/mag varieties. I wonder if there is a universal way to do this... Any help is appreciated.

 

Rgds,

Bandpass

Share this post


Link to post
Share on other sites

Search the for the equivalent mag class name for tracer or the color of it exists then add to container. If you want to go down the string parsing route.

Sent from my WAS-LX1A using Tapatalk

Share this post


Link to post
Share on other sites

Used this a couple of years ago, should still work. Works only for vanilla magazines.

_unit = param [0,objNull];
private _pWeap = primaryWeapon _unit;
private _magarray = primaryWeaponMagazine _unit;
private _magtype = _magarray select 0;
if (isNil "_magtype") exitWith {};
				
if (_magtype isEqualTo "30Rnd_65x39_caseless_mag") then {_tracermag = "30Rnd_65x39_caseless_mag_Tracer"}; // Blufor
if (_magtype isEqualTo "100Rnd_65x39_caseless_mag") then {_tracermag = "100Rnd_65x39_caseless_mag_Tracer"}; // Blufor
if (_magtype isEqualTo "150Rnd_556x45_Drum_Mag_F") then {_tracermag = "150Rnd_556x45_Drum_Mag_Tracer_F"}; // Blufor
if (_magtype isEqualTo "30Rnd_65x39_caseless_green") then {_tracermag = "30Rnd_65x39_caseless_green_mag_Tracer"}; // Opfor
if (_magtype isEqualTo "150Rnd_762x51_Box") then {_tracermag = "150Rnd_762x51_Box_Tracer"}; // Opfor
if (_magtype isEqualTo "150Rnd_762x54_Box") then {_tracermag = "150Rnd_762x54_Box_Tracer"}; // Opfor
if (_magtype isEqualTo "30Rnd_580x42_Mag_F") then {_tracermag = "30Rnd_580x42_Mag_Tracer_F"}; // Opfor
if (_magtype isEqualTo "100Rnd_580x42_Mag_F") then {_tracermag = "100Rnd_580x42_Mag_Tracer_F"}; // Opfor
if (_magtype isEqualTo "200Rnd_65x39_cased_Box") then {_tracermag = "200Rnd_65x39_cased_Box_Tracer"}; //Indep

if (_magtype isEqualTo "30Rnd_762x39_Mag_F") then {_tracermag = "30Rnd_762x39_Mag_Tracer_F"}; //Indep
if (_magtype isEqualTo "30Rnd_545x39_Mag_F") then {_tracermag = "30Rnd_545x39_Mag_Tracer_F"}; //Indep
if (_magtype isEqualTo "20Rnd_650x39_Cased_Mag_F") then {_tracermag = "20Rnd_650x39_Cased_Mag_F"}; //Indep

if (_magtype isEqualTo "30Rnd_556x45_Stanag") then {
	if (side _unit == west) then {_tracermag = "30Rnd_556x45_Stanag_Tracer_Red"}; // Blufor
		if (side _unit == independent) then {_tracermag = "30Rnd_556x45_Stanag_Tracer_Yellow"}; // Indep
			if (side _unit == east) then {_tracermag = "30Rnd_556x45_Stanag_Tracer_Green"}; // Opfor
};
if (_magtype isEqualTo "30Rnd_9x21_Mag") then {
	if (side _unit == west) then {_tracermag = "30Rnd_9x21_Red_Mag"}; // Blufor
		if (side _unit == independent) then {_tracermag = "30Rnd_9x21_Yellow_Mag"}; // Indep
			if (side _unit == east) then {_tracermag = "30Rnd_9x21_Green_Mag"}; // Opfor
		
};
if (_magtype isEqualTo "16Rnd_9x21_Mag") then {
	if (side _unit == west) then {_tracermag = "16Rnd_9x21_red_Mag"}; // Blufor
		if (side _unit == independent) then {_tracermag = "16Rnd_9x21_green_Mag"}; // Indep
			if (side _unit == east) then {_tracermag = "16Rnd_9x21_yellow_Mag"}; // Opfor
};
if (_magtype isEqualTo "30Rnd_45ACP_Mag_SMG_01") then {
	if (side _unit == west) then {_tracermag = "30Rnd_45ACP_Mag_SMG_01_Tracer_Red"}; // Blufor
		if (side _unit == independent) then {_tracermag = "30Rnd_45ACP_Mag_SMG_01_Tracer_Yellow"}; // Indep
			if (side _unit == east) then {_tracermag = "30Rnd_45ACP_Mag_SMG_01_Tracer_Green"}; // Opfor
};
if (_magtype isEqualTo "30Rnd_9x21_Mag_SMG_02") then {
	if (side _unit == west) then {_tracermag = "30Rnd_9x21_Mag_SMG_02_Tracer_Red"}; // Blufor
		if (side _unit == independent) then {_tracermag = "30Rnd_9x21_Mag_SMG_02_Tracer_Yellow"}; // Indep
			if (side _unit == east) then {_tracermag = "30Rnd_9x21_Mag_SMG_02_Tracer_Green"}; // Opfor
};
if (_magtype isEqualTo "200Rnd_556x45_Box_F") then {
	if (side _unit == west) then {_tracermag = "200Rnd_556x45_Box_Red_F"}; // Blufor
		if (side _unit == independent) then {_tracermag = "200Rnd_556x45_Box_Tracer_F"}; // Indep
			if (side _unit == east) then {_tracermag = "200Rnd_556x45_Box_Tracer_Red_F"}; // Opfor
};

_magcount = {_x == _magtype} count magazines _unit;
_unit removeMagazines _magtype;
_unit removePrimaryWeaponItem _magtype;

_unit addMagazines [_tracermag, _magcount];
_unit addPrimaryWeaponItem _tracermag;
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Oh nice - that's going to save a lot of work! Could use this as an interim solution until I come across a generic concise solution (if at all possible).

 

Bandpass

Share this post


Link to post
Share on other sites

This will replace all mags for primary weapon with tracers.  I didn't bother for pistols but you can expand it if you need to.

 

Not sure if this works on mods, but vanilla weapons will be ok.  If you have problems with mods, you can find them by changing the system to look for tracer property in cfgAmmo, but I couldn't be bothered here as you didn't mention mods.

 

It will strip the current mag out of your primary weapon, so if you are holding it, then you will have zero ammo and have to press reload button.  If you're holding your pistol then script is run then the primary weapon will be reloaded correctly.  It's just fwp though  ;)

 

fnc_replaceWithTracer = {
    _magTypesToDel = [];
    _tracerTypes = [];
    {
        if (toLower _x find "tracer" > -1) then {
            _tracerTypes pushBack _x
        } else {
            _magTypesToDel pushBack _x
        }
    } forEach (getArray(configfile>>"cfgWeapons">>(primaryWeapon _this)>>"magazines"));
    _magsToRemove = [];
    _magsToAdd = [];
    {
        _currMag = _x;
        if (_currMag in _magTypesToDel) then {
            _count = getNumber(configfile>>"cfgMagazines">>_currMag>>"count");
            {
                if (_count == getNumber(configfile>>"cfgMagazines">>_x>>"count")) exitWith {
                    _magsToRemove pushBack _currMag;
                    _magsToAdd pushBack _x;
                }
            } forEach _tracerTypes;
            if (_forEachIndex == 0) then {
                _this setAmmo [primaryWeapon _this,0];
            }
        }
    } forEach ([currentMagazine _this] + magazines _this);
    {
        _this removeMagazine _x
    } forEach _magsToRemove;
    {
        _this addMagazine _x
    } forEach _magsToAdd;
};

 

execute with:

 

myUnit call fnc_replaceWithTracer

 

for one guy

 

Or

 

{
    _x call fnc_replaceWithTracer
} forEach someUnits

 

for some guys

 

  • Like 4

Share this post


Link to post
Share on other sites

Welp @das attorney was a bit faster but here's my solution, for all weapons:

params ["_unit"];
_weapons = weapons _unit;

{
	_compMags = getArray (configfile >> "CfgWeapons" >> _x >> "magazines");
	// Determine right tracer color
	_tracerColor = "red";
	switch (side _unit) do
	{
		case east: {_tracerColor = "green"};
		case independent: {_tracerColor = "yellow"};
	};
	// Find correct tracer mag name
	_correctMag = _compMags select {toLower _x find "tracer" > 0};
	if (count _correctMag == 0) exitWith {/*No tracer mags for this weapon*/};
	_correctMag = _compMags select {toLower _x find _tracerColor > 0};
	if (count _correctMag > 0) then {
		_correctMag = _correctMag select 0;
	} else {
		_correctMag = _compMags select {toLower _x find "tracer" > 0};
		_correctMag = _correctMag select {toLower _x find "red" < 0 && toLower _x find "green" < 0 && toLower _x find "yellow" < 0};
		_correctMag = _correctMag select 0;
	};

	// Add magazines and remove non tracer ones
	_currentMags = (magazines _unit) select {_x in _compMags};
	_nonTracerMags = _currentMags select {toLower _x find "tracer" < 0};
	_amount = count _nonTracerMags;
	_tracerMags = _currentMags select {toLower _x find "tracer" > 0};

	{_unit removeMagazines _x} forEach _nonTracerMags;
	_unit addMagazines [_correctMag, _amount];

	switch (_x) do
	{
		case primaryWeapon _unit:
		{
			_unit removePrimaryWeaponItem ((primaryWeaponMagazine _unit) select 0);
			_unit addPrimaryWeaponItem _correctMag;
		};
		case secondaryWeapon _unit:
		{
			_unit removeSecondaryWeaponItem ((secondaryWeaponMagazine _unit) select 0);
			_unit addSecondaryWeaponItem _correctMag;
		};
		case handgunWeapon _unit:
		{
			_unit removeSecondaryWeaponItem ((handgunMagazine _unit) select 0);
			_unit addHandgunItem _correctMag;
		};
		default
		{
			/* maybe lasermarker? */
		};
	};



} forEach _weapons;

	// 0.0767ms

 

Edited by 7erra
New code, all weapons included
  • Like 5

Share this post


Link to post
Share on other sites
_unit addPrimaryWeaponItem _correctMag;

Ah, nice one - I didn't know that command existed :)

Share this post


Link to post
Share on other sites
1 minute ago, das attorney said:

I didn't know that command existed :)

Me neither but I saw the script of @A Bandpass Filter above :icon_biggrin:

Share this post


Link to post
Share on other sites

Edited first code for all weapons.

Share this post


Link to post
Share on other sites

Heh, this is horribly slow but should change all the magazines in your inventory
 

[player] call {
	params [
		["_unit", objNull, [objNull]]
	];

	private _allMagazines = ("getNumber (_x >> 'scope') isEqualto 2" configClasses (configFile >> "cfgMagazines")) apply {configName _x};
	private _magArr = (magazines _unit) select {(toLower _x find "tracer") isEqualTo -1};
	private _newMagArr = _magArr call BIS_fnc_consolidateArray;
	
	
	{
		_x params ["_tmpMag", "_amt"];
		private _tmp = _allMagazines select {_x find _tmpMag > -1};

		if (count _tmp > 1) then {
			_x set [0, _tmp select 1];
		};
	} forEach _newMagArr;


	{_unit removeMagazines _x;} forEach _magArr;
	{_unit addMagazines _x;} forEach _newMagArr;
};

(it'll also change smoke grenades too..)

  • Like 5

Share this post


Link to post
Share on other sites

Hey guys, thanks so much for the responses - they have been super helpful!

 

I have managed to successfully implement a script that replaces all mags (including the loaded mag) for all units' primary weapons. I also implemented a second script that resets all units to their original primary weapon magazine loadouts (minus mags spent after converting to tracer mags).

 

The first script works by 1) recording a units' name, current loaded primary weapon mag, and all inventory-stored primary weapon mags into an array (ammoList), and 2) replacing all primary weapon mags with equivalent tracer mags. The second script resets all units' mags to their original state (minus ammo spent while in "tracer mode") by accessing the array (ammoList).

 

Both scripts worked flawlessly with a small number of units, but when I tested with with about 8 to 10 units, the array "ammoList" (during 1st script) does not get populated with all unit info (perhaps only 3 units of 8 total) and thus most of the units' original loadouts do not get repopulated when script #2 is run. I can't seem to spot the flaw in the logic which would prevent the array from populating all unit info... Might anyone here have some insight on the matter? 

 

Note that I am trying to integrate these scripts as a feature in a mod I am working on. These scripts exist as two separate .sqf files, which I call separately as execVMs. 

 

The two scripts are as follows:

 

Apply Tracers:

(Note: I noticed a mini bug in the tracer-colour parsing for the code I posted. This doesn't effect the issue I'm having. I'll update that with the latest code soon)

ammoList = [];
{
_unit = _x;
_weapons = weapons _unit;
_unitName = name _x;

_x = primaryWeapon _unit;

_currentMag = "";
_ammoCount = 0;
_magList    = magazinesAmmo _unit; 
_magNameAmmoList = [];  
_currentMag = (primaryWeaponMagazine _unit) select 0;
_ammoCount = _unit ammo primaryWeapon _unit;

_compMags = getArray (configfile >> "CfgWeapons" >> _x >> "magazines");
_magBaseName = _compMags select {toLower _x find "tracer" < 0};
_magBaseName = _magBaseName select 0;
{
if (toLower (_x select 0) find toLower _magBaseName >= 0) then 
{
_magNameAmmoList pushBack _x;
};
} forEach _magList;
ammoList pushBack [_unitName, _currentMag, _magNameAmmoList];

if ([(side _unit),(side player)] call BIS_fnc_sideIsFriendly) then {_tracerColor = "yellow";} 
else { _tracerColor = "yellow";};

_correctMag = _compMags select {toLower _x find "tracer" > 0};
if (count _correctMag == 0) exitWith {};

if (count _correctMag > 0) then 
{
_tracerSuffix = "";
_tracerList = [];
{ 
_magNameArray = toArray _x;
_magNameArray deleteRange [0, count (toArray _currentMag)];
_tracerSuffix = toString _magNameArray;
_tracerList pushBack _tracerSuffix;
} forEach _correctMag;
hint format ["%1", _tracerList];

_correctMag = _currentMag + _tracerSuffix;
hint format ["%1", _correctMag];
}
else
{
_correctMag = _compMags select {toLower _x find "tracer" > 0};
_correctMag = _correctMag select 0;
};

hint format ["%1", _correctMag];

_currentMags = (magazines _unit) select {_x in _compMags};
_nonTracerMags = _currentMags select {toLower _x find "tracer" < 0};
_amount = count _nonTracerMags;

{_unit removeMagazines _x} forEach _nonTracerMags;
_unit addMagazines [_correctMag, _amount];

hint format ["%1, %2, %3, %4, %5", _unit, _correctMag, _currentMag, _x, _ammoCount];

nul = [_unit, _correctMag, _currentMag, _x, _ammoCount] spawn 
{
sleep 0.1;
_unit = _this select 0;
_unit removePrimaryWeaponItem (_this select 2);
_unit addPrimaryWeaponItem (_this select 1);
_unit setAmmo [(_this select 3), (_this select 4)];
};

}forEach allUnits;

 

Reset Ammo:
{
_unit = _x;
_unitName = name _x;
_magList = magazines _unit;
_totalMagCount = 0;
_ammoList = _this select 0;

_previousMag = "";
_magNameList = [];
_ammoCount = 0;

{ 
if ((_x select 0) isEqualTo _unitName) then
{
_previousMag = (_x select 1);
_magNameList = (_x select 2);
}  
} forEach _ammoList;

{  
if (toLower _x find toLower "tracer" >= 0 ) then
{
_unit removeMagazine _x;
_totalMagCount = _totalMagCount + 1;
hint format ["%1", _totalMagCount];
}
} forEach magazines _unit;

for "_i" from 1 to _totalMagCount do
{
_magName = _magNameList select _i;
_unit addMagazine _magName;
hint format ["%1", _i];
};

_ammoCount = _unit ammo primaryWeapon _unit;
_unit removePrimaryWeaponItem ((primaryWeaponMagazine _unit) select 0);
_unit addPrimaryWeaponItem _previousMag;

_unit setAmmo [_x, _ammoCount];

} forEach allUnits;

 

 
 

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

×