2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-02-08 22:36:58 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
|
|
|
|
* Starts repacking a specific magazine classname.
|
2015-02-09 04:44:23 +00:00
|
|
|
* If room in inventory, unload magazine from weapon to be repacked.
|
2015-02-08 22:36:58 +00:00
|
|
|
* Precalcs all the event timings and starts the progressBar.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-04-01 18:09:03 +00:00
|
|
|
* 0: Target <OBJECT>
|
|
|
|
* 1: Player <OBJECT>
|
|
|
|
* 2: Magazine Classname <STRING>
|
2015-02-08 22:36:58 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2015-02-08 22:36:58 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2016-06-04 18:40:55 +00:00
|
|
|
* [player, player, "30Rnd_65x39_caseless_mag"] call ace_magazinerepack_fnc_startRepackingMagazine
|
2015-02-08 22:36:58 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
params ["_target", "_player", "_magazineClassname"];
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-04-01 18:09:03 +00:00
|
|
|
if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");};
|
2016-06-04 18:40:55 +00:00
|
|
|
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineClassname;
|
2015-04-01 16:21:30 +00:00
|
|
|
// Calculate actual ammo to transfer during repack
|
2016-06-04 18:40:55 +00:00
|
|
|
private _fullMagazineCount = getNumber (_magazineCfg >> "count");
|
2015-04-01 16:21:30 +00:00
|
|
|
//Is linked belt magazine:
|
2016-06-04 18:40:55 +00:00
|
|
|
private _isBelt = isNumber (_magazineCfg >> "ACE_isBelt") && {(getNumber (_magazineCfg >> "ACE_isBelt")) == 1};
|
2015-02-08 22:36:58 +00:00
|
|
|
|
2015-04-04 03:37:48 +00:00
|
|
|
//Check canInteractWith:
|
2017-08-22 18:30:56 +00:00
|
|
|
if !([_player, objNull, ["isNotInside", "isNotSwimming", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {};
|
2015-04-04 03:37:48 +00:00
|
|
|
|
2015-04-01 16:21:30 +00:00
|
|
|
[_player] call EFUNC(common,goKneeling);
|
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
private _startingAmmoCounts = [];
|
2015-02-08 19:48:53 +00:00
|
|
|
{
|
2016-06-04 18:40:55 +00:00
|
|
|
_x params ["_xClassname", "_xCount", "_xLoaded", "_xType"];
|
|
|
|
if (_xClassname == _magazineClassname && {_xCount != _fullMagazineCount && {_xCount > 0}}) then {
|
2015-02-08 19:48:53 +00:00
|
|
|
if (_xLoaded) then {
|
|
|
|
//Try to Remove from weapon and add to inventory, otherwise ignore
|
2015-04-01 16:21:30 +00:00
|
|
|
if (_player canAdd _magazineClassname) then {
|
2015-02-08 19:48:53 +00:00
|
|
|
switch (_xType) do {
|
2016-06-04 18:40:55 +00:00
|
|
|
case (1): {_player removePrimaryWeaponItem _magazineClassname};
|
|
|
|
case (2): {_player removeHandgunItem _magazineClassname};
|
|
|
|
case (4): {_player removeSecondaryWeaponItem _magazineClassname};
|
2015-02-08 19:48:53 +00:00
|
|
|
default {ERROR("Loaded Location Invalid");};
|
|
|
|
};
|
2015-04-01 16:21:30 +00:00
|
|
|
_player addMagazine [_magazineClassname, _xCount];
|
2015-02-08 19:48:53 +00:00
|
|
|
_startingAmmoCounts pushBack _xCount;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
_startingAmmoCounts pushBack _xCount;
|
|
|
|
};
|
|
|
|
};
|
2015-04-01 16:21:30 +00:00
|
|
|
} forEach (magazinesAmmoFull _player);
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
if (count _startingAmmoCounts < 2) exitWith {ERROR("Not Enough Mags to Repack");};
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
private _simEvents = [_fullMagazineCount, _startingAmmoCounts, _isBelt] call FUNC(simulateRepackEvents);
|
|
|
|
private _totalTime = _simEvents select (count _simEvents - 1) select 0;
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-02-08 23:35:21 +00:00
|
|
|
[
|
2015-08-15 22:30:24 +00:00
|
|
|
_totalTime,
|
|
|
|
[_magazineClassname, _startingAmmoCounts, _simEvents],
|
|
|
|
{_this call FUNC(magazineRepackFinish)},
|
|
|
|
{_this call FUNC(magazineRepackFinish)},
|
|
|
|
(localize LSTRING(RepackingMagazine)),
|
|
|
|
{_this call FUNC(magazineRepackProgress)},
|
2017-08-22 18:30:56 +00:00
|
|
|
["isNotInside", "isNotSwimming", "isNotSitting"]
|
2015-02-08 23:35:21 +00:00
|
|
|
] call EFUNC(common,progressBar);
|