ACE3/addons/magazinerepack/functions/fnc_magazineRepackProgress.sqf

78 lines
2.5 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
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
*/
params ["_args", "_elapsedTime", "_totalTime"];
2015-08-15 22:30:24 +00:00
_args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"];
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
//Verify we aren't missing any ammo
private _currentAmmoCount = [];
{
2015-08-15 22:30:24 +00:00
_x params ["_xClassname", "_xCount"];
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
private _addedMagazines = +_currentAmmoCount;
private _missingAmmo = false;
{
if (_x > 0) then {
private _index = _addedMagazines find _x;
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)
private _updateMagazinesOnPlayerFnc = {
2015-02-08 22:36:58 +00:00
ACE_player removeMagazines _magazineClassname; //remove inventory magazines
{
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 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;
};
} else {
2015-02-11 21:43:08 +00:00
playSound QGVAR(soundMagazineFinished);
2015-02-08 22:36:58 +00:00
call _updateMagazinesOnPlayerFnc;
};
_simEvents deleteAt 0; //pop off the event
2015-08-15 22:30:24 +00:00
true