2015-02-08 22:36:58 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
|
|
|
|
* Handles each frame durring the repack progressBar.
|
|
|
|
* On each event (repacked bullet or move to new mag) it plays a sound and syncs up the new magazines to the player.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Arguments [classname,lastAmmoStatus,events] <ARRAY>
|
|
|
|
* 1: Elapsed Time <NUMBER>
|
|
|
|
* 2: Total Time Repacking Will Take <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Keep going (on missing mags return false) <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* (args from progressBar) call ace_magazinerepack_fnc_magazineRepackProgress
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-02-08 19:48:53 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
params ["_ars", "_elapsedTime", "_totalTime"];
|
|
|
|
_args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"];
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
if !((_simEvents select 0) params ["_nextEventTime", "_nextEventIsBullet", "_nextEventMags"]) exitWith { ERROR("No Event"); false };
|
|
|
|
|
|
|
|
|
|
|
|
if (_nextEventTime > _elapsedTime) exitWith { true };//waiting on next event
|
2015-02-08 19:48:53 +00:00
|
|
|
|
|
|
|
//Verify we aren't missing any ammo
|
2016-06-04 18:40:55 +00:00
|
|
|
private _currentAmmoCount = [];
|
2015-02-08 19:48:53 +00:00
|
|
|
{
|
2015-08-15 22:30:24 +00:00
|
|
|
_x params ["_xClassname", "_xCount"];
|
2015-02-08 19:48:53 +00:00
|
|
|
if (_xClassname == _magazineClassname) then {
|
|
|
|
_currentAmmoCount pushBack _xCount;
|
|
|
|
};
|
|
|
|
} forEach (magazinesAmmo ACE_player); //only inventory mags
|
|
|
|
|
2015-02-09 04:44:23 +00:00
|
|
|
//Go through mags we currently have and check off the ones we should have
|
2016-06-04 18:40:55 +00:00
|
|
|
private _addedMagazines = +_currentAmmoCount;
|
|
|
|
private _missingAmmo = false;
|
2015-02-08 19:48:53 +00:00
|
|
|
{
|
|
|
|
if (_x > 0) then {
|
2016-06-04 18:40:55 +00:00
|
|
|
private _index = _addedMagazines find _x;
|
2015-02-08 19:48:53 +00:00
|
|
|
if (_index != -1) then {
|
|
|
|
_addedMagazines deleteAt _index;
|
|
|
|
} else {
|
|
|
|
_missingAmmo = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _lastAmmoCount;
|
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
if (_missingAmmo) exitWith { false }; //something removed ammo that was being repacked (could be other players or scripts)
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
private _updateMagazinesOnPlayerFnc = {
|
2015-02-08 22:36:58 +00:00
|
|
|
ACE_player removeMagazines _magazineClassname; //remove inventory magazines
|
2015-02-08 19:48:53 +00:00
|
|
|
{
|
|
|
|
if (_x > 0) then {
|
|
|
|
ACE_player addMagazine [_magazineClassname, _x];
|
|
|
|
};
|
2015-02-08 22:36:58 +00:00
|
|
|
} forEach (_addedMagazines + _nextEventMags);
|
|
|
|
_args set [1, _nextEventMags]; //store the new magazine
|
2015-02-08 19:48:53 +00:00
|
|
|
};
|
|
|
|
|
2015-02-08 22:36:58 +00:00
|
|
|
if (_nextEventIsBullet) then {
|
2015-02-11 21:43:08 +00:00
|
|
|
playSound QGVAR(soundRoundFinished);
|
2015-02-08 22:36:58 +00:00
|
|
|
if ((((count _simEvents) % 3) == 0) || {(count _simEvents) == 1}) then {
|
2015-02-09 04:44:23 +00:00
|
|
|
//For performance - only update mags every 3 bullets (or if it's the last event)
|
2015-02-08 22:36:58 +00:00
|
|
|
call _updateMagazinesOnPlayerFnc;
|
2015-02-08 19:48:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-02-11 21:43:08 +00:00
|
|
|
playSound QGVAR(soundMagazineFinished);
|
2015-02-08 22:36:58 +00:00
|
|
|
call _updateMagazinesOnPlayerFnc;
|
2015-02-08 19:48:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_simEvents deleteAt 0; //pop off the event
|
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
true
|