ACE3/addons/magazinerepack/functions/fnc_magazineRepackProgress.sqf

79 lines
2.5 KiB
Plaintext
Raw Normal View History

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
*/
#include "script_component.hpp"
2015-02-08 22:36:58 +00:00
private ["_currentAmmoCount", "_addedMagazines", "_missingAmmo", "_index", "_updateMagazinesOnPlayerFnc"];
PARAMS_3(_args,_elapsedTime,_totalTime);
EXPLODE_3_PVT(_args,_magazineClassname,_lastAmmoCount,_simEvents);
if ((count _simEvents) == 0) exitWith {ERROR("No Event"); false};
2015-02-08 22:36:58 +00:00
EXPLODE_3_PVT((_simEvents select 0),_nextEventTime,_nextEventIsBullet,_nextEventMags);
if (_nextEventTime > _elapsedTime) exitWith {true};//waiting on next event
//Verify we aren't missing any ammo
_currentAmmoCount = [];
{
EXPLODE_2_PVT(_x,_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
_addedMagazines = +_currentAmmoCount;
_missingAmmo = false;
{
if (_x > 0) then {
_index = _addedMagazines find _x;
if (_index != -1) then {
_addedMagazines deleteAt _index;
} else {
_missingAmmo = true;
};
};
} forEach _lastAmmoCount;
2015-02-09 04:44:23 +00:00
if (_missingAmmo) exitWith {false}; //something removed ammo that was being repacked (could be other players or scripts)
2015-02-08 22:36:58 +00:00
_updateMagazinesOnPlayerFnc = {
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
true;