2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-12-16 19:22:18 +00:00
|
|
|
/*
|
|
|
|
* Author: Grey
|
|
|
|
* Loads Magazine into static weapon
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: static <OBJECT>
|
|
|
|
* 1: unit <OBJECT>
|
2015-12-19 11:10:12 +00:00
|
|
|
* 2: magazine class to load; if not given the first compatible magazine is loaded <STRING> (default: "")
|
2015-12-16 19:22:18 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2015-12-16 22:47:14 +00:00
|
|
|
* [_target,_player,"ACE_1Rnd_82mm_Mo_HE"] call ace_mk6mortar_fnc_loadMagazine
|
2015-12-16 19:22:18 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2015-12-16 22:47:14 +00:00
|
|
|
params ["_static","_unit",["_magazineClassOptional","",[""]]];
|
2015-12-16 19:22:18 +00:00
|
|
|
|
2015-12-19 11:10:12 +00:00
|
|
|
//If function has been called with an optional classname hten add that magazine to the static weapon. Otherwise add the compatible magazine
|
|
|
|
if(_magazineClassOptional != "") then {
|
|
|
|
_unit removeMagazine _magazineClassOptional;
|
2016-05-22 15:29:05 +00:00
|
|
|
[QGVAR(addMagazine), [_static, _magazineClassOptional]] call CBA_fnc_globalEvent;
|
2015-12-19 11:10:12 +00:00
|
|
|
} else {
|
|
|
|
//Get weapon & magazine information of static weapon
|
2017-10-10 14:39:59 +00:00
|
|
|
private _weapon = (_static weaponsTurret [0]) select 0;
|
|
|
|
private _currentMagazine = (magazinesAllTurrets _static) select 1;
|
|
|
|
private _currentMagazineClass = _currentMagazine select 0;
|
|
|
|
private _count = _currentMagazine select 2;
|
2015-12-16 19:22:18 +00:00
|
|
|
|
2015-12-19 11:10:12 +00:00
|
|
|
//Check all of the players magazines to see if they are compatible with the static weapon. First magazine that is compatible is chosen
|
|
|
|
//VKing: This section ought to be double checked.
|
2017-10-10 14:39:59 +00:00
|
|
|
private _magazines = magazines _unit;
|
|
|
|
private _magazineDetails = magazinesDetail _unit;
|
|
|
|
private _listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines");
|
|
|
|
private _magazineClass = "";
|
|
|
|
private _magazineClassDetails = "";
|
|
|
|
private _roundsLeft = 0;
|
2015-12-19 11:10:12 +00:00
|
|
|
{
|
|
|
|
if (_x in _listOfMagNames) exitWith {
|
|
|
|
_magazineClass = _x;
|
|
|
|
_magazineClassDetails = _magazineDetails select _forEachIndex;
|
|
|
|
};
|
|
|
|
} forEach _magazines;
|
|
|
|
//If the static weapon already has an empty magazine then remove it
|
|
|
|
if (_count == 0) then {
|
2016-05-22 15:29:05 +00:00
|
|
|
[QGVAR(removeMagazine), [_static, _currentMagazineClass]] call CBA_fnc_globalEvent;
|
2015-12-16 19:22:18 +00:00
|
|
|
};
|
2015-12-19 11:10:12 +00:00
|
|
|
//Find out the ammo count of the compatible magazine found
|
|
|
|
if (_magazineClassDetails != "") then{
|
2017-10-10 14:39:59 +00:00
|
|
|
private _parsed = _magazineClassDetails splitString "([]/: )";
|
2015-12-19 11:10:12 +00:00
|
|
|
_parsed params ["_type", "", "", "_roundsLeftText", "_maxRoundsText"];
|
|
|
|
_roundsLeft = parseNumber _roundsLeftText;
|
|
|
|
_magType = _type;
|
2015-12-16 19:22:18 +00:00
|
|
|
};
|
2015-12-19 11:10:12 +00:00
|
|
|
|
|
|
|
_unit removeMagazine _magazineClass;
|
2016-05-22 15:29:05 +00:00
|
|
|
[QGVAR(addMagazine), [_static, _magazineClass]] call CBA_fnc_globalEvent;
|
|
|
|
[QGVAR(setAmmo), [_static, _magazineClass,_roundsLeft], _static] call CBA_fnc_targetEvent;
|
2015-12-19 11:10:12 +00:00
|
|
|
};
|